ldtk icon indicating copy to clipboard operation
ldtk copied to clipboard

[SUGGESTION] Hot Reloading in Haxe

Open chosencharacters opened this issue 2 years ago • 1 comments

I don't know if this is a limitation of Haxe macros, but there's been some investigation into hot reloading levels (especially with flixel) in LDTK. This would significantly cut down on dev time as it'd remove the need for constant recompiling to regen the macro. This is for situations where assets aren't embedded of course.

Could it be possible?

chosencharacters avatar Dec 12 '23 22:12 chosencharacters

Hot reloading should work in Haxe through the official LDtk Haxe importer. Here is an example from GameBase:

https://github.com/deepnight/gameBase/blob/79c70ea035d096c6282846b181997749ace67032/src/game/assets/Assets.hx#L60

what it does in short:

  • check if the ldtk is in the res subfolder (where assets belong)
  • watch the file for changes
  • if any change happen (in the watch callback), wait for 0.2s before actually reloading the file. This prevents some deadlocks when trying to load a file while it's being saved (happens for large projects)
  • get the new raw JSON string (through getText)
  • call parseJson() with this new string
  • notify the game that the LDtk data was reloaded

the idea should be the same in HF, but using their specific asset system

deepnight avatar Dec 31 '23 10:12 deepnight