@nice2dev/game-engine 1.3.14 → 1.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/accessibility/Accessibility.js +152 -165
- package/dist/cjs/ai/AI.js +292 -294
- package/dist/cjs/ai/BehaviorTree.js +1029 -1113
- package/dist/cjs/ai/StateMachine.js +694 -756
- package/dist/cjs/animation/Animation.js +232 -241
- package/dist/cjs/audio/AudioAdvanced.js +221 -236
- package/dist/cjs/audio/AudioBridge.js +441 -435
- package/dist/cjs/audio/AudioManager.js +242 -259
- package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
- package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
- package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
- package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
- package/dist/cjs/core/EventBus.js +51 -56
- package/dist/cjs/core/GameClock.js +62 -66
- package/dist/cjs/core/GameConfig.js +72 -79
- package/dist/cjs/core/GameLoop.js +80 -89
- package/dist/cjs/core/ServiceLocator.js +61 -65
- package/dist/cjs/core/Validation.js +72 -82
- package/dist/cjs/core/math.js +108 -112
- package/dist/cjs/devtools/DevTools.js +542 -563
- package/dist/cjs/devtools/DeveloperExperience.js +521 -559
- package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
- package/dist/cjs/dialogue/DialogueSystem.js +984 -986
- package/dist/cjs/docs/DocGenerator.js +339 -364
- package/dist/cjs/ecs/World.js +355 -371
- package/dist/cjs/editor/AchievementEditor.js +580 -636
- package/dist/cjs/editor/AdvancedEditor.js +184 -191
- package/dist/cjs/editor/AnimationRetargeting.js +696 -741
- package/dist/cjs/editor/AssetBrowser.js +1072 -1160
- package/dist/cjs/editor/AssetManager.js +187 -192
- package/dist/cjs/editor/ConsolePro.js +971 -1061
- package/dist/cjs/editor/CraftingEditor.js +680 -730
- package/dist/cjs/editor/DebugTools.js +187 -185
- package/dist/cjs/editor/DialogueSystem.js +844 -901
- package/dist/cjs/editor/LeaderboardSystem.js +429 -483
- package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
- package/dist/cjs/editor/PrefabSystem.js +772 -838
- package/dist/cjs/editor/ProfilerPanel.js +649 -700
- package/dist/cjs/editor/QuestEditor.js +792 -839
- package/dist/cjs/editor/ReplaySystem.js +585 -634
- package/dist/cjs/editor/SceneEditor.js +176 -200
- package/dist/cjs/editor/ScreenshotMode.js +621 -688
- package/dist/cjs/editor/ShaderGraph.js +1556 -1582
- package/dist/cjs/editor/TimelineEditor.js +715 -778
- package/dist/cjs/editor/UndoRedoPro.js +830 -904
- package/dist/cjs/editor/VRARMode.js +582 -645
- package/dist/cjs/engine/NiceGameEngine.js +141 -164
- package/dist/cjs/engine/SaveSystem.js +441 -495
- package/dist/cjs/enterprise/Enterprise.js +254 -261
- package/dist/cjs/export/BevyExporter.js +927 -967
- package/dist/cjs/export/CocosExporter.js +644 -673
- package/dist/cjs/export/Construct3Exporter.js +783 -794
- package/dist/cjs/export/DefoldExporter.js +1028 -1069
- package/dist/cjs/export/GDevelopExporter.js +674 -708
- package/dist/cjs/export/GameMakerExporter.js +791 -805
- package/dist/cjs/export/GodotExporter.js +1003 -1045
- package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
- package/dist/cjs/export/MonoGameExporter.js +1265 -1293
- package/dist/cjs/export/Pico8Exporter.js +766 -812
- package/dist/cjs/export/PlatformExporter.js +188 -206
- package/dist/cjs/export/RPGMakerExporter.js +860 -879
- package/dist/cjs/export/RobloxExporter.js +883 -919
- package/dist/cjs/export/Solar2DExporter.js +1218 -1256
- package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
- package/dist/cjs/export/Tic80Exporter.js +1210 -1267
- package/dist/cjs/export/UnityExporter.js +1116 -1131
- package/dist/cjs/export/UnrealExporter.js +889 -919
- package/dist/cjs/export/WebExporter.js +931 -970
- package/dist/cjs/export/index.js +42 -65
- package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
- package/dist/cjs/godot-integration/GodotImport.js +929 -1027
- package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
- package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
- package/dist/cjs/i18n/I18n.js +860 -900
- package/dist/cjs/i18n/useTranslation.js +84 -89
- package/dist/cjs/import/AsepriteImporter.js +658 -716
- package/dist/cjs/import/DragonBonesImporter.js +437 -461
- package/dist/cjs/import/GameMakerImporter.js +511 -521
- package/dist/cjs/import/GodotSceneImporter.js +788 -822
- package/dist/cjs/import/LDtkImporter.js +436 -454
- package/dist/cjs/import/Live2DImporter.js +497 -518
- package/dist/cjs/import/NdgFormat.js +424 -457
- package/dist/cjs/import/OgmoImporter.js +466 -493
- package/dist/cjs/import/RPGMakerImporter.js +451 -477
- package/dist/cjs/import/SceneImporter.js +378 -423
- package/dist/cjs/import/SpineImporter.js +511 -546
- package/dist/cjs/import/SpriterImporter.js +590 -613
- package/dist/cjs/import/TiledMapImporter.js +811 -846
- package/dist/cjs/import/UnitySceneImporter.js +687 -703
- package/dist/cjs/import/index.js +206 -251
- package/dist/cjs/index.js +275 -278
- package/dist/cjs/input/GamepadNavigation.js +185 -205
- package/dist/cjs/input/InputManager.js +397 -421
- package/dist/cjs/input/useGamepads.js +70 -81
- package/dist/cjs/integration/IconSprite.js +129 -256
- package/dist/cjs/inventory/InventorySystem.js +920 -995
- package/dist/cjs/kids/KidMode.js +997 -1022
- package/dist/cjs/kids/KidTools.js +570 -594
- package/dist/cjs/monetization/Monetization.js +170 -177
- package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
- package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
- package/dist/cjs/native-engine/AnimationSystem.js +731 -806
- package/dist/cjs/native-engine/AssetPipeline.js +454 -515
- package/dist/cjs/native-engine/AudioEngine.js +763 -804
- package/dist/cjs/native-engine/InputSystem.js +1075 -1145
- package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
- package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
- package/dist/cjs/native-engine/RenderingEngine.js +302 -350
- package/dist/cjs/native-engine/SceneGraph.js +769 -808
- package/dist/cjs/network/MultiplayerTransport.js +97 -132
- package/dist/cjs/network/Networking.js +549 -564
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
- package/dist/cjs/pathfinding/Pathfinding.js +245 -263
- package/dist/cjs/performance/AssetStreaming.js +561 -635
- package/dist/cjs/performance/BenchmarkSuite.js +283 -311
- package/dist/cjs/performance/DeltaCompression.js +467 -526
- package/dist/cjs/performance/DeterministicPhysics.js +450 -498
- package/dist/cjs/performance/ECSOptimization.js +644 -695
- package/dist/cjs/performance/GameSaveSystem.js +509 -556
- package/dist/cjs/performance/HotReload.js +447 -500
- package/dist/cjs/performance/InputRecording.js +511 -561
- package/dist/cjs/performance/InterestManagement.js +453 -500
- package/dist/cjs/performance/LocalizationRuntime.js +376 -423
- package/dist/cjs/performance/MemoryManagement.js +410 -470
- package/dist/cjs/performance/ModSupport.js +445 -496
- package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
- package/dist/cjs/performance/NetworkPrediction.js +424 -482
- package/dist/cjs/performance/ObjectPooling.js +569 -617
- package/dist/cjs/performance/Performance.js +174 -190
- package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
- package/dist/cjs/performance/WebGPURenderer.js +656 -683
- package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
- package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
- package/dist/cjs/plugins/PluginSDK.js +432 -466
- package/dist/cjs/plugins/PluginTestKit.js +307 -330
- package/dist/cjs/procedural/Procedural.js +243 -254
- package/dist/cjs/procedural/WorldBuilding.js +297 -314
- package/dist/cjs/quest/QuestSystem.js +975 -932
- package/dist/cjs/release/MobileExport.js +157 -163
- package/dist/cjs/release/Release.js +225 -238
- package/dist/cjs/rendering/Camera2D.js +121 -124
- package/dist/cjs/rendering/Renderer2D.js +321 -335
- package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
- package/dist/cjs/runtime3d/Runtime3D.js +359 -378
- package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
- package/dist/cjs/scene/SceneManager.js +177 -193
- package/dist/cjs/scripting/GraphToAST.js +574 -547
- package/dist/cjs/scripting/LanguageExporter.js +254 -279
- package/dist/cjs/scripting/NodeGraph.js +546 -570
- package/dist/cjs/scripting/ScriptAST.js +31 -39
- package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
- package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
- package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
- package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
- package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
- package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
- package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
- package/dist/cjs/social/Social.js +72 -80
- package/dist/cjs/systems/LightingSystem.js +844 -931
- package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
- package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
- package/dist/cjs/systems/TerrainSystem.js +985 -1098
- package/dist/cjs/templates/ActionTemplates.js +296 -309
- package/dist/cjs/templates/FightingTemplate.js +417 -463
- package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
- package/dist/cjs/templates/PartyTemplates.js +190 -202
- package/dist/cjs/templates/PuzzleTemplates.js +245 -261
- package/dist/cjs/templates/RPGTemplates.js +160 -178
- package/dist/cjs/templates/SportsTemplates.js +237 -250
- package/dist/cjs/templates/StrategyTemplates.js +143 -153
- package/dist/cjs/templates/SurvivalTemplate.js +336 -380
- package/dist/cjs/templates/WaveDefense.js +499 -526
- package/dist/cjs/tilemap/Tilemap.js +207 -214
- package/dist/cjs/tutorials/TutorialBranching.js +396 -417
- package/dist/cjs/tutorials/TutorialEngine.js +888 -931
- package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
- package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
- package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
- package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
- package/dist/cjs/ui/GameUI.js +295 -312
- package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
- package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
- package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
- package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
- package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
- package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
- package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
- package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
- package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
- package/dist/cjs/xr/ARVR.js +167 -175
- package/dist/esm/accessibility/Accessibility.js +160 -164
- package/dist/esm/ai/AI.js +310 -293
- package/dist/esm/ai/BehaviorTree.js +1057 -1112
- package/dist/esm/ai/StateMachine.js +709 -755
- package/dist/esm/animation/Animation.js +237 -240
- package/dist/esm/audio/AudioAdvanced.js +239 -235
- package/dist/esm/audio/AudioBridge.js +448 -434
- package/dist/esm/audio/AudioManager.js +243 -258
- package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
- package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
- package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
- package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
- package/dist/esm/core/EventBus.js +52 -55
- package/dist/esm/core/GameClock.js +63 -65
- package/dist/esm/core/GameConfig.js +77 -78
- package/dist/esm/core/GameLoop.js +81 -88
- package/dist/esm/core/ServiceLocator.js +63 -64
- package/dist/esm/core/Validation.js +82 -81
- package/dist/esm/core/math.js +109 -111
- package/dist/esm/devtools/DevTools.js +546 -562
- package/dist/esm/devtools/DeveloperExperience.js +535 -558
- package/dist/esm/devtools/GameplayAnalytics.js +647 -645
- package/dist/esm/dialogue/DialogueSystem.js +998 -985
- package/dist/esm/docs/DocGenerator.js +342 -363
- package/dist/esm/ecs/World.js +358 -370
- package/dist/esm/editor/AchievementEditor.js +584 -635
- package/dist/esm/editor/AdvancedEditor.js +191 -190
- package/dist/esm/editor/AnimationRetargeting.js +700 -740
- package/dist/esm/editor/AssetBrowser.js +1078 -1159
- package/dist/esm/editor/AssetManager.js +188 -191
- package/dist/esm/editor/ConsolePro.js +977 -1060
- package/dist/esm/editor/CraftingEditor.js +684 -729
- package/dist/esm/editor/DebugTools.js +194 -184
- package/dist/esm/editor/DialogueSystem.js +849 -900
- package/dist/esm/editor/LeaderboardSystem.js +433 -482
- package/dist/esm/editor/NiceGameEditor.js +1908 -1200
- package/dist/esm/editor/PrefabSystem.js +777 -837
- package/dist/esm/editor/ProfilerPanel.js +654 -699
- package/dist/esm/editor/QuestEditor.js +795 -838
- package/dist/esm/editor/ReplaySystem.js +591 -633
- package/dist/esm/editor/SceneEditor.js +189 -199
- package/dist/esm/editor/ScreenshotMode.js +628 -687
- package/dist/esm/editor/ShaderGraph.js +1565 -1581
- package/dist/esm/editor/TimelineEditor.js +733 -777
- package/dist/esm/editor/UndoRedoPro.js +835 -903
- package/dist/esm/editor/VRARMode.js +586 -644
- package/dist/esm/engine/NiceGameEngine.js +142 -163
- package/dist/esm/engine/SaveSystem.js +447 -494
- package/dist/esm/enterprise/Enterprise.js +265 -260
- package/dist/esm/export/BevyExporter.js +929 -966
- package/dist/esm/export/CocosExporter.js +646 -672
- package/dist/esm/export/Construct3Exporter.js +785 -793
- package/dist/esm/export/DefoldExporter.js +1030 -1068
- package/dist/esm/export/GDevelopExporter.js +676 -707
- package/dist/esm/export/GameMakerExporter.js +793 -804
- package/dist/esm/export/GodotExporter.js +1004 -1044
- package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
- package/dist/esm/export/MonoGameExporter.js +1267 -1292
- package/dist/esm/export/Pico8Exporter.js +768 -811
- package/dist/esm/export/PlatformExporter.js +193 -205
- package/dist/esm/export/RPGMakerExporter.js +862 -878
- package/dist/esm/export/RobloxExporter.js +885 -918
- package/dist/esm/export/Solar2DExporter.js +1220 -1255
- package/dist/esm/export/ThreeJSExporter.js +1007 -1072
- package/dist/esm/export/Tic80Exporter.js +1212 -1266
- package/dist/esm/export/UnityExporter.js +1117 -1130
- package/dist/esm/export/UnrealExporter.js +891 -918
- package/dist/esm/export/WebExporter.js +933 -969
- package/dist/esm/export/index.js +86 -71
- package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
- package/dist/esm/godot-integration/GodotImport.js +935 -1026
- package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
- package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
- package/dist/esm/i18n/I18n.js +871 -899
- package/dist/esm/i18n/useTranslation.js +88 -88
- package/dist/esm/import/AsepriteImporter.js +637 -715
- package/dist/esm/import/DragonBonesImporter.js +417 -460
- package/dist/esm/import/GameMakerImporter.js +491 -520
- package/dist/esm/import/GodotSceneImporter.js +767 -821
- package/dist/esm/import/LDtkImporter.js +415 -453
- package/dist/esm/import/Live2DImporter.js +477 -517
- package/dist/esm/import/NdgFormat.js +410 -456
- package/dist/esm/import/OgmoImporter.js +446 -492
- package/dist/esm/import/RPGMakerImporter.js +431 -476
- package/dist/esm/import/SceneImporter.js +385 -422
- package/dist/esm/import/SpineImporter.js +491 -545
- package/dist/esm/import/SpriterImporter.js +570 -612
- package/dist/esm/import/TiledMapImporter.js +790 -845
- package/dist/esm/import/UnitySceneImporter.js +666 -702
- package/dist/esm/import/index.js +247 -258
- package/dist/esm/index.js +1332 -188
- package/dist/esm/input/GamepadNavigation.js +187 -204
- package/dist/esm/input/InputManager.js +401 -420
- package/dist/esm/input/useGamepads.js +72 -80
- package/dist/esm/integration/IconSprite.js +143 -255
- package/dist/esm/inventory/InventorySystem.js +925 -994
- package/dist/esm/kids/KidMode.js +1003 -1021
- package/dist/esm/kids/KidTools.js +573 -593
- package/dist/esm/monetization/Monetization.js +180 -176
- package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
- package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
- package/dist/esm/native-engine/AnimationSystem.js +735 -805
- package/dist/esm/native-engine/AssetPipeline.js +456 -514
- package/dist/esm/native-engine/AudioEngine.js +765 -803
- package/dist/esm/native-engine/InputSystem.js +1079 -1144
- package/dist/esm/native-engine/NetworkingSystem.js +740 -792
- package/dist/esm/native-engine/PhysicsEngine.js +585 -606
- package/dist/esm/native-engine/RenderingEngine.js +304 -349
- package/dist/esm/native-engine/SceneGraph.js +773 -807
- package/dist/esm/network/MultiplayerTransport.js +99 -131
- package/dist/esm/network/Networking.js +556 -563
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
- package/dist/esm/pathfinding/Pathfinding.js +249 -262
- package/dist/esm/performance/AssetStreaming.js +567 -634
- package/dist/esm/performance/BenchmarkSuite.js +285 -310
- package/dist/esm/performance/DeltaCompression.js +478 -525
- package/dist/esm/performance/DeterministicPhysics.js +479 -497
- package/dist/esm/performance/ECSOptimization.js +653 -694
- package/dist/esm/performance/GameSaveSystem.js +515 -555
- package/dist/esm/performance/HotReload.js +454 -499
- package/dist/esm/performance/InputRecording.js +520 -560
- package/dist/esm/performance/InterestManagement.js +460 -499
- package/dist/esm/performance/LocalizationRuntime.js +382 -422
- package/dist/esm/performance/MemoryManagement.js +415 -469
- package/dist/esm/performance/ModSupport.js +455 -495
- package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
- package/dist/esm/performance/NetworkPrediction.js +436 -481
- package/dist/esm/performance/ObjectPooling.js +582 -616
- package/dist/esm/performance/Performance.js +182 -189
- package/dist/esm/performance/PerformanceAdvanced.js +621 -636
- package/dist/esm/performance/WebGPURenderer.js +660 -682
- package/dist/esm/physics/PhysicsAdvanced.js +359 -378
- package/dist/esm/physics/PhysicsEngine2D.js +393 -426
- package/dist/esm/plugins/PluginSDK.js +435 -465
- package/dist/esm/plugins/PluginTestKit.js +315 -329
- package/dist/esm/procedural/Procedural.js +248 -253
- package/dist/esm/procedural/WorldBuilding.js +316 -313
- package/dist/esm/quest/QuestSystem.js +982 -931
- package/dist/esm/release/MobileExport.js +163 -162
- package/dist/esm/release/Release.js +234 -237
- package/dist/esm/rendering/Camera2D.js +122 -123
- package/dist/esm/rendering/Renderer2D.js +323 -334
- package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
- package/dist/esm/runtime3d/Runtime3D.js +368 -377
- package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
- package/dist/esm/scene/SceneManager.js +178 -192
- package/dist/esm/scripting/GraphToAST.js +576 -546
- package/dist/esm/scripting/LanguageExporter.js +263 -278
- package/dist/esm/scripting/NodeGraph.js +550 -569
- package/dist/esm/scripting/ScriptAST.js +45 -38
- package/dist/esm/scripting/VisualScripting2.js +1025 -1064
- package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
- package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
- package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
- package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
- package/dist/esm/scripting/exporters/RustExporter.js +460 -511
- package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
- package/dist/esm/social/Social.js +77 -79
- package/dist/esm/systems/LightingSystem.js +855 -930
- package/dist/esm/systems/ParticleSystem2.js +1453 -1450
- package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
- package/dist/esm/systems/TerrainSystem.js +996 -1097
- package/dist/esm/templates/ActionTemplates.js +307 -308
- package/dist/esm/templates/FightingTemplate.js +439 -462
- package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
- package/dist/esm/templates/PartyTemplates.js +206 -201
- package/dist/esm/templates/PuzzleTemplates.js +260 -260
- package/dist/esm/templates/RPGTemplates.js +172 -177
- package/dist/esm/templates/SportsTemplates.js +251 -249
- package/dist/esm/templates/StrategyTemplates.js +158 -152
- package/dist/esm/templates/SurvivalTemplate.js +367 -379
- package/dist/esm/templates/WaveDefense.js +501 -525
- package/dist/esm/tilemap/Tilemap.js +209 -213
- package/dist/esm/tutorials/TutorialBranching.js +399 -416
- package/dist/esm/tutorials/TutorialEngine.js +893 -930
- package/dist/esm/tutorials/TutorialOverlay.js +603 -639
- package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
- package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
- package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
- package/dist/esm/ui/GameUI.js +296 -311
- package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
- package/dist/esm/unity-integration/UnityImport.js +1071 -1175
- package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
- package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
- package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
- package/dist/esm/unreal-integration/UnrealImport.js +395 -411
- package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
- package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
- package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
- package/dist/esm/xr/ARVR.js +181 -174
- package/package.json +7 -12
|
@@ -1,852 +1,797 @@
|
|
|
1
|
-
import { SceneImporter, parseXML } from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file TiledMapImporter.ts
|
|
5
|
-
* @description Import Tiled Map Editor files (.tmx, .tsx)
|
|
6
|
-
* PRO-1.3: Scene Format Interoperability
|
|
7
|
-
*
|
|
8
|
-
* Supports:
|
|
9
|
-
* - Tiled Map files (.tmx, .tmj)
|
|
10
|
-
* - Tileset files (.tsx, .tsj)
|
|
11
|
-
* - Template files (.tx, .tj)
|
|
12
|
-
* - World files (.world)
|
|
13
|
-
*
|
|
14
|
-
* Features:
|
|
15
|
-
* - Tile layers
|
|
16
|
-
* - Object layers
|
|
17
|
-
* - Image layers
|
|
18
|
-
* - Group layers
|
|
19
|
-
* - Animations
|
|
20
|
-
* - Custom properties
|
|
21
|
-
* - Collision shapes
|
|
22
|
-
*/
|
|
23
|
-
// ============================================================
|
|
24
|
-
// Tiled Map Importer
|
|
25
|
-
// ============================================================
|
|
1
|
+
import { SceneImporter, parseXML } from "./SceneImporter.js";
|
|
26
2
|
class TiledMapImporter extends SceneImporter {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
// Image layer specific
|
|
217
|
-
if (json.type === 'imagelayer') {
|
|
218
|
-
layer.image = json.image ? String(json.image) : undefined;
|
|
219
|
-
layer.repeatX = json.repeatx ? Boolean(json.repeatx) : undefined;
|
|
220
|
-
layer.repeatY = json.repeaty ? Boolean(json.repeaty) : undefined;
|
|
221
|
-
}
|
|
222
|
-
// Group layer specific
|
|
223
|
-
if (json.type === 'group' && json.layers) {
|
|
224
|
-
layer.layers = json.layers.map((l) => this.normalizeJsonLayer(l));
|
|
225
|
-
}
|
|
226
|
-
return layer;
|
|
227
|
-
}
|
|
228
|
-
normalizeJsonObject(json) {
|
|
229
|
-
return {
|
|
230
|
-
id: Number(json.id) || 0,
|
|
231
|
-
name: String(json.name || ''),
|
|
232
|
-
type: String(json.type || json.class || ''),
|
|
233
|
-
x: Number(json.x) || 0,
|
|
234
|
-
y: Number(json.y) || 0,
|
|
235
|
-
width: Number(json.width) || 0,
|
|
236
|
-
height: Number(json.height) || 0,
|
|
237
|
-
rotation: Number(json.rotation) || 0,
|
|
238
|
-
visible: json.visible !== false,
|
|
239
|
-
gid: json.gid ? Number(json.gid) : undefined,
|
|
240
|
-
template: json.template ? String(json.template) : undefined,
|
|
241
|
-
point: json.point ? Boolean(json.point) : undefined,
|
|
242
|
-
ellipse: json.ellipse ? Boolean(json.ellipse) : undefined,
|
|
243
|
-
polygon: json.polygon,
|
|
244
|
-
polyline: json.polyline,
|
|
245
|
-
text: json.text,
|
|
246
|
-
properties: this.normalizeProperties(json.properties),
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
normalizeProperties(props) {
|
|
250
|
-
if (!props) {
|
|
251
|
-
return undefined;
|
|
252
|
-
}
|
|
253
|
-
return props.map((p) => {
|
|
254
|
-
const prop = p;
|
|
255
|
-
return {
|
|
256
|
-
name: String(prop.name || ''),
|
|
257
|
-
type: prop.type || 'string',
|
|
258
|
-
value: prop.value,
|
|
259
|
-
propertyType: prop.propertytype ? String(prop.propertytype) : undefined,
|
|
260
|
-
};
|
|
3
|
+
constructor() {
|
|
4
|
+
super("tiled");
|
|
5
|
+
this.tilesets = /* @__PURE__ */ new Map();
|
|
6
|
+
this.tilesetsById = /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
8
|
+
async import(options) {
|
|
9
|
+
const startTime = Date.now();
|
|
10
|
+
this.options = options;
|
|
11
|
+
this.clearMessages();
|
|
12
|
+
this.tilesets.clear();
|
|
13
|
+
this.tilesetsById.clear();
|
|
14
|
+
const errors = await this.validate(options.sourcePath);
|
|
15
|
+
if (errors.some((e) => e.fatal)) {
|
|
16
|
+
return {
|
|
17
|
+
...this.createEmptyResult(),
|
|
18
|
+
errors
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const scenes = [];
|
|
22
|
+
const assets = [];
|
|
23
|
+
try {
|
|
24
|
+
const content = await this.readFile(options.sourcePath);
|
|
25
|
+
const isJson = options.sourcePath.endsWith(".tmj") || options.sourcePath.endsWith(".json");
|
|
26
|
+
const map = isJson ? this.parseJsonMap(content) : this.parseXmlMap(content);
|
|
27
|
+
if (map) {
|
|
28
|
+
await this.loadExternalTilesets(map, options.sourcePath);
|
|
29
|
+
const parsed = this.convertTiledMapToScene(map);
|
|
30
|
+
const niceScene = this.convertParsedToNiceScene(parsed);
|
|
31
|
+
scenes.push(niceScene);
|
|
32
|
+
const extractedAssets = this.extractAssets(map);
|
|
33
|
+
assets.push(...extractedAssets);
|
|
34
|
+
}
|
|
35
|
+
} catch (error) {
|
|
36
|
+
this.addError(
|
|
37
|
+
"IMPORT_ERROR",
|
|
38
|
+
`Failed to import: ${error}`,
|
|
39
|
+
options.sourcePath,
|
|
40
|
+
void 0,
|
|
41
|
+
true
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return this.createResult(scenes, assets, startTime);
|
|
45
|
+
}
|
|
46
|
+
async parseFile(content, filePath) {
|
|
47
|
+
const stringContent = typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
48
|
+
const isJson = filePath.endsWith(".tmj") || filePath.endsWith(".json");
|
|
49
|
+
const map = isJson ? this.parseJsonMap(stringContent) : this.parseXmlMap(stringContent);
|
|
50
|
+
if (!map) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return this.convertTiledMapToScene(map);
|
|
54
|
+
}
|
|
55
|
+
async validate(sourcePath) {
|
|
56
|
+
const errors = [];
|
|
57
|
+
if (!this.canHandle(sourcePath)) {
|
|
58
|
+
errors.push({
|
|
59
|
+
code: "INVALID_FORMAT",
|
|
60
|
+
message: `File ${sourcePath} is not a valid Tiled file`,
|
|
61
|
+
file: sourcePath,
|
|
62
|
+
fatal: true
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return errors;
|
|
66
|
+
}
|
|
67
|
+
// ----------------------------------------
|
|
68
|
+
// Tiled Parsing
|
|
69
|
+
// ----------------------------------------
|
|
70
|
+
parseJsonMap(content) {
|
|
71
|
+
try {
|
|
72
|
+
const json = JSON.parse(content);
|
|
73
|
+
return this.normalizeJsonMap(json);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
this.addError("JSON_PARSE_ERROR", `Failed to parse JSON: ${error}`);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
normalizeJsonMap(json) {
|
|
80
|
+
return {
|
|
81
|
+
version: String(json.version || "1.0"),
|
|
82
|
+
tiledVersion: String(json.tiledversion || ""),
|
|
83
|
+
orientation: json.orientation || "orthogonal",
|
|
84
|
+
renderOrder: json.renderorder || "right-down",
|
|
85
|
+
width: Number(json.width) || 0,
|
|
86
|
+
height: Number(json.height) || 0,
|
|
87
|
+
tileWidth: Number(json.tilewidth) || 0,
|
|
88
|
+
tileHeight: Number(json.tileheight) || 0,
|
|
89
|
+
infinite: Boolean(json.infinite),
|
|
90
|
+
backgroundColor: json.backgroundcolor ? String(json.backgroundcolor) : void 0,
|
|
91
|
+
nextLayerId: Number(json.nextlayerid) || 0,
|
|
92
|
+
nextObjectId: Number(json.nextobjectid) || 0,
|
|
93
|
+
parallaxOriginX: json.parallaxoriginx ? Number(json.parallaxoriginx) : void 0,
|
|
94
|
+
parallaxOriginY: json.parallaxoriginy ? Number(json.parallaxoriginy) : void 0,
|
|
95
|
+
tilesets: json.tilesets?.map(
|
|
96
|
+
(ts) => this.normalizeJsonTileset(ts)
|
|
97
|
+
) || [],
|
|
98
|
+
layers: json.layers?.map(
|
|
99
|
+
(l) => this.normalizeJsonLayer(l)
|
|
100
|
+
) || [],
|
|
101
|
+
properties: this.normalizeProperties(json.properties),
|
|
102
|
+
hexSideLength: json.hexsidelength ? Number(json.hexsidelength) : void 0,
|
|
103
|
+
staggerAxis: json.staggeraxis,
|
|
104
|
+
staggerIndex: json.staggerindex
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
normalizeJsonTileset(json) {
|
|
108
|
+
const tileset = {
|
|
109
|
+
firstGid: Number(json.firstgid) || 0,
|
|
110
|
+
source: json.source ? String(json.source) : void 0,
|
|
111
|
+
name: String(json.name || ""),
|
|
112
|
+
tileWidth: Number(json.tilewidth) || 0,
|
|
113
|
+
tileHeight: Number(json.tileheight) || 0,
|
|
114
|
+
spacing: Number(json.spacing) || 0,
|
|
115
|
+
margin: Number(json.margin) || 0,
|
|
116
|
+
tileCount: Number(json.tilecount) || 0,
|
|
117
|
+
columns: Number(json.columns) || 0,
|
|
118
|
+
image: json.image ? String(json.image) : void 0,
|
|
119
|
+
imageWidth: json.imagewidth ? Number(json.imagewidth) : void 0,
|
|
120
|
+
imageHeight: json.imageheight ? Number(json.imageheight) : void 0,
|
|
121
|
+
transparentColor: json.transparentcolor ? String(json.transparentcolor) : void 0,
|
|
122
|
+
properties: this.normalizeProperties(json.properties)
|
|
123
|
+
};
|
|
124
|
+
if (json.tiles) {
|
|
125
|
+
tileset.tiles = json.tiles.map(
|
|
126
|
+
(t) => this.normalizeJsonTile(t)
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
if (json.tileoffset) {
|
|
130
|
+
const offset = json.tileoffset;
|
|
131
|
+
tileset.tileOffset = { x: Number(offset.x) || 0, y: Number(offset.y) || 0 };
|
|
132
|
+
}
|
|
133
|
+
return tileset;
|
|
134
|
+
}
|
|
135
|
+
normalizeJsonTile(json) {
|
|
136
|
+
const tile = {
|
|
137
|
+
id: Number(json.id) || 0,
|
|
138
|
+
type: json.type ? String(json.type) : void 0,
|
|
139
|
+
properties: this.normalizeProperties(json.properties)
|
|
140
|
+
};
|
|
141
|
+
if (json.animation) {
|
|
142
|
+
tile.animation = json.animation.map((f) => ({
|
|
143
|
+
tileId: Number(f.tileid),
|
|
144
|
+
duration: Number(f.duration)
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
if (json.objectgroup) {
|
|
148
|
+
const og = json.objectgroup;
|
|
149
|
+
tile.objectGroup = {
|
|
150
|
+
drawOrder: String(og.draworder || "index"),
|
|
151
|
+
id: Number(og.id) || 0,
|
|
152
|
+
name: String(og.name || ""),
|
|
153
|
+
objects: og.objects?.map(
|
|
154
|
+
(o) => this.normalizeJsonObject(o)
|
|
155
|
+
) || []
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return tile;
|
|
159
|
+
}
|
|
160
|
+
normalizeJsonLayer(json) {
|
|
161
|
+
const layer = {
|
|
162
|
+
id: Number(json.id) || 0,
|
|
163
|
+
name: String(json.name || ""),
|
|
164
|
+
type: json.type || "tilelayer",
|
|
165
|
+
visible: json.visible !== false,
|
|
166
|
+
opacity: json.opacity !== void 0 ? Number(json.opacity) : 1,
|
|
167
|
+
offsetX: Number(json.offsetx) || 0,
|
|
168
|
+
offsetY: Number(json.offsety) || 0,
|
|
169
|
+
parallaxX: json.parallaxx !== void 0 ? Number(json.parallaxx) : 1,
|
|
170
|
+
parallaxY: json.parallaxy !== void 0 ? Number(json.parallaxy) : 1,
|
|
171
|
+
tintColor: json.tintcolor ? String(json.tintcolor) : void 0,
|
|
172
|
+
locked: json.locked ? Boolean(json.locked) : void 0,
|
|
173
|
+
class: json.class ? String(json.class) : void 0,
|
|
174
|
+
properties: this.normalizeProperties(json.properties)
|
|
175
|
+
};
|
|
176
|
+
if (json.type === "tilelayer") {
|
|
177
|
+
layer.width = Number(json.width) || 0;
|
|
178
|
+
layer.height = Number(json.height) || 0;
|
|
179
|
+
layer.data = json.data;
|
|
180
|
+
layer.encoding = json.encoding;
|
|
181
|
+
layer.compression = json.compression;
|
|
182
|
+
if (json.chunks) {
|
|
183
|
+
layer.chunks = json.chunks.map((c) => {
|
|
184
|
+
const chunk = c;
|
|
185
|
+
return {
|
|
186
|
+
x: Number(chunk.x),
|
|
187
|
+
y: Number(chunk.y),
|
|
188
|
+
width: Number(chunk.width),
|
|
189
|
+
height: Number(chunk.height),
|
|
190
|
+
data: chunk.data
|
|
191
|
+
};
|
|
261
192
|
});
|
|
262
|
-
|
|
263
|
-
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (json.type === "objectgroup") {
|
|
196
|
+
layer.objects = json.objects?.map(
|
|
197
|
+
(o) => this.normalizeJsonObject(o)
|
|
198
|
+
) || [];
|
|
199
|
+
layer.drawOrder = json.draworder || "topdown";
|
|
200
|
+
layer.color = json.color ? String(json.color) : void 0;
|
|
201
|
+
}
|
|
202
|
+
if (json.type === "imagelayer") {
|
|
203
|
+
layer.image = json.image ? String(json.image) : void 0;
|
|
204
|
+
layer.repeatX = json.repeatx ? Boolean(json.repeatx) : void 0;
|
|
205
|
+
layer.repeatY = json.repeaty ? Boolean(json.repeaty) : void 0;
|
|
206
|
+
}
|
|
207
|
+
if (json.type === "group" && json.layers) {
|
|
208
|
+
layer.layers = json.layers.map(
|
|
209
|
+
(l) => this.normalizeJsonLayer(l)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return layer;
|
|
213
|
+
}
|
|
214
|
+
normalizeJsonObject(json) {
|
|
215
|
+
return {
|
|
216
|
+
id: Number(json.id) || 0,
|
|
217
|
+
name: String(json.name || ""),
|
|
218
|
+
type: String(json.type || json.class || ""),
|
|
219
|
+
x: Number(json.x) || 0,
|
|
220
|
+
y: Number(json.y) || 0,
|
|
221
|
+
width: Number(json.width) || 0,
|
|
222
|
+
height: Number(json.height) || 0,
|
|
223
|
+
rotation: Number(json.rotation) || 0,
|
|
224
|
+
visible: json.visible !== false,
|
|
225
|
+
gid: json.gid ? Number(json.gid) : void 0,
|
|
226
|
+
template: json.template ? String(json.template) : void 0,
|
|
227
|
+
point: json.point ? Boolean(json.point) : void 0,
|
|
228
|
+
ellipse: json.ellipse ? Boolean(json.ellipse) : void 0,
|
|
229
|
+
polygon: json.polygon,
|
|
230
|
+
polyline: json.polyline,
|
|
231
|
+
text: json.text,
|
|
232
|
+
properties: this.normalizeProperties(json.properties)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
normalizeProperties(props) {
|
|
236
|
+
if (!props) {
|
|
237
|
+
return void 0;
|
|
238
|
+
}
|
|
239
|
+
return props.map((p) => {
|
|
240
|
+
const prop = p;
|
|
241
|
+
return {
|
|
242
|
+
name: String(prop.name || ""),
|
|
243
|
+
type: prop.type || "string",
|
|
244
|
+
value: prop.value,
|
|
245
|
+
propertyType: prop.propertytype ? String(prop.propertytype) : void 0
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
parseXmlMap(content) {
|
|
250
|
+
try {
|
|
251
|
+
const xml = parseXML(content);
|
|
252
|
+
return this.normalizeXmlMap(xml);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
this.addError("XML_PARSE_ERROR", `Failed to parse XML: ${error}`);
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
normalizeXmlMap(xml) {
|
|
259
|
+
const map = {
|
|
260
|
+
version: xml.attributes.version || "1.0",
|
|
261
|
+
tiledVersion: xml.attributes.tiledversion || "",
|
|
262
|
+
orientation: xml.attributes.orientation || "orthogonal",
|
|
263
|
+
renderOrder: xml.attributes.renderorder || "right-down",
|
|
264
|
+
width: parseInt(xml.attributes.width || "0", 10),
|
|
265
|
+
height: parseInt(xml.attributes.height || "0", 10),
|
|
266
|
+
tileWidth: parseInt(xml.attributes.tilewidth || "0", 10),
|
|
267
|
+
tileHeight: parseInt(xml.attributes.tileheight || "0", 10),
|
|
268
|
+
infinite: xml.attributes.infinite === "1",
|
|
269
|
+
backgroundColor: xml.attributes.backgroundcolor,
|
|
270
|
+
nextLayerId: parseInt(xml.attributes.nextlayerid || "0", 10),
|
|
271
|
+
nextObjectId: parseInt(xml.attributes.nextobjectid || "0", 10),
|
|
272
|
+
tilesets: [],
|
|
273
|
+
layers: [],
|
|
274
|
+
properties: this.parseXmlProperties(xml.children.find((c) => c.name === "properties"))
|
|
275
|
+
};
|
|
276
|
+
for (const child of xml.children.filter((c) => c.name === "tileset")) {
|
|
277
|
+
map.tilesets.push(this.normalizeXmlTileset(child));
|
|
278
|
+
}
|
|
279
|
+
for (const child of xml.children) {
|
|
280
|
+
if (["layer", "objectgroup", "imagelayer", "group"].includes(child.name)) {
|
|
281
|
+
map.layers.push(this.normalizeXmlLayer(child));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return map;
|
|
285
|
+
}
|
|
286
|
+
normalizeXmlTileset(xml) {
|
|
287
|
+
const tileset = {
|
|
288
|
+
firstGid: parseInt(xml.attributes.firstgid || "0", 10),
|
|
289
|
+
source: xml.attributes.source,
|
|
290
|
+
name: xml.attributes.name || "",
|
|
291
|
+
tileWidth: parseInt(xml.attributes.tilewidth || "0", 10),
|
|
292
|
+
tileHeight: parseInt(xml.attributes.tileheight || "0", 10),
|
|
293
|
+
spacing: parseInt(xml.attributes.spacing || "0", 10),
|
|
294
|
+
margin: parseInt(xml.attributes.margin || "0", 10),
|
|
295
|
+
tileCount: parseInt(xml.attributes.tilecount || "0", 10),
|
|
296
|
+
columns: parseInt(xml.attributes.columns || "0", 10),
|
|
297
|
+
properties: this.parseXmlProperties(xml.children.find((c) => c.name === "properties"))
|
|
298
|
+
};
|
|
299
|
+
const image = xml.children.find((c) => c.name === "image");
|
|
300
|
+
if (image) {
|
|
301
|
+
tileset.image = image.attributes.source;
|
|
302
|
+
tileset.imageWidth = parseInt(image.attributes.width || "0", 10);
|
|
303
|
+
tileset.imageHeight = parseInt(image.attributes.height || "0", 10);
|
|
304
|
+
tileset.transparentColor = image.attributes.trans;
|
|
305
|
+
}
|
|
306
|
+
const tiles = xml.children.filter((c) => c.name === "tile");
|
|
307
|
+
if (tiles.length > 0) {
|
|
308
|
+
tileset.tiles = tiles.map((t) => this.normalizeXmlTile(t));
|
|
309
|
+
}
|
|
310
|
+
const offset = xml.children.find((c) => c.name === "tileoffset");
|
|
311
|
+
if (offset) {
|
|
312
|
+
tileset.tileOffset = {
|
|
313
|
+
x: parseInt(offset.attributes.x || "0", 10),
|
|
314
|
+
y: parseInt(offset.attributes.y || "0", 10)
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
return tileset;
|
|
318
|
+
}
|
|
319
|
+
normalizeXmlTile(xml) {
|
|
320
|
+
const tile = {
|
|
321
|
+
id: parseInt(xml.attributes.id || "0", 10),
|
|
322
|
+
type: xml.attributes.type,
|
|
323
|
+
properties: this.parseXmlProperties(xml.children.find((c) => c.name === "properties"))
|
|
324
|
+
};
|
|
325
|
+
const animation = xml.children.find((c) => c.name === "animation");
|
|
326
|
+
if (animation) {
|
|
327
|
+
tile.animation = animation.children.filter((c) => c.name === "frame").map((f) => ({
|
|
328
|
+
tileId: parseInt(f.attributes.tileid || "0", 10),
|
|
329
|
+
duration: parseInt(f.attributes.duration || "0", 10)
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
332
|
+
const objectGroup = xml.children.find((c) => c.name === "objectgroup");
|
|
333
|
+
if (objectGroup) {
|
|
334
|
+
tile.objectGroup = {
|
|
335
|
+
drawOrder: objectGroup.attributes.draworder || "index",
|
|
336
|
+
id: parseInt(objectGroup.attributes.id || "0", 10),
|
|
337
|
+
name: objectGroup.attributes.name || "",
|
|
338
|
+
objects: objectGroup.children.filter((c) => c.name === "object").map((o) => this.normalizeXmlObject(o))
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
return tile;
|
|
342
|
+
}
|
|
343
|
+
normalizeXmlLayer(xml) {
|
|
344
|
+
const type = this.getLayerType(xml.name);
|
|
345
|
+
const layer = {
|
|
346
|
+
id: parseInt(xml.attributes.id || "0", 10),
|
|
347
|
+
name: xml.attributes.name || "",
|
|
348
|
+
type,
|
|
349
|
+
visible: xml.attributes.visible !== "0",
|
|
350
|
+
opacity: parseFloat(xml.attributes.opacity || "1"),
|
|
351
|
+
offsetX: parseFloat(xml.attributes.offsetx || "0"),
|
|
352
|
+
offsetY: parseFloat(xml.attributes.offsety || "0"),
|
|
353
|
+
parallaxX: parseFloat(xml.attributes.parallaxx || "1"),
|
|
354
|
+
parallaxY: parseFloat(xml.attributes.parallaxy || "1"),
|
|
355
|
+
tintColor: xml.attributes.tintcolor,
|
|
356
|
+
locked: xml.attributes.locked === "1",
|
|
357
|
+
class: xml.attributes.class,
|
|
358
|
+
properties: this.parseXmlProperties(xml.children.find((c) => c.name === "properties"))
|
|
359
|
+
};
|
|
360
|
+
if (type === "tilelayer") {
|
|
361
|
+
layer.width = parseInt(xml.attributes.width || "0", 10);
|
|
362
|
+
layer.height = parseInt(xml.attributes.height || "0", 10);
|
|
363
|
+
const dataNode = xml.children.find((c) => c.name === "data");
|
|
364
|
+
if (dataNode) {
|
|
365
|
+
layer.encoding = dataNode.attributes.encoding;
|
|
366
|
+
layer.compression = dataNode.attributes.compression;
|
|
367
|
+
if (layer.encoding === "csv" || !layer.encoding) {
|
|
368
|
+
layer.data = dataNode.text.split(",").map((s) => parseInt(s.trim(), 10));
|
|
369
|
+
} else if (layer.encoding === "base64") {
|
|
370
|
+
this.addWarning(
|
|
371
|
+
"BASE64_DATA",
|
|
372
|
+
"Base64 encoded tile data requires decompression",
|
|
373
|
+
xml.attributes.name
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
const chunks = dataNode.children.filter((c) => c.name === "chunk");
|
|
377
|
+
if (chunks.length > 0) {
|
|
378
|
+
layer.chunks = chunks.map((c) => ({
|
|
379
|
+
x: parseInt(c.attributes.x || "0", 10),
|
|
380
|
+
y: parseInt(c.attributes.y || "0", 10),
|
|
381
|
+
width: parseInt(c.attributes.width || "0", 10),
|
|
382
|
+
height: parseInt(c.attributes.height || "0", 10),
|
|
383
|
+
data: c.text.split(",").map((s) => parseInt(s.trim(), 10))
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (type === "objectgroup") {
|
|
389
|
+
layer.objects = xml.children.filter((c) => c.name === "object").map((o) => this.normalizeXmlObject(o));
|
|
390
|
+
layer.drawOrder = xml.attributes.draworder || "topdown";
|
|
391
|
+
layer.color = xml.attributes.color;
|
|
392
|
+
}
|
|
393
|
+
if (type === "imagelayer") {
|
|
394
|
+
const image = xml.children.find((c) => c.name === "image");
|
|
395
|
+
if (image) {
|
|
396
|
+
layer.image = image.attributes.source;
|
|
397
|
+
}
|
|
398
|
+
layer.repeatX = xml.attributes.repeatx === "1";
|
|
399
|
+
layer.repeatY = xml.attributes.repeaty === "1";
|
|
400
|
+
}
|
|
401
|
+
if (type === "group") {
|
|
402
|
+
layer.layers = [];
|
|
403
|
+
for (const child of xml.children) {
|
|
404
|
+
if (["layer", "objectgroup", "imagelayer", "group"].includes(child.name)) {
|
|
405
|
+
layer.layers.push(this.normalizeXmlLayer(child));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return layer;
|
|
410
|
+
}
|
|
411
|
+
normalizeXmlObject(xml) {
|
|
412
|
+
const obj = {
|
|
413
|
+
id: parseInt(xml.attributes.id || "0", 10),
|
|
414
|
+
name: xml.attributes.name || "",
|
|
415
|
+
type: xml.attributes.type || xml.attributes.class || "",
|
|
416
|
+
x: parseFloat(xml.attributes.x || "0"),
|
|
417
|
+
y: parseFloat(xml.attributes.y || "0"),
|
|
418
|
+
width: parseFloat(xml.attributes.width || "0"),
|
|
419
|
+
height: parseFloat(xml.attributes.height || "0"),
|
|
420
|
+
rotation: parseFloat(xml.attributes.rotation || "0"),
|
|
421
|
+
visible: xml.attributes.visible !== "0",
|
|
422
|
+
gid: xml.attributes.gid ? parseInt(xml.attributes.gid, 10) : void 0,
|
|
423
|
+
template: xml.attributes.template,
|
|
424
|
+
properties: this.parseXmlProperties(xml.children.find((c) => c.name === "properties"))
|
|
425
|
+
};
|
|
426
|
+
if (xml.children.some((c) => c.name === "point")) {
|
|
427
|
+
obj.point = true;
|
|
428
|
+
}
|
|
429
|
+
if (xml.children.some((c) => c.name === "ellipse")) {
|
|
430
|
+
obj.ellipse = true;
|
|
431
|
+
}
|
|
432
|
+
const polygon = xml.children.find((c) => c.name === "polygon");
|
|
433
|
+
if (polygon && polygon.attributes.points) {
|
|
434
|
+
obj.polygon = this.parsePoints(polygon.attributes.points);
|
|
435
|
+
}
|
|
436
|
+
const polyline = xml.children.find((c) => c.name === "polyline");
|
|
437
|
+
if (polyline && polyline.attributes.points) {
|
|
438
|
+
obj.polyline = this.parsePoints(polyline.attributes.points);
|
|
439
|
+
}
|
|
440
|
+
const text = xml.children.find((c) => c.name === "text");
|
|
441
|
+
if (text) {
|
|
442
|
+
obj.text = {
|
|
443
|
+
text: text.text || "",
|
|
444
|
+
fontFamily: text.attributes.fontfamily || "sans-serif",
|
|
445
|
+
pixelSize: parseInt(text.attributes.pixelsize || "16", 10),
|
|
446
|
+
wrap: text.attributes.wrap === "1",
|
|
447
|
+
color: text.attributes.color || "#000000",
|
|
448
|
+
bold: text.attributes.bold === "1",
|
|
449
|
+
italic: text.attributes.italic === "1",
|
|
450
|
+
underline: text.attributes.underline === "1",
|
|
451
|
+
strikeout: text.attributes.strikeout === "1",
|
|
452
|
+
kerning: text.attributes.kerning !== "0",
|
|
453
|
+
halign: text.attributes.halign || "left",
|
|
454
|
+
valign: text.attributes.valign || "top"
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
return obj;
|
|
458
|
+
}
|
|
459
|
+
parseXmlProperties(xml) {
|
|
460
|
+
if (!xml) {
|
|
461
|
+
return void 0;
|
|
462
|
+
}
|
|
463
|
+
return xml.children.filter((c) => c.name === "property").map((p) => ({
|
|
464
|
+
name: p.attributes.name || "",
|
|
465
|
+
type: p.attributes.type || "string",
|
|
466
|
+
value: this.parsePropertyValue(p.attributes.value || p.text, p.attributes.type),
|
|
467
|
+
propertyType: p.attributes.propertytype
|
|
468
|
+
}));
|
|
469
|
+
}
|
|
470
|
+
parsePropertyValue(value, type) {
|
|
471
|
+
switch (type) {
|
|
472
|
+
case "int":
|
|
473
|
+
return parseInt(value, 10);
|
|
474
|
+
case "float":
|
|
475
|
+
return parseFloat(value);
|
|
476
|
+
case "bool":
|
|
477
|
+
return value === "true";
|
|
478
|
+
default:
|
|
479
|
+
return value;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
parsePoints(pointsStr) {
|
|
483
|
+
return pointsStr.split(" ").map((p) => {
|
|
484
|
+
const [x, y] = p.split(",").map((v) => parseFloat(v));
|
|
485
|
+
return { x, y };
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
getLayerType(xmlName) {
|
|
489
|
+
switch (xmlName) {
|
|
490
|
+
case "layer":
|
|
491
|
+
return "tilelayer";
|
|
492
|
+
case "objectgroup":
|
|
493
|
+
return "objectgroup";
|
|
494
|
+
case "imagelayer":
|
|
495
|
+
return "imagelayer";
|
|
496
|
+
case "group":
|
|
497
|
+
return "group";
|
|
498
|
+
default:
|
|
499
|
+
return "tilelayer";
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
async loadExternalTilesets(map, mapPath) {
|
|
503
|
+
const basePath = mapPath.substring(0, mapPath.lastIndexOf("/") + 1);
|
|
504
|
+
for (const tileset of map.tilesets) {
|
|
505
|
+
if (tileset.source) {
|
|
264
506
|
try {
|
|
507
|
+
const tilesetPath = basePath + tileset.source;
|
|
508
|
+
const content = await this.readFile(tilesetPath);
|
|
509
|
+
const isJson = tileset.source.endsWith(".tsj") || tileset.source.endsWith(".json");
|
|
510
|
+
let externalTileset;
|
|
511
|
+
if (isJson) {
|
|
512
|
+
const json = JSON.parse(content);
|
|
513
|
+
externalTileset = this.normalizeJsonTileset(json);
|
|
514
|
+
} else {
|
|
265
515
|
const xml = parseXML(content);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
normalizeXmlMap(xml) {
|
|
274
|
-
const map = {
|
|
275
|
-
version: xml.attributes.version || '1.0',
|
|
276
|
-
tiledVersion: xml.attributes.tiledversion || '',
|
|
277
|
-
orientation: xml.attributes.orientation || 'orthogonal',
|
|
278
|
-
renderOrder: xml.attributes.renderorder || 'right-down',
|
|
279
|
-
width: parseInt(xml.attributes.width || '0', 10),
|
|
280
|
-
height: parseInt(xml.attributes.height || '0', 10),
|
|
281
|
-
tileWidth: parseInt(xml.attributes.tilewidth || '0', 10),
|
|
282
|
-
tileHeight: parseInt(xml.attributes.tileheight || '0', 10),
|
|
283
|
-
infinite: xml.attributes.infinite === '1',
|
|
284
|
-
backgroundColor: xml.attributes.backgroundcolor,
|
|
285
|
-
nextLayerId: parseInt(xml.attributes.nextlayerid || '0', 10),
|
|
286
|
-
nextObjectId: parseInt(xml.attributes.nextobjectid || '0', 10),
|
|
287
|
-
tilesets: [],
|
|
288
|
-
layers: [],
|
|
289
|
-
properties: this.parseXmlProperties(xml.children.find((c) => c.name === 'properties')),
|
|
290
|
-
};
|
|
291
|
-
// Parse tilesets
|
|
292
|
-
for (const child of xml.children.filter((c) => c.name === 'tileset')) {
|
|
293
|
-
map.tilesets.push(this.normalizeXmlTileset(child));
|
|
294
|
-
}
|
|
295
|
-
// Parse layers
|
|
296
|
-
for (const child of xml.children) {
|
|
297
|
-
if (['layer', 'objectgroup', 'imagelayer', 'group'].includes(child.name)) {
|
|
298
|
-
map.layers.push(this.normalizeXmlLayer(child));
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return map;
|
|
302
|
-
}
|
|
303
|
-
normalizeXmlTileset(xml) {
|
|
304
|
-
const tileset = {
|
|
305
|
-
firstGid: parseInt(xml.attributes.firstgid || '0', 10),
|
|
306
|
-
source: xml.attributes.source,
|
|
307
|
-
name: xml.attributes.name || '',
|
|
308
|
-
tileWidth: parseInt(xml.attributes.tilewidth || '0', 10),
|
|
309
|
-
tileHeight: parseInt(xml.attributes.tileheight || '0', 10),
|
|
310
|
-
spacing: parseInt(xml.attributes.spacing || '0', 10),
|
|
311
|
-
margin: parseInt(xml.attributes.margin || '0', 10),
|
|
312
|
-
tileCount: parseInt(xml.attributes.tilecount || '0', 10),
|
|
313
|
-
columns: parseInt(xml.attributes.columns || '0', 10),
|
|
314
|
-
properties: this.parseXmlProperties(xml.children.find((c) => c.name === 'properties')),
|
|
315
|
-
};
|
|
316
|
-
// Image
|
|
317
|
-
const image = xml.children.find((c) => c.name === 'image');
|
|
318
|
-
if (image) {
|
|
319
|
-
tileset.image = image.attributes.source;
|
|
320
|
-
tileset.imageWidth = parseInt(image.attributes.width || '0', 10);
|
|
321
|
-
tileset.imageHeight = parseInt(image.attributes.height || '0', 10);
|
|
322
|
-
tileset.transparentColor = image.attributes.trans;
|
|
323
|
-
}
|
|
324
|
-
// Tiles
|
|
325
|
-
const tiles = xml.children.filter((c) => c.name === 'tile');
|
|
326
|
-
if (tiles.length > 0) {
|
|
327
|
-
tileset.tiles = tiles.map((t) => this.normalizeXmlTile(t));
|
|
328
|
-
}
|
|
329
|
-
// Tile offset
|
|
330
|
-
const offset = xml.children.find((c) => c.name === 'tileoffset');
|
|
331
|
-
if (offset) {
|
|
332
|
-
tileset.tileOffset = {
|
|
333
|
-
x: parseInt(offset.attributes.x || '0', 10),
|
|
334
|
-
y: parseInt(offset.attributes.y || '0', 10),
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
return tileset;
|
|
338
|
-
}
|
|
339
|
-
normalizeXmlTile(xml) {
|
|
340
|
-
const tile = {
|
|
341
|
-
id: parseInt(xml.attributes.id || '0', 10),
|
|
342
|
-
type: xml.attributes.type,
|
|
343
|
-
properties: this.parseXmlProperties(xml.children.find((c) => c.name === 'properties')),
|
|
344
|
-
};
|
|
345
|
-
// Animation
|
|
346
|
-
const animation = xml.children.find((c) => c.name === 'animation');
|
|
347
|
-
if (animation) {
|
|
348
|
-
tile.animation = animation.children
|
|
349
|
-
.filter((c) => c.name === 'frame')
|
|
350
|
-
.map((f) => ({
|
|
351
|
-
tileId: parseInt(f.attributes.tileid || '0', 10),
|
|
352
|
-
duration: parseInt(f.attributes.duration || '0', 10),
|
|
353
|
-
}));
|
|
354
|
-
}
|
|
355
|
-
// Collision (objectgroup)
|
|
356
|
-
const objectGroup = xml.children.find((c) => c.name === 'objectgroup');
|
|
357
|
-
if (objectGroup) {
|
|
358
|
-
tile.objectGroup = {
|
|
359
|
-
drawOrder: objectGroup.attributes.draworder || 'index',
|
|
360
|
-
id: parseInt(objectGroup.attributes.id || '0', 10),
|
|
361
|
-
name: objectGroup.attributes.name || '',
|
|
362
|
-
objects: objectGroup.children
|
|
363
|
-
.filter((c) => c.name === 'object')
|
|
364
|
-
.map((o) => this.normalizeXmlObject(o)),
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
return tile;
|
|
368
|
-
}
|
|
369
|
-
normalizeXmlLayer(xml) {
|
|
370
|
-
const type = this.getLayerType(xml.name);
|
|
371
|
-
const layer = {
|
|
372
|
-
id: parseInt(xml.attributes.id || '0', 10),
|
|
373
|
-
name: xml.attributes.name || '',
|
|
374
|
-
type,
|
|
375
|
-
visible: xml.attributes.visible !== '0',
|
|
376
|
-
opacity: parseFloat(xml.attributes.opacity || '1'),
|
|
377
|
-
offsetX: parseFloat(xml.attributes.offsetx || '0'),
|
|
378
|
-
offsetY: parseFloat(xml.attributes.offsety || '0'),
|
|
379
|
-
parallaxX: parseFloat(xml.attributes.parallaxx || '1'),
|
|
380
|
-
parallaxY: parseFloat(xml.attributes.parallaxy || '1'),
|
|
381
|
-
tintColor: xml.attributes.tintcolor,
|
|
382
|
-
locked: xml.attributes.locked === '1',
|
|
383
|
-
class: xml.attributes.class,
|
|
384
|
-
properties: this.parseXmlProperties(xml.children.find((c) => c.name === 'properties')),
|
|
385
|
-
};
|
|
386
|
-
// Tile layer
|
|
387
|
-
if (type === 'tilelayer') {
|
|
388
|
-
layer.width = parseInt(xml.attributes.width || '0', 10);
|
|
389
|
-
layer.height = parseInt(xml.attributes.height || '0', 10);
|
|
390
|
-
const dataNode = xml.children.find((c) => c.name === 'data');
|
|
391
|
-
if (dataNode) {
|
|
392
|
-
layer.encoding = dataNode.attributes.encoding;
|
|
393
|
-
layer.compression = dataNode.attributes.compression;
|
|
394
|
-
if (layer.encoding === 'csv' || !layer.encoding) {
|
|
395
|
-
// CSV data
|
|
396
|
-
layer.data = dataNode.text.split(',').map((s) => parseInt(s.trim(), 10));
|
|
397
|
-
}
|
|
398
|
-
else if (layer.encoding === 'base64') {
|
|
399
|
-
// Base64 encoded - would need decompression for gzip/zlib
|
|
400
|
-
// For now, store as warning
|
|
401
|
-
this.addWarning('BASE64_DATA', 'Base64 encoded tile data requires decompression', xml.attributes.name);
|
|
402
|
-
}
|
|
403
|
-
// Chunks for infinite maps
|
|
404
|
-
const chunks = dataNode.children.filter((c) => c.name === 'chunk');
|
|
405
|
-
if (chunks.length > 0) {
|
|
406
|
-
layer.chunks = chunks.map((c) => ({
|
|
407
|
-
x: parseInt(c.attributes.x || '0', 10),
|
|
408
|
-
y: parseInt(c.attributes.y || '0', 10),
|
|
409
|
-
width: parseInt(c.attributes.width || '0', 10),
|
|
410
|
-
height: parseInt(c.attributes.height || '0', 10),
|
|
411
|
-
data: c.text.split(',').map((s) => parseInt(s.trim(), 10)),
|
|
412
|
-
}));
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
// Object layer
|
|
417
|
-
if (type === 'objectgroup') {
|
|
418
|
-
layer.objects = xml.children
|
|
419
|
-
.filter((c) => c.name === 'object')
|
|
420
|
-
.map((o) => this.normalizeXmlObject(o));
|
|
421
|
-
layer.drawOrder = xml.attributes.draworder || 'topdown';
|
|
422
|
-
layer.color = xml.attributes.color;
|
|
423
|
-
}
|
|
424
|
-
// Image layer
|
|
425
|
-
if (type === 'imagelayer') {
|
|
426
|
-
const image = xml.children.find((c) => c.name === 'image');
|
|
427
|
-
if (image) {
|
|
428
|
-
layer.image = image.attributes.source;
|
|
516
|
+
const tilesetNode = xml.name === "tileset" ? xml : xml.children.find((c) => c.name === "tileset");
|
|
517
|
+
if (tilesetNode) {
|
|
518
|
+
externalTileset = this.normalizeXmlTileset(tilesetNode);
|
|
519
|
+
} else {
|
|
520
|
+
continue;
|
|
429
521
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
// Conversion
|
|
579
|
-
// ----------------------------------------
|
|
580
|
-
convertTiledMapToScene(map) {
|
|
581
|
-
const layers = [];
|
|
582
|
-
const entities = [];
|
|
583
|
-
const zIndex = 0;
|
|
584
|
-
this.processLayers(map.layers, layers, entities, zIndex);
|
|
585
|
-
return {
|
|
586
|
-
name: 'TiledMap',
|
|
587
|
-
width: map.width * map.tileWidth,
|
|
588
|
-
height: map.height * map.tileHeight,
|
|
589
|
-
backgroundColor: map.backgroundColor || '#000000',
|
|
590
|
-
layers,
|
|
591
|
-
entities,
|
|
592
|
-
properties: {
|
|
593
|
-
orientation: map.orientation,
|
|
594
|
-
renderOrder: map.renderOrder,
|
|
595
|
-
tileWidth: map.tileWidth,
|
|
596
|
-
tileHeight: map.tileHeight,
|
|
597
|
-
infinite: map.infinite,
|
|
598
|
-
...this.convertProperties(map.properties),
|
|
599
|
-
},
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
processLayers(layers, outLayers, outEntities, zIndex) {
|
|
603
|
-
for (const layer of layers) {
|
|
604
|
-
if (layer.type === 'group' && layer.layers) {
|
|
605
|
-
zIndex = this.processLayers(layer.layers, outLayers, outEntities, zIndex);
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
outLayers.push(this.convertLayer(layer, zIndex));
|
|
609
|
-
// Extract objects as entities
|
|
610
|
-
if (layer.type === 'objectgroup' && layer.objects) {
|
|
611
|
-
for (const obj of layer.objects) {
|
|
612
|
-
outEntities.push(this.convertObject(obj, layer.name, zIndex));
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
zIndex++;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
return zIndex;
|
|
619
|
-
}
|
|
620
|
-
convertLayer(layer, zIndex) {
|
|
621
|
-
const parsedLayer = {
|
|
622
|
-
name: layer.name,
|
|
623
|
-
type: this.mapLayerType(layer.type),
|
|
624
|
-
visible: layer.visible,
|
|
625
|
-
opacity: layer.opacity,
|
|
626
|
-
offsetX: layer.offsetX,
|
|
627
|
-
offsetY: layer.offsetY,
|
|
628
|
-
parallaxX: layer.parallaxX,
|
|
629
|
-
parallaxY: layer.parallaxY,
|
|
630
|
-
zIndex,
|
|
631
|
-
properties: this.convertProperties(layer.properties),
|
|
632
|
-
};
|
|
633
|
-
// Tile data
|
|
634
|
-
if (layer.type === 'tilelayer' && layer.data) {
|
|
635
|
-
parsedLayer.data = {
|
|
636
|
-
width: layer.width || 0,
|
|
637
|
-
height: layer.height || 0,
|
|
638
|
-
tileWidth: 0, // Will be set from tileset
|
|
639
|
-
tileHeight: 0,
|
|
640
|
-
tiles: layer.data,
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
return parsedLayer;
|
|
644
|
-
}
|
|
645
|
-
mapLayerType(type) {
|
|
646
|
-
switch (type) {
|
|
647
|
-
case 'tilelayer':
|
|
648
|
-
return 'tile';
|
|
649
|
-
case 'objectgroup':
|
|
650
|
-
return 'object';
|
|
651
|
-
case 'imagelayer':
|
|
652
|
-
return 'image';
|
|
653
|
-
case 'group':
|
|
654
|
-
return 'group';
|
|
655
|
-
default:
|
|
656
|
-
return 'object';
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
convertObject(obj, layerName, zIndex) {
|
|
660
|
-
const components = [];
|
|
661
|
-
// Determine shape type
|
|
662
|
-
if (obj.polygon) {
|
|
663
|
-
components.push({
|
|
664
|
-
type: 'PolygonCollider',
|
|
665
|
-
data: {
|
|
666
|
-
points: obj.polygon,
|
|
667
|
-
isTrigger: false,
|
|
668
|
-
},
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
else if (obj.polyline) {
|
|
672
|
-
components.push({
|
|
673
|
-
type: 'EdgeCollider',
|
|
674
|
-
data: {
|
|
675
|
-
points: obj.polyline,
|
|
676
|
-
},
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
else if (obj.ellipse) {
|
|
680
|
-
components.push({
|
|
681
|
-
type: 'CircleCollider',
|
|
682
|
-
data: {
|
|
683
|
-
radius: Math.max(obj.width, obj.height) / 2,
|
|
684
|
-
isTrigger: false,
|
|
685
|
-
},
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
else if (obj.point) {
|
|
689
|
-
components.push({
|
|
690
|
-
type: 'Point',
|
|
691
|
-
data: {},
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
else if (obj.text) {
|
|
695
|
-
components.push({
|
|
696
|
-
type: 'Text',
|
|
697
|
-
data: {
|
|
698
|
-
text: obj.text.text,
|
|
699
|
-
fontFamily: obj.text.fontFamily,
|
|
700
|
-
fontSize: obj.text.pixelSize,
|
|
701
|
-
color: obj.text.color,
|
|
702
|
-
bold: obj.text.bold,
|
|
703
|
-
italic: obj.text.italic,
|
|
704
|
-
align: obj.text.halign,
|
|
705
|
-
valign: obj.text.valign,
|
|
706
|
-
wrap: obj.text.wrap,
|
|
707
|
-
},
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
else if (obj.gid) {
|
|
711
|
-
// Tile object
|
|
712
|
-
const tileset = this.findTilesetForGid(obj.gid);
|
|
713
|
-
if (tileset) {
|
|
714
|
-
const localId = obj.gid - tileset.firstGid;
|
|
715
|
-
components.push({
|
|
716
|
-
type: 'Sprite',
|
|
717
|
-
data: {
|
|
718
|
-
tileset: tileset.name,
|
|
719
|
-
tileId: localId,
|
|
720
|
-
width: obj.width,
|
|
721
|
-
height: obj.height,
|
|
722
|
-
},
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
else {
|
|
727
|
-
// Rectangle
|
|
728
|
-
components.push({
|
|
729
|
-
type: 'BoxCollider',
|
|
730
|
-
data: {
|
|
731
|
-
width: obj.width,
|
|
732
|
-
height: obj.height,
|
|
733
|
-
isTrigger: false,
|
|
734
|
-
},
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
return {
|
|
738
|
-
id: obj.id.toString(),
|
|
739
|
-
name: obj.name || `Object_${obj.id}`,
|
|
740
|
-
type: obj.type || 'TiledObject',
|
|
741
|
-
x: obj.x,
|
|
742
|
-
y: obj.y,
|
|
522
|
+
}
|
|
523
|
+
Object.assign(tileset, externalTileset, { firstGid: tileset.firstGid });
|
|
524
|
+
} catch {
|
|
525
|
+
this.addWarning(
|
|
526
|
+
"TILESET_LOAD_ERROR",
|
|
527
|
+
`Failed to load external tileset: ${tileset.source}`,
|
|
528
|
+
tileset.source
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
this.tilesets.set(tileset.name, tileset);
|
|
533
|
+
this.tilesetsById.set(tileset.firstGid, tileset);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
// ----------------------------------------
|
|
537
|
+
// Conversion
|
|
538
|
+
// ----------------------------------------
|
|
539
|
+
convertTiledMapToScene(map) {
|
|
540
|
+
const layers = [];
|
|
541
|
+
const entities = [];
|
|
542
|
+
const zIndex = 0;
|
|
543
|
+
this.processLayers(map.layers, layers, entities, zIndex);
|
|
544
|
+
return {
|
|
545
|
+
name: "TiledMap",
|
|
546
|
+
width: map.width * map.tileWidth,
|
|
547
|
+
height: map.height * map.tileHeight,
|
|
548
|
+
backgroundColor: map.backgroundColor || "#000000",
|
|
549
|
+
layers,
|
|
550
|
+
entities,
|
|
551
|
+
properties: {
|
|
552
|
+
orientation: map.orientation,
|
|
553
|
+
renderOrder: map.renderOrder,
|
|
554
|
+
tileWidth: map.tileWidth,
|
|
555
|
+
tileHeight: map.tileHeight,
|
|
556
|
+
infinite: map.infinite,
|
|
557
|
+
...this.convertProperties(map.properties)
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
processLayers(layers, outLayers, outEntities, zIndex) {
|
|
562
|
+
for (const layer of layers) {
|
|
563
|
+
if (layer.type === "group" && layer.layers) {
|
|
564
|
+
zIndex = this.processLayers(layer.layers, outLayers, outEntities, zIndex);
|
|
565
|
+
} else {
|
|
566
|
+
outLayers.push(this.convertLayer(layer, zIndex));
|
|
567
|
+
if (layer.type === "objectgroup" && layer.objects) {
|
|
568
|
+
for (const obj of layer.objects) {
|
|
569
|
+
outEntities.push(this.convertObject(obj, layer.name, zIndex));
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
zIndex++;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return zIndex;
|
|
576
|
+
}
|
|
577
|
+
convertLayer(layer, zIndex) {
|
|
578
|
+
const parsedLayer = {
|
|
579
|
+
name: layer.name,
|
|
580
|
+
type: this.mapLayerType(layer.type),
|
|
581
|
+
visible: layer.visible,
|
|
582
|
+
opacity: layer.opacity,
|
|
583
|
+
offsetX: layer.offsetX,
|
|
584
|
+
offsetY: layer.offsetY,
|
|
585
|
+
parallaxX: layer.parallaxX,
|
|
586
|
+
parallaxY: layer.parallaxY,
|
|
587
|
+
zIndex,
|
|
588
|
+
properties: this.convertProperties(layer.properties)
|
|
589
|
+
};
|
|
590
|
+
if (layer.type === "tilelayer" && layer.data) {
|
|
591
|
+
parsedLayer.data = {
|
|
592
|
+
width: layer.width || 0,
|
|
593
|
+
height: layer.height || 0,
|
|
594
|
+
tileWidth: 0,
|
|
595
|
+
// Will be set from tileset
|
|
596
|
+
tileHeight: 0,
|
|
597
|
+
tiles: layer.data
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
return parsedLayer;
|
|
601
|
+
}
|
|
602
|
+
mapLayerType(type) {
|
|
603
|
+
switch (type) {
|
|
604
|
+
case "tilelayer":
|
|
605
|
+
return "tile";
|
|
606
|
+
case "objectgroup":
|
|
607
|
+
return "object";
|
|
608
|
+
case "imagelayer":
|
|
609
|
+
return "image";
|
|
610
|
+
case "group":
|
|
611
|
+
return "group";
|
|
612
|
+
default:
|
|
613
|
+
return "object";
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
convertObject(obj, layerName, zIndex) {
|
|
617
|
+
const components = [];
|
|
618
|
+
if (obj.polygon) {
|
|
619
|
+
components.push({
|
|
620
|
+
type: "PolygonCollider",
|
|
621
|
+
data: {
|
|
622
|
+
points: obj.polygon,
|
|
623
|
+
isTrigger: false
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
} else if (obj.polyline) {
|
|
627
|
+
components.push({
|
|
628
|
+
type: "EdgeCollider",
|
|
629
|
+
data: {
|
|
630
|
+
points: obj.polyline
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
} else if (obj.ellipse) {
|
|
634
|
+
components.push({
|
|
635
|
+
type: "CircleCollider",
|
|
636
|
+
data: {
|
|
637
|
+
radius: Math.max(obj.width, obj.height) / 2,
|
|
638
|
+
isTrigger: false
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
} else if (obj.point) {
|
|
642
|
+
components.push({
|
|
643
|
+
type: "Point",
|
|
644
|
+
data: {}
|
|
645
|
+
});
|
|
646
|
+
} else if (obj.text) {
|
|
647
|
+
components.push({
|
|
648
|
+
type: "Text",
|
|
649
|
+
data: {
|
|
650
|
+
text: obj.text.text,
|
|
651
|
+
fontFamily: obj.text.fontFamily,
|
|
652
|
+
fontSize: obj.text.pixelSize,
|
|
653
|
+
color: obj.text.color,
|
|
654
|
+
bold: obj.text.bold,
|
|
655
|
+
italic: obj.text.italic,
|
|
656
|
+
align: obj.text.halign,
|
|
657
|
+
valign: obj.text.valign,
|
|
658
|
+
wrap: obj.text.wrap
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
} else if (obj.gid) {
|
|
662
|
+
const tileset = this.findTilesetForGid(obj.gid);
|
|
663
|
+
if (tileset) {
|
|
664
|
+
const localId = obj.gid - tileset.firstGid;
|
|
665
|
+
components.push({
|
|
666
|
+
type: "Sprite",
|
|
667
|
+
data: {
|
|
668
|
+
tileset: tileset.name,
|
|
669
|
+
tileId: localId,
|
|
743
670
|
width: obj.width,
|
|
744
|
-
height: obj.height
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
671
|
+
height: obj.height
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
} else {
|
|
676
|
+
components.push({
|
|
677
|
+
type: "BoxCollider",
|
|
678
|
+
data: {
|
|
679
|
+
width: obj.width,
|
|
680
|
+
height: obj.height,
|
|
681
|
+
isTrigger: false
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
id: obj.id.toString(),
|
|
687
|
+
name: obj.name || `Object_${obj.id}`,
|
|
688
|
+
type: obj.type || "TiledObject",
|
|
689
|
+
x: obj.x,
|
|
690
|
+
y: obj.y,
|
|
691
|
+
width: obj.width,
|
|
692
|
+
height: obj.height,
|
|
693
|
+
rotation: obj.rotation,
|
|
694
|
+
scaleX: 1,
|
|
695
|
+
scaleY: 1,
|
|
696
|
+
visible: obj.visible,
|
|
697
|
+
components,
|
|
698
|
+
children: [],
|
|
699
|
+
properties: {
|
|
700
|
+
layer: layerName,
|
|
701
|
+
zIndex,
|
|
702
|
+
...this.convertProperties(obj.properties)
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
findTilesetForGid(gid) {
|
|
707
|
+
const tileId = gid & 268435455;
|
|
708
|
+
let result = null;
|
|
709
|
+
let maxFirstGid = 0;
|
|
710
|
+
for (const [_, tileset] of this.tilesetsById) {
|
|
711
|
+
if (tileset.firstGid <= tileId && tileset.firstGid > maxFirstGid) {
|
|
712
|
+
maxFirstGid = tileset.firstGid;
|
|
713
|
+
result = tileset;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return result;
|
|
717
|
+
}
|
|
718
|
+
convertProperties(props) {
|
|
719
|
+
if (!props) {
|
|
720
|
+
return {};
|
|
721
|
+
}
|
|
722
|
+
const result = {};
|
|
723
|
+
for (const prop of props) {
|
|
724
|
+
result[prop.name] = prop.value;
|
|
725
|
+
}
|
|
726
|
+
return result;
|
|
727
|
+
}
|
|
728
|
+
extractAssets(map) {
|
|
729
|
+
const assets = [];
|
|
730
|
+
for (const tileset of map.tilesets) {
|
|
731
|
+
if (tileset.image) {
|
|
732
|
+
assets.push({
|
|
733
|
+
id: this.generateId(),
|
|
734
|
+
name: tileset.name,
|
|
735
|
+
type: "tileset",
|
|
736
|
+
path: tileset.image,
|
|
737
|
+
data: {
|
|
738
|
+
tileWidth: tileset.tileWidth,
|
|
739
|
+
tileHeight: tileset.tileHeight,
|
|
740
|
+
tileCount: tileset.tileCount,
|
|
741
|
+
columns: tileset.columns,
|
|
742
|
+
margin: tileset.margin,
|
|
743
|
+
spacing: tileset.spacing,
|
|
744
|
+
firstGid: tileset.firstGid,
|
|
745
|
+
tiles: tileset.tiles?.map((t) => ({
|
|
746
|
+
id: t.id,
|
|
747
|
+
type: t.type,
|
|
748
|
+
animation: t.animation,
|
|
749
|
+
collision: t.objectGroup?.objects
|
|
750
|
+
}))
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
for (const layer of this.flattenLayers(map.layers)) {
|
|
756
|
+
if (layer.type === "imagelayer" && layer.image) {
|
|
757
|
+
assets.push({
|
|
758
|
+
id: this.generateId(),
|
|
759
|
+
name: layer.name + "_image",
|
|
760
|
+
type: "texture",
|
|
761
|
+
path: layer.image,
|
|
762
|
+
data: {
|
|
763
|
+
repeatX: layer.repeatX,
|
|
764
|
+
repeatY: layer.repeatY
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return assets;
|
|
770
|
+
}
|
|
771
|
+
flattenLayers(layers) {
|
|
772
|
+
const result = [];
|
|
773
|
+
for (const layer of layers) {
|
|
774
|
+
result.push(layer);
|
|
775
|
+
if (layer.type === "group" && layer.layers) {
|
|
776
|
+
result.push(...this.flattenLayers(layer.layers));
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return result;
|
|
780
|
+
}
|
|
781
|
+
// ----------------------------------------
|
|
782
|
+
// Helper Methods
|
|
783
|
+
// ----------------------------------------
|
|
784
|
+
async readFile(path) {
|
|
785
|
+
if (typeof globalThis.process !== "undefined" && globalThis.process.versions?.node) {
|
|
786
|
+
const fs = await import("fs");
|
|
787
|
+
return fs.readFileSync(path, "utf-8");
|
|
788
|
+
} else if (typeof fetch !== "undefined") {
|
|
789
|
+
const response = await fetch(path);
|
|
790
|
+
return response.text();
|
|
791
|
+
}
|
|
792
|
+
throw new Error("Unable to read file in current environment");
|
|
793
|
+
}
|
|
850
794
|
}
|
|
851
|
-
|
|
852
|
-
|
|
795
|
+
export {
|
|
796
|
+
TiledMapImporter
|
|
797
|
+
};
|