@nice2dev/game-engine 1.0.2 → 1.0.4

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.
Files changed (188) hide show
  1. package/dist/cjs/ai/BehaviorTree.js +1215 -0
  2. package/dist/cjs/ai/BehaviorTree.js.map +1 -0
  3. package/dist/cjs/ai/StateMachine.js +783 -0
  4. package/dist/cjs/ai/StateMachine.js.map +1 -0
  5. package/dist/cjs/editor/ShaderGraph.js +1616 -0
  6. package/dist/cjs/editor/ShaderGraph.js.map +1 -0
  7. package/dist/cjs/editor/TimelineEditor.js +819 -0
  8. package/dist/cjs/editor/TimelineEditor.js.map +1 -0
  9. package/dist/cjs/export/GodotExporter.js +1102 -0
  10. package/dist/cjs/export/GodotExporter.js.map +1 -0
  11. package/dist/cjs/export/PlatformExporter.js +236 -0
  12. package/dist/cjs/export/PlatformExporter.js.map +1 -0
  13. package/dist/cjs/export/ThreeJSExporter.js +1116 -0
  14. package/dist/cjs/export/ThreeJSExporter.js.map +1 -0
  15. package/dist/cjs/export/UnityExporter.js +1193 -0
  16. package/dist/cjs/export/UnityExporter.js.map +1 -0
  17. package/dist/cjs/export/WebExporter.js +1036 -0
  18. package/dist/cjs/export/WebExporter.js.map +1 -0
  19. package/dist/cjs/export/index.js +58 -0
  20. package/dist/cjs/export/index.js.map +1 -0
  21. package/dist/cjs/import/AsepriteImporter.js +761 -0
  22. package/dist/cjs/import/AsepriteImporter.js.map +1 -0
  23. package/dist/cjs/import/DragonBonesImporter.js +499 -0
  24. package/dist/cjs/import/DragonBonesImporter.js.map +1 -0
  25. package/dist/cjs/import/GameMakerImporter.js +559 -0
  26. package/dist/cjs/import/GameMakerImporter.js.map +1 -0
  27. package/dist/cjs/import/GodotSceneImporter.js +824 -0
  28. package/dist/cjs/import/GodotSceneImporter.js.map +1 -0
  29. package/dist/cjs/import/LDtkImporter.js +481 -0
  30. package/dist/cjs/import/LDtkImporter.js.map +1 -0
  31. package/dist/cjs/import/Live2DImporter.js +553 -0
  32. package/dist/cjs/import/Live2DImporter.js.map +1 -0
  33. package/dist/cjs/import/NdgFormat.js +499 -0
  34. package/dist/cjs/import/NdgFormat.js.map +1 -0
  35. package/dist/cjs/import/OgmoImporter.js +529 -0
  36. package/dist/cjs/import/OgmoImporter.js.map +1 -0
  37. package/dist/cjs/import/RPGMakerImporter.js +520 -0
  38. package/dist/cjs/import/RPGMakerImporter.js.map +1 -0
  39. package/dist/cjs/import/SceneImporter.js +449 -0
  40. package/dist/cjs/import/SceneImporter.js.map +1 -0
  41. package/dist/cjs/import/SpineImporter.js +583 -0
  42. package/dist/cjs/import/SpineImporter.js.map +1 -0
  43. package/dist/cjs/import/SpriterImporter.js +652 -0
  44. package/dist/cjs/import/SpriterImporter.js.map +1 -0
  45. package/dist/cjs/import/TiledMapImporter.js +859 -0
  46. package/dist/cjs/import/TiledMapImporter.js.map +1 -0
  47. package/dist/cjs/import/UnitySceneImporter.js +732 -0
  48. package/dist/cjs/import/UnitySceneImporter.js.map +1 -0
  49. package/dist/cjs/import/index.js +305 -0
  50. package/dist/cjs/import/index.js.map +1 -0
  51. package/dist/cjs/index.js +201 -0
  52. package/dist/cjs/index.js.map +1 -1
  53. package/dist/cjs/scripting/GraphToAST.js +567 -0
  54. package/dist/cjs/scripting/GraphToAST.js.map +1 -0
  55. package/dist/cjs/scripting/LanguageExporter.js +321 -0
  56. package/dist/cjs/scripting/LanguageExporter.js.map +1 -0
  57. package/dist/cjs/scripting/ScriptAST.js +67 -0
  58. package/dist/cjs/scripting/ScriptAST.js.map +1 -0
  59. package/dist/cjs/scripting/VisualScripting2.js +1140 -0
  60. package/dist/cjs/scripting/VisualScripting2.js.map +1 -0
  61. package/dist/cjs/scripting/exporters/CSharpExporter.js +503 -0
  62. package/dist/cjs/scripting/exporters/CSharpExporter.js.map +1 -0
  63. package/dist/cjs/scripting/exporters/GDScriptExporter.js +452 -0
  64. package/dist/cjs/scripting/exporters/GDScriptExporter.js.map +1 -0
  65. package/dist/cjs/scripting/exporters/LuaExporter.js +457 -0
  66. package/dist/cjs/scripting/exporters/LuaExporter.js.map +1 -0
  67. package/dist/cjs/scripting/exporters/PythonExporter.js +565 -0
  68. package/dist/cjs/scripting/exporters/PythonExporter.js.map +1 -0
  69. package/dist/cjs/scripting/exporters/RustExporter.js +525 -0
  70. package/dist/cjs/scripting/exporters/RustExporter.js.map +1 -0
  71. package/dist/cjs/scripting/exporters/TypeScriptExporter.js +570 -0
  72. package/dist/cjs/scripting/exporters/TypeScriptExporter.js.map +1 -0
  73. package/dist/cjs/systems/ParticleSystem2.js +1478 -0
  74. package/dist/cjs/systems/ParticleSystem2.js.map +1 -0
  75. package/dist/esm/ai/BehaviorTree.js +1186 -0
  76. package/dist/esm/ai/BehaviorTree.js.map +1 -0
  77. package/dist/esm/ai/StateMachine.js +767 -0
  78. package/dist/esm/ai/StateMachine.js.map +1 -0
  79. package/dist/esm/editor/ShaderGraph.js +1606 -0
  80. package/dist/esm/editor/ShaderGraph.js.map +1 -0
  81. package/dist/esm/editor/TimelineEditor.js +800 -0
  82. package/dist/esm/editor/TimelineEditor.js.map +1 -0
  83. package/dist/esm/export/GodotExporter.js +1100 -0
  84. package/dist/esm/export/GodotExporter.js.map +1 -0
  85. package/dist/esm/export/PlatformExporter.js +230 -0
  86. package/dist/esm/export/PlatformExporter.js.map +1 -0
  87. package/dist/esm/export/ThreeJSExporter.js +1114 -0
  88. package/dist/esm/export/ThreeJSExporter.js.map +1 -0
  89. package/dist/esm/export/UnityExporter.js +1191 -0
  90. package/dist/esm/export/UnityExporter.js.map +1 -0
  91. package/dist/esm/export/WebExporter.js +1033 -0
  92. package/dist/esm/export/WebExporter.js.map +1 -0
  93. package/dist/esm/export/index.js +44 -0
  94. package/dist/esm/export/index.js.map +1 -0
  95. package/dist/esm/import/AsepriteImporter.js +759 -0
  96. package/dist/esm/import/AsepriteImporter.js.map +1 -0
  97. package/dist/esm/import/DragonBonesImporter.js +496 -0
  98. package/dist/esm/import/DragonBonesImporter.js.map +1 -0
  99. package/dist/esm/import/GameMakerImporter.js +556 -0
  100. package/dist/esm/import/GameMakerImporter.js.map +1 -0
  101. package/dist/esm/import/GodotSceneImporter.js +822 -0
  102. package/dist/esm/import/GodotSceneImporter.js.map +1 -0
  103. package/dist/esm/import/LDtkImporter.js +479 -0
  104. package/dist/esm/import/LDtkImporter.js.map +1 -0
  105. package/dist/esm/import/Live2DImporter.js +550 -0
  106. package/dist/esm/import/Live2DImporter.js.map +1 -0
  107. package/dist/esm/import/NdgFormat.js +490 -0
  108. package/dist/esm/import/NdgFormat.js.map +1 -0
  109. package/dist/esm/import/OgmoImporter.js +526 -0
  110. package/dist/esm/import/OgmoImporter.js.map +1 -0
  111. package/dist/esm/import/RPGMakerImporter.js +517 -0
  112. package/dist/esm/import/RPGMakerImporter.js.map +1 -0
  113. package/dist/esm/import/SceneImporter.js +441 -0
  114. package/dist/esm/import/SceneImporter.js.map +1 -0
  115. package/dist/esm/import/SpineImporter.js +580 -0
  116. package/dist/esm/import/SpineImporter.js.map +1 -0
  117. package/dist/esm/import/SpriterImporter.js +649 -0
  118. package/dist/esm/import/SpriterImporter.js.map +1 -0
  119. package/dist/esm/import/TiledMapImporter.js +857 -0
  120. package/dist/esm/import/TiledMapImporter.js.map +1 -0
  121. package/dist/esm/import/UnitySceneImporter.js +730 -0
  122. package/dist/esm/import/UnitySceneImporter.js.map +1 -0
  123. package/dist/esm/import/index.js +279 -0
  124. package/dist/esm/import/index.js.map +1 -0
  125. package/dist/esm/index.js +36 -0
  126. package/dist/esm/index.js.map +1 -1
  127. package/dist/esm/scripting/GraphToAST.js +564 -0
  128. package/dist/esm/scripting/GraphToAST.js.map +1 -0
  129. package/dist/esm/scripting/LanguageExporter.js +311 -0
  130. package/dist/esm/scripting/LanguageExporter.js.map +1 -0
  131. package/dist/esm/scripting/ScriptAST.js +52 -0
  132. package/dist/esm/scripting/ScriptAST.js.map +1 -0
  133. package/dist/esm/scripting/VisualScripting2.js +1130 -0
  134. package/dist/esm/scripting/VisualScripting2.js.map +1 -0
  135. package/dist/esm/scripting/exporters/CSharpExporter.js +501 -0
  136. package/dist/esm/scripting/exporters/CSharpExporter.js.map +1 -0
  137. package/dist/esm/scripting/exporters/GDScriptExporter.js +450 -0
  138. package/dist/esm/scripting/exporters/GDScriptExporter.js.map +1 -0
  139. package/dist/esm/scripting/exporters/LuaExporter.js +455 -0
  140. package/dist/esm/scripting/exporters/LuaExporter.js.map +1 -0
  141. package/dist/esm/scripting/exporters/PythonExporter.js +563 -0
  142. package/dist/esm/scripting/exporters/PythonExporter.js.map +1 -0
  143. package/dist/esm/scripting/exporters/RustExporter.js +523 -0
  144. package/dist/esm/scripting/exporters/RustExporter.js.map +1 -0
  145. package/dist/esm/scripting/exporters/TypeScriptExporter.js +568 -0
  146. package/dist/esm/scripting/exporters/TypeScriptExporter.js.map +1 -0
  147. package/dist/esm/systems/ParticleSystem2.js +1471 -0
  148. package/dist/esm/systems/ParticleSystem2.js.map +1 -0
  149. package/dist/types/ai/BehaviorTree.d.ts +375 -0
  150. package/dist/types/ai/StateMachine.d.ts +296 -0
  151. package/dist/types/editor/ShaderGraph.d.ts +207 -0
  152. package/dist/types/editor/TimelineEditor.d.ts +393 -0
  153. package/dist/types/export/GodotExporter.d.ts +56 -0
  154. package/dist/types/export/PlatformExporter.d.ts +201 -0
  155. package/dist/types/export/ThreeJSExporter.d.ts +40 -0
  156. package/dist/types/export/UnityExporter.d.ts +69 -0
  157. package/dist/types/export/WebExporter.d.ts +58 -0
  158. package/dist/types/export/index.d.ts +19 -0
  159. package/dist/types/import/AsepriteImporter.d.ts +46 -0
  160. package/dist/types/import/DragonBonesImporter.d.ts +331 -0
  161. package/dist/types/import/GameMakerImporter.d.ts +375 -0
  162. package/dist/types/import/GodotSceneImporter.d.ts +34 -0
  163. package/dist/types/import/LDtkImporter.d.ts +177 -0
  164. package/dist/types/import/Live2DImporter.d.ts +237 -0
  165. package/dist/types/import/NdgFormat.d.ts +387 -0
  166. package/dist/types/import/OgmoImporter.d.ts +237 -0
  167. package/dist/types/import/RPGMakerImporter.d.ts +186 -0
  168. package/dist/types/import/SceneImporter.d.ts +276 -0
  169. package/dist/types/import/SpineImporter.d.ts +372 -0
  170. package/dist/types/import/SpriterImporter.d.ts +230 -0
  171. package/dist/types/import/TiledMapImporter.d.ts +57 -0
  172. package/dist/types/import/UnitySceneImporter.d.ts +87 -0
  173. package/dist/types/import/index.d.ts +59 -0
  174. package/dist/types/index.d.ts +29 -17
  175. package/dist/types/scripting/GraphToAST.d.ts +55 -0
  176. package/dist/types/scripting/LanguageExporter.d.ts +136 -0
  177. package/dist/types/scripting/ScriptAST.d.ts +312 -0
  178. package/dist/types/scripting/VisualScripting2.d.ts +353 -0
  179. package/dist/types/scripting/exporters/CSharpExporter.d.ts +44 -0
  180. package/dist/types/scripting/exporters/GDScriptExporter.d.ts +46 -0
  181. package/dist/types/scripting/exporters/LuaExporter.d.ts +46 -0
  182. package/dist/types/scripting/exporters/PythonExporter.d.ts +49 -0
  183. package/dist/types/scripting/exporters/RustExporter.d.ts +46 -0
  184. package/dist/types/scripting/exporters/TypeScriptExporter.d.ts +48 -0
  185. package/dist/types/scripting/exporters/index.d.ts +8 -0
  186. package/dist/types/scripting/index.d.ts +11 -0
  187. package/dist/types/systems/ParticleSystem2.d.ts +646 -0
  188. package/package.json +3 -3
@@ -0,0 +1,822 @@
1
+ import { SceneImporter } from './SceneImporter.js';
2
+
3
+ /**
4
+ * @file GodotSceneImporter.ts
5
+ * @description Import Godot scenes (.tscn) and resources (.tres)
6
+ * PRO-1.3: Scene Format Interoperability
7
+ *
8
+ * Parses Godot 4.x scene format and converts to Nice2Dev entities.
9
+ * Supports:
10
+ * - Scene files (.tscn)
11
+ * - Resource files (.tres)
12
+ * - Project files (.godot)
13
+ */
14
+ // ============================================================
15
+ // Godot Node Types Mapping
16
+ // ============================================================
17
+ const GODOT_NODE_MAPPING = {
18
+ // 2D Nodes
19
+ Node2D: { niceType: 'Transform2D', category: '2d' },
20
+ Sprite2D: { niceType: 'Sprite', category: '2d' },
21
+ AnimatedSprite2D: { niceType: 'AnimatedSprite', category: '2d' },
22
+ CharacterBody2D: { niceType: 'CharacterController2D', category: '2d' },
23
+ RigidBody2D: { niceType: 'Rigidbody2D', category: '2d' },
24
+ StaticBody2D: { niceType: 'StaticBody2D', category: '2d' },
25
+ Area2D: { niceType: 'Trigger2D', category: '2d' },
26
+ CollisionShape2D: { niceType: 'Collider2D', category: '2d' },
27
+ CollisionPolygon2D: { niceType: 'PolygonCollider2D', category: '2d' },
28
+ TileMap: { niceType: 'Tilemap', category: '2d' },
29
+ TileMapLayer: { niceType: 'TilemapLayer', category: '2d' },
30
+ Camera2D: { niceType: 'Camera2D', category: '2d' },
31
+ Light2D: { niceType: 'Light2D', category: '2d' },
32
+ PointLight2D: { niceType: 'PointLight2D', category: '2d' },
33
+ DirectionalLight2D: { niceType: 'DirectionalLight2D', category: '2d' },
34
+ Line2D: { niceType: 'LineRenderer', category: '2d' },
35
+ Path2D: { niceType: 'Path2D', category: '2d' },
36
+ PathFollow2D: { niceType: 'PathFollower2D', category: '2d' },
37
+ GPUParticles2D: { niceType: 'ParticleSystem2D', category: '2d' },
38
+ CPUParticles2D: { niceType: 'CPUParticles2D', category: '2d' },
39
+ // 3D Nodes
40
+ Node3D: { niceType: 'Transform3D', category: '3d' },
41
+ MeshInstance3D: { niceType: 'MeshRenderer', category: '3d' },
42
+ CharacterBody3D: { niceType: 'CharacterController3D', category: '3d' },
43
+ RigidBody3D: { niceType: 'Rigidbody3D', category: '3d' },
44
+ StaticBody3D: { niceType: 'StaticBody3D', category: '3d' },
45
+ Area3D: { niceType: 'Trigger3D', category: '3d' },
46
+ CollisionShape3D: { niceType: 'Collider3D', category: '3d' },
47
+ Camera3D: { niceType: 'Camera3D', category: '3d' },
48
+ DirectionalLight3D: { niceType: 'DirectionalLight', category: '3d' },
49
+ OmniLight3D: { niceType: 'PointLight', category: '3d' },
50
+ SpotLight3D: { niceType: 'SpotLight', category: '3d' },
51
+ GPUParticles3D: { niceType: 'ParticleSystem3D', category: '3d' },
52
+ // Audio
53
+ AudioStreamPlayer: { niceType: 'AudioSource', category: 'audio' },
54
+ AudioStreamPlayer2D: { niceType: 'AudioSource2D', category: 'audio' },
55
+ AudioStreamPlayer3D: { niceType: 'AudioSource3D', category: 'audio' },
56
+ // UI
57
+ Control: { niceType: 'UIElement', category: 'ui' },
58
+ Label: { niceType: 'Text', category: 'ui' },
59
+ Button: { niceType: 'Button', category: 'ui' },
60
+ TextureRect: { niceType: 'Image', category: 'ui' },
61
+ Panel: { niceType: 'Panel', category: 'ui' },
62
+ HBoxContainer: { niceType: 'HorizontalLayout', category: 'ui' },
63
+ VBoxContainer: { niceType: 'VerticalLayout', category: 'ui' },
64
+ GridContainer: { niceType: 'GridLayout', category: 'ui' },
65
+ ScrollContainer: { niceType: 'ScrollView', category: 'ui' },
66
+ LineEdit: { niceType: 'InputField', category: 'ui' },
67
+ TextEdit: { niceType: 'TextArea', category: 'ui' },
68
+ CheckBox: { niceType: 'Checkbox', category: 'ui' },
69
+ ProgressBar: { niceType: 'ProgressBar', category: 'ui' },
70
+ Slider: { niceType: 'Slider', category: 'ui' },
71
+ SpinBox: { niceType: 'SpinBox', category: 'ui' },
72
+ ColorRect: { niceType: 'ColorPanel', category: 'ui' },
73
+ NinePatchRect: { niceType: 'NineSlice', category: 'ui' },
74
+ CanvasLayer: { niceType: 'UICanvas', category: 'ui' },
75
+ // Animation
76
+ AnimationPlayer: { niceType: 'Animator', category: 'animation' },
77
+ AnimationTree: { niceType: 'AnimationStateMachine', category: 'animation' },
78
+ // Navigation
79
+ NavigationRegion2D: { niceType: 'NavMesh2D', category: 'navigation' },
80
+ NavigationAgent2D: { niceType: 'NavAgent2D', category: 'navigation' },
81
+ NavigationRegion3D: { niceType: 'NavMesh3D', category: 'navigation' },
82
+ NavigationAgent3D: { niceType: 'NavAgent3D', category: 'navigation' },
83
+ // Other
84
+ Timer: { niceType: 'Timer', category: 'utility' },
85
+ HTTPRequest: { niceType: 'HTTPClient', category: 'utility' },
86
+ };
87
+ // ============================================================
88
+ // Godot Scene Importer
89
+ // ============================================================
90
+ class GodotSceneImporter extends SceneImporter {
91
+ constructor() {
92
+ super('godot');
93
+ this.extResources = new Map();
94
+ this.subResources = new Map();
95
+ this.nodes = [];
96
+ this.connections = [];
97
+ this.header = {};
98
+ }
99
+ async import(options) {
100
+ const startTime = Date.now();
101
+ this.options = options;
102
+ this.clearMessages();
103
+ this.extResources.clear();
104
+ this.subResources.clear();
105
+ this.nodes = [];
106
+ this.connections = [];
107
+ const errors = await this.validate(options.sourcePath);
108
+ if (errors.some((e) => e.fatal)) {
109
+ return {
110
+ ...this.createEmptyResult(),
111
+ errors: errors,
112
+ };
113
+ }
114
+ const scenes = [];
115
+ const assets = [];
116
+ try {
117
+ const content = await this.readFile(options.sourcePath);
118
+ const parsed = this.parseGodotScene(content, options.sourcePath);
119
+ if (parsed) {
120
+ const niceScene = this.convertParsedToNiceScene(parsed);
121
+ scenes.push(niceScene);
122
+ const extractedAssets = this.extractAssets();
123
+ assets.push(...extractedAssets);
124
+ }
125
+ }
126
+ catch (error) {
127
+ this.addError('IMPORT_ERROR', `Failed to import: ${error}`, options.sourcePath, undefined, true);
128
+ }
129
+ return this.createResult(scenes, assets, startTime);
130
+ }
131
+ async parseFile(content, filePath) {
132
+ const stringContent = typeof content === 'string' ? content : new TextDecoder().decode(content);
133
+ return this.parseGodotScene(stringContent, filePath);
134
+ }
135
+ async validate(sourcePath) {
136
+ const errors = [];
137
+ if (!this.canHandle(sourcePath)) {
138
+ errors.push({
139
+ code: 'INVALID_FORMAT',
140
+ message: `File ${sourcePath} is not a valid Godot file`,
141
+ file: sourcePath,
142
+ fatal: true,
143
+ });
144
+ }
145
+ return errors;
146
+ }
147
+ // ----------------------------------------
148
+ // Godot Parsing
149
+ // ----------------------------------------
150
+ parseGodotScene(content, filePath) {
151
+ const lines = content.split('\n');
152
+ let currentSection = null;
153
+ let currentItem = {};
154
+ let bracketDepth = 0;
155
+ let multilineKey = '';
156
+ let multilineValue = '';
157
+ for (const line of lines) {
158
+ const trimmed = line.trim();
159
+ // Skip empty lines and comments
160
+ if (trimmed === '' || trimmed.startsWith(';'))
161
+ continue;
162
+ // Check for section headers
163
+ const sectionMatch = trimmed.match(/^\[(\w+)(.*?)\]$/);
164
+ if (sectionMatch) {
165
+ // Save previous item
166
+ this.saveCurrentItem(currentSection, currentItem);
167
+ currentItem = {};
168
+ const sectionType = sectionMatch[1];
169
+ const sectionParams = sectionMatch[2].trim();
170
+ if (sectionType === 'gd_scene' || sectionType === 'gd_resource') {
171
+ currentSection = 'header';
172
+ this.header = this.parseInlineParams(sectionParams);
173
+ }
174
+ else if (sectionType === 'ext_resource') {
175
+ currentSection = 'ext_resource';
176
+ currentItem = this.parseInlineParams(sectionParams);
177
+ }
178
+ else if (sectionType === 'sub_resource') {
179
+ currentSection = 'sub_resource';
180
+ currentItem = this.parseInlineParams(sectionParams);
181
+ }
182
+ else if (sectionType === 'node') {
183
+ currentSection = 'node';
184
+ currentItem = this.parseInlineParams(sectionParams);
185
+ }
186
+ else if (sectionType === 'connection') {
187
+ currentSection = 'connection';
188
+ currentItem = this.parseInlineParams(sectionParams);
189
+ }
190
+ continue;
191
+ }
192
+ // Handle multiline values
193
+ if (multilineKey) {
194
+ multilineValue += '\n' + line;
195
+ bracketDepth += (line.match(/[\[\{]/g) || []).length;
196
+ bracketDepth -= (line.match(/[\]\}]/g) || []).length;
197
+ if (bracketDepth === 0) {
198
+ currentItem[multilineKey] = this.parseGodotValue(multilineValue);
199
+ multilineKey = '';
200
+ multilineValue = '';
201
+ }
202
+ continue;
203
+ }
204
+ // Parse property assignment
205
+ const propMatch = trimmed.match(/^(\w+)\s*=\s*(.*)$/);
206
+ if (propMatch) {
207
+ const key = propMatch[1];
208
+ const value = propMatch[2];
209
+ // Check if value starts multiline
210
+ bracketDepth = (value.match(/[\[\{]/g) || []).length;
211
+ bracketDepth -= (value.match(/[\]\}]/g) || []).length;
212
+ if (bracketDepth > 0) {
213
+ multilineKey = key;
214
+ multilineValue = value;
215
+ }
216
+ else {
217
+ currentItem[key] = this.parseGodotValue(value);
218
+ }
219
+ }
220
+ }
221
+ // Save final item
222
+ this.saveCurrentItem(currentSection, currentItem);
223
+ // Build scene structure
224
+ const sceneName = filePath.substring(filePath.lastIndexOf('/') + 1).replace(/\.\w+$/, '');
225
+ // Find root node
226
+ const rootNode = this.nodes.find((n) => !n.parent);
227
+ return {
228
+ name: sceneName,
229
+ width: 1920,
230
+ height: 1080,
231
+ backgroundColor: '#1a1a2e',
232
+ layers: [],
233
+ entities: rootNode ? [this.convertNodeToEntity(rootNode)] : [],
234
+ properties: {
235
+ godotVersion: this.header.gdVersion,
236
+ format: this.header.format,
237
+ loadSteps: this.header.loadSteps,
238
+ },
239
+ };
240
+ }
241
+ saveCurrentItem(section, item) {
242
+ if (!section || Object.keys(item).length === 0)
243
+ return;
244
+ switch (section) {
245
+ case 'ext_resource':
246
+ const extRes = {
247
+ id: String(item.id || ''),
248
+ type: String(item.type || ''),
249
+ path: String(item.path || ''),
250
+ uid: item.uid ? String(item.uid) : undefined,
251
+ };
252
+ this.extResources.set(extRes.id, extRes);
253
+ break;
254
+ case 'sub_resource':
255
+ const subRes = {
256
+ id: String(item.id || ''),
257
+ type: String(item.type || ''),
258
+ properties: { ...item },
259
+ };
260
+ delete subRes.properties.id;
261
+ delete subRes.properties.type;
262
+ this.subResources.set(subRes.id, subRes);
263
+ break;
264
+ case 'node':
265
+ const node = {
266
+ name: String(item.name || ''),
267
+ type: item.type ? String(item.type) : undefined,
268
+ parent: item.parent ? String(item.parent) : undefined,
269
+ instance: item.instance ? String(item.instance) : undefined,
270
+ instancePlaceholder: item.instance_placeholder
271
+ ? String(item.instance_placeholder)
272
+ : undefined,
273
+ owner: item.owner ? String(item.owner) : undefined,
274
+ index: item.index ? Number(item.index) : undefined,
275
+ groups: item.groups ? item.groups : undefined,
276
+ properties: {},
277
+ children: [],
278
+ };
279
+ // Copy remaining properties
280
+ for (const [key, value] of Object.entries(item)) {
281
+ if (![
282
+ 'name',
283
+ 'type',
284
+ 'parent',
285
+ 'instance',
286
+ 'instance_placeholder',
287
+ 'owner',
288
+ 'index',
289
+ 'groups',
290
+ ].includes(key)) {
291
+ node.properties[key] = value;
292
+ }
293
+ }
294
+ this.nodes.push(node);
295
+ break;
296
+ case 'connection':
297
+ const conn = {
298
+ signal: String(item.signal || ''),
299
+ from: String(item.from || ''),
300
+ to: String(item.to || ''),
301
+ method: String(item.method || ''),
302
+ flags: item.flags ? Number(item.flags) : undefined,
303
+ binds: item.binds,
304
+ };
305
+ this.connections.push(conn);
306
+ break;
307
+ }
308
+ }
309
+ parseInlineParams(params) {
310
+ const result = {};
311
+ // Parse space-separated key=value pairs
312
+ const paramRegex = /(\w+)=("(?:[^"\\]|\\.)*"|[^\s]+)/g;
313
+ let match;
314
+ while ((match = paramRegex.exec(params)) !== null) {
315
+ const key = match[1];
316
+ let value = match[2];
317
+ // Remove quotes
318
+ if (value.startsWith('"') && value.endsWith('"')) {
319
+ value = value.slice(1, -1).replace(/\\"/g, '"');
320
+ }
321
+ result[key] = this.parseGodotValue(value);
322
+ }
323
+ return result;
324
+ }
325
+ parseGodotValue(value) {
326
+ value = value.trim();
327
+ // Null
328
+ if (value === 'null')
329
+ return null;
330
+ // Boolean
331
+ if (value === 'true')
332
+ return true;
333
+ if (value === 'false')
334
+ return false;
335
+ // Number
336
+ if (/^-?\d+$/.test(value))
337
+ return parseInt(value, 10);
338
+ if (/^-?\d+\.\d+$/.test(value))
339
+ return parseFloat(value);
340
+ // String
341
+ if (value.startsWith('"') && value.endsWith('"')) {
342
+ return value.slice(1, -1).replace(/\\"/g, '"').replace(/\\n/g, '\n');
343
+ }
344
+ // Vector2
345
+ const vec2Match = value.match(/^Vector2\s*\(\s*([\d.-]+)\s*,\s*([\d.-]+)\s*\)$/);
346
+ if (vec2Match) {
347
+ return {
348
+ _type: 'Vector2',
349
+ x: parseFloat(vec2Match[1]),
350
+ y: parseFloat(vec2Match[2]),
351
+ };
352
+ }
353
+ // Vector3
354
+ const vec3Match = value.match(/^Vector3\s*\(\s*([\d.-]+)\s*,\s*([\d.-]+)\s*,\s*([\d.-]+)\s*\)$/);
355
+ if (vec3Match) {
356
+ return {
357
+ _type: 'Vector3',
358
+ x: parseFloat(vec3Match[1]),
359
+ y: parseFloat(vec3Match[2]),
360
+ z: parseFloat(vec3Match[3]),
361
+ };
362
+ }
363
+ // Rect2
364
+ const rect2Match = value.match(/^Rect2\s*\(\s*([\d.-]+)\s*,\s*([\d.-]+)\s*,\s*([\d.-]+)\s*,\s*([\d.-]+)\s*\)$/);
365
+ if (rect2Match) {
366
+ return {
367
+ _type: 'Rect2',
368
+ x: parseFloat(rect2Match[1]),
369
+ y: parseFloat(rect2Match[2]),
370
+ width: parseFloat(rect2Match[3]),
371
+ height: parseFloat(rect2Match[4]),
372
+ };
373
+ }
374
+ // Color
375
+ const colorMatch = value.match(/^Color\s*\(\s*([\d.-]+)\s*,\s*([\d.-]+)\s*,\s*([\d.-]+)\s*(?:,\s*([\d.-]+))?\s*\)$/);
376
+ if (colorMatch) {
377
+ return {
378
+ _type: 'Color',
379
+ r: parseFloat(colorMatch[1]),
380
+ g: parseFloat(colorMatch[2]),
381
+ b: parseFloat(colorMatch[3]),
382
+ a: colorMatch[4] ? parseFloat(colorMatch[4]) : 1.0,
383
+ };
384
+ }
385
+ // ExtResource
386
+ const extResMatch = value.match(/^ExtResource\s*\(\s*"?(\d+)"?\s*\)$/);
387
+ if (extResMatch) {
388
+ return { _type: 'ExtResource', id: extResMatch[1] };
389
+ }
390
+ // SubResource
391
+ const subResMatch = value.match(/^SubResource\s*\(\s*"?(\d+)"?\s*\)$/);
392
+ if (subResMatch) {
393
+ return { _type: 'SubResource', id: subResMatch[1] };
394
+ }
395
+ // Array
396
+ if (value.startsWith('[') && value.endsWith(']')) {
397
+ return this.parseGodotArray(value);
398
+ }
399
+ // Dictionary
400
+ if (value.startsWith('{') && value.endsWith('}')) {
401
+ return this.parseGodotDictionary(value);
402
+ }
403
+ // Unquoted string
404
+ return value;
405
+ }
406
+ parseGodotArray(value) {
407
+ const content = value.slice(1, -1).trim();
408
+ if (!content)
409
+ return [];
410
+ const items = [];
411
+ let depth = 0;
412
+ let current = '';
413
+ for (let i = 0; i < content.length; i++) {
414
+ const char = content[i];
415
+ if (char === '[' || char === '{' || char === '(')
416
+ depth++;
417
+ else if (char === ']' || char === '}' || char === ')')
418
+ depth--;
419
+ if (char === ',' && depth === 0) {
420
+ items.push(this.parseGodotValue(current.trim()));
421
+ current = '';
422
+ }
423
+ else {
424
+ current += char;
425
+ }
426
+ }
427
+ if (current.trim()) {
428
+ items.push(this.parseGodotValue(current.trim()));
429
+ }
430
+ return items;
431
+ }
432
+ parseGodotDictionary(value) {
433
+ const content = value.slice(1, -1).trim();
434
+ if (!content)
435
+ return {};
436
+ const result = {};
437
+ let depth = 0;
438
+ let current = '';
439
+ let key = '';
440
+ let inKey = true;
441
+ for (let i = 0; i < content.length; i++) {
442
+ const char = content[i];
443
+ if (char === '[' || char === '{' || char === '(')
444
+ depth++;
445
+ else if (char === ']' || char === '}' || char === ')')
446
+ depth--;
447
+ if (char === ':' && depth === 0 && inKey) {
448
+ key = current.trim().replace(/^"|"$/g, '');
449
+ current = '';
450
+ inKey = false;
451
+ }
452
+ else if (char === ',' && depth === 0) {
453
+ result[key] = this.parseGodotValue(current.trim());
454
+ current = '';
455
+ key = '';
456
+ inKey = true;
457
+ }
458
+ else {
459
+ current += char;
460
+ }
461
+ }
462
+ if (key && current.trim()) {
463
+ result[key] = this.parseGodotValue(current.trim());
464
+ }
465
+ return result;
466
+ }
467
+ convertNodeToEntity(node) {
468
+ const mapping = GODOT_NODE_MAPPING[node.type || ''] || {
469
+ niceType: node.type || 'Node',
470
+ category: 'unknown',
471
+ };
472
+ // Find children
473
+ const children = this.nodes.filter((n) => {
474
+ if (!n.parent)
475
+ return false;
476
+ // Parent is "." means direct child of root
477
+ if (n.parent === '.')
478
+ return node.parent === undefined;
479
+ // Match by path
480
+ return n.parent === node.name || n.parent.endsWith('/' + node.name);
481
+ });
482
+ // Extract position and rotation
483
+ const position = this.extractVector2(node.properties.position) || { x: 0, y: 0 };
484
+ const rotation = typeof node.properties.rotation === 'number' ? node.properties.rotation * (180 / Math.PI) : 0;
485
+ const scale = this.extractVector2(node.properties.scale) || { x: 1, y: 1 };
486
+ // Build components
487
+ const components = [];
488
+ components.push(this.convertGodotNodeToComponent(node));
489
+ // Add script component if present
490
+ if (node.properties.script) {
491
+ components.push({
492
+ type: 'Script',
493
+ data: {
494
+ script: node.properties.script,
495
+ scriptType: 'gdscript',
496
+ },
497
+ });
498
+ }
499
+ return {
500
+ id: this.generateId(),
501
+ name: node.name,
502
+ type: mapping.niceType,
503
+ x: position.x,
504
+ y: position.y,
505
+ width: 1,
506
+ height: 1,
507
+ rotation,
508
+ scaleX: scale.x,
509
+ scaleY: scale.y,
510
+ visible: node.properties.visible !== false,
511
+ components,
512
+ children: children.map((c) => this.convertNodeToEntity(c)),
513
+ properties: {
514
+ godotType: node.type,
515
+ category: mapping.category,
516
+ groups: node.groups,
517
+ ...node.properties,
518
+ },
519
+ };
520
+ }
521
+ convertGodotNodeToComponent(node) {
522
+ var _a, _b, _c, _d, _e, _f, _g;
523
+ const type = node.type || 'Node';
524
+ switch (type) {
525
+ case 'Sprite2D':
526
+ return {
527
+ type: 'Sprite',
528
+ data: {
529
+ texture: node.properties.texture,
530
+ centered: node.properties.centered !== false,
531
+ offset: this.extractVector2(node.properties.offset),
532
+ flipH: node.properties.flip_h || false,
533
+ flipV: node.properties.flip_v || false,
534
+ hframes: node.properties.hframes || 1,
535
+ vframes: node.properties.vframes || 1,
536
+ frame: node.properties.frame || 0,
537
+ modulate: node.properties.modulate,
538
+ },
539
+ };
540
+ case 'AnimatedSprite2D':
541
+ return {
542
+ type: 'AnimatedSprite',
543
+ data: {
544
+ spriteFrames: node.properties.sprite_frames,
545
+ animation: node.properties.animation,
546
+ frame: node.properties.frame || 0,
547
+ playing: node.properties.playing || false,
548
+ speedScale: node.properties.speed_scale || 1.0,
549
+ centered: node.properties.centered !== false,
550
+ offset: this.extractVector2(node.properties.offset),
551
+ flipH: node.properties.flip_h || false,
552
+ flipV: node.properties.flip_v || false,
553
+ },
554
+ };
555
+ case 'CharacterBody2D':
556
+ return {
557
+ type: 'CharacterController2D',
558
+ data: {
559
+ motionMode: node.properties.motion_mode || 0,
560
+ upDirection: this.extractVector2(node.properties.up_direction) || { x: 0, y: -1 },
561
+ floorStopOnSlope: node.properties.floor_stop_on_slope || true,
562
+ floorMaxAngle: node.properties.floor_max_angle || 0.785398,
563
+ platformOnLeave: node.properties.platform_on_leave || 0,
564
+ safeMargin: node.properties.safe_margin || 0.08,
565
+ },
566
+ };
567
+ case 'RigidBody2D':
568
+ return {
569
+ type: 'Rigidbody2D',
570
+ data: {
571
+ mass: node.properties.mass || 1.0,
572
+ physicsMaterialOverride: node.properties.physics_material_override,
573
+ gravityScale: (_a = node.properties.gravity_scale) !== null && _a !== void 0 ? _a : 1.0,
574
+ freezeMode: node.properties.freeze_mode || 0,
575
+ freeze: node.properties.freeze || false,
576
+ customIntegrator: node.properties.custom_integrator || false,
577
+ continuousCd: node.properties.continuous_cd || 0,
578
+ linearVelocity: this.extractVector2(node.properties.linear_velocity),
579
+ angularVelocity: node.properties.angular_velocity || 0,
580
+ linearDamp: node.properties.linear_damp || 0,
581
+ angularDamp: node.properties.angular_damp || 0,
582
+ },
583
+ };
584
+ case 'CollisionShape2D':
585
+ return {
586
+ type: 'Collider2D',
587
+ data: {
588
+ shape: node.properties.shape,
589
+ disabled: node.properties.disabled || false,
590
+ oneWayCollision: node.properties.one_way_collision || false,
591
+ oneWayCollisionMargin: node.properties.one_way_collision_margin || 1.0,
592
+ },
593
+ };
594
+ case 'Area2D':
595
+ return {
596
+ type: 'Trigger2D',
597
+ data: {
598
+ monitorable: (_b = node.properties.monitorable) !== null && _b !== void 0 ? _b : true,
599
+ monitoring: (_c = node.properties.monitoring) !== null && _c !== void 0 ? _c : true,
600
+ priority: node.properties.priority || 0,
601
+ collisionLayer: node.properties.collision_layer,
602
+ collisionMask: node.properties.collision_mask,
603
+ gravitySpaceOverride: node.properties.gravity_space_override,
604
+ gravityPointCenter: this.extractVector2(node.properties.gravity_point_center),
605
+ gravity: node.properties.gravity,
606
+ },
607
+ };
608
+ case 'Camera2D':
609
+ return {
610
+ type: 'Camera2D',
611
+ data: {
612
+ enabled: (_d = node.properties.enabled) !== null && _d !== void 0 ? _d : true,
613
+ zoom: this.extractVector2(node.properties.zoom) || { x: 1, y: 1 },
614
+ offset: this.extractVector2(node.properties.offset),
615
+ anchorMode: node.properties.anchor_mode || 1,
616
+ rotationSmoothingEnabled: node.properties.rotation_smoothing_enabled || false,
617
+ positionSmoothingEnabled: node.properties.position_smoothing_enabled || false,
618
+ positionSmoothingSpeed: node.properties.position_smoothing_speed || 5,
619
+ limitLeft: node.properties.limit_left,
620
+ limitTop: node.properties.limit_top,
621
+ limitRight: node.properties.limit_right,
622
+ limitBottom: node.properties.limit_bottom,
623
+ limitSmoothed: node.properties.limit_smoothed || false,
624
+ },
625
+ };
626
+ case 'TileMap':
627
+ case 'TileMapLayer':
628
+ return {
629
+ type: 'Tilemap',
630
+ data: {
631
+ tileSet: node.properties.tile_set,
632
+ cellSize: this.extractVector2(node.properties.cell_size) || { x: 16, y: 16 },
633
+ quadrantSize: node.properties.quadrant_size || 16,
634
+ format: node.properties.format,
635
+ tileData: node.properties.tile_data || node.properties.layer_0 || node.properties.layer0,
636
+ },
637
+ };
638
+ case 'AudioStreamPlayer':
639
+ case 'AudioStreamPlayer2D':
640
+ case 'AudioStreamPlayer3D':
641
+ return {
642
+ type: 'AudioSource',
643
+ data: {
644
+ stream: node.properties.stream,
645
+ volumeDb: node.properties.volume_db || 0,
646
+ pitchScale: node.properties.pitch_scale || 1.0,
647
+ playing: node.properties.playing || false,
648
+ autoplay: node.properties.autoplay || false,
649
+ bus: node.properties.bus || 'Master',
650
+ maxDistance: node.properties.max_distance,
651
+ attenuation: node.properties.attenuation,
652
+ },
653
+ };
654
+ case 'AnimationPlayer':
655
+ return {
656
+ type: 'Animator',
657
+ data: {
658
+ rootNode: node.properties.root_node,
659
+ autoplay: node.properties.autoplay,
660
+ currentAnimation: node.properties.current_animation,
661
+ playbackSpeed: node.properties.playback_speed || 1.0,
662
+ libraries: node.properties.libraries,
663
+ },
664
+ };
665
+ case 'GPUParticles2D':
666
+ case 'CPUParticles2D':
667
+ return {
668
+ type: 'ParticleSystem2D',
669
+ data: {
670
+ emitting: (_e = node.properties.emitting) !== null && _e !== void 0 ? _e : true,
671
+ amount: node.properties.amount || 8,
672
+ lifetime: node.properties.lifetime || 1.0,
673
+ oneShot: node.properties.one_shot || false,
674
+ preprocess: node.properties.preprocess || 0,
675
+ speedScale: node.properties.speed_scale || 1.0,
676
+ explosiveness: node.properties.explosiveness || 0,
677
+ randomness: node.properties.randomness || 0,
678
+ texture: node.properties.texture,
679
+ processMaterial: node.properties.process_material,
680
+ },
681
+ };
682
+ case 'Light2D':
683
+ case 'PointLight2D':
684
+ return {
685
+ type: 'Light2D',
686
+ data: {
687
+ enabled: (_f = node.properties.enabled) !== null && _f !== void 0 ? _f : true,
688
+ color: node.properties.color,
689
+ energy: (_g = node.properties.energy) !== null && _g !== void 0 ? _g : 1.0,
690
+ texture: node.properties.texture,
691
+ textureScale: node.properties.texture_scale || 1.0,
692
+ blendMode: node.properties.blend_mode || 0,
693
+ shadowEnabled: node.properties.shadow_enabled || false,
694
+ shadowColor: node.properties.shadow_color,
695
+ },
696
+ };
697
+ case 'Label':
698
+ return {
699
+ type: 'Text',
700
+ data: {
701
+ text: node.properties.text || '',
702
+ horizontalAlignment: node.properties.horizontal_alignment || 0,
703
+ verticalAlignment: node.properties.vertical_alignment || 0,
704
+ autowrapMode: node.properties.autowrap_mode || 0,
705
+ clipText: node.properties.clip_text || false,
706
+ textOverrunBehavior: node.properties.text_overrun_behavior || 0,
707
+ theme: node.properties.theme,
708
+ themeOverride: node.properties.theme_override_colors || node.properties.theme_override_fonts,
709
+ },
710
+ };
711
+ case 'Button':
712
+ return {
713
+ type: 'Button',
714
+ data: {
715
+ text: node.properties.text || '',
716
+ disabled: node.properties.disabled || false,
717
+ flat: node.properties.flat || false,
718
+ icon: node.properties.icon,
719
+ toggleMode: node.properties.toggle_mode || false,
720
+ buttonPressed: node.properties.button_pressed || false,
721
+ },
722
+ };
723
+ default:
724
+ return {
725
+ type: type,
726
+ data: { ...node.properties },
727
+ };
728
+ }
729
+ }
730
+ extractVector2(value) {
731
+ if (!value)
732
+ return undefined;
733
+ if (typeof value === 'object' && value !== null) {
734
+ if ('_type' in value && value._type === 'Vector2') {
735
+ return { x: value.x, y: value.y };
736
+ }
737
+ if ('x' in value && 'y' in value) {
738
+ return {
739
+ x: Number(value.x),
740
+ y: Number(value.y),
741
+ };
742
+ }
743
+ }
744
+ return undefined;
745
+ }
746
+ extractAssets() {
747
+ var _a;
748
+ const assets = [];
749
+ for (const [id, extRes] of this.extResources) {
750
+ let assetType = 'data';
751
+ // Determine asset type from Godot resource type
752
+ switch (extRes.type) {
753
+ case 'Texture2D':
754
+ case 'CompressedTexture2D':
755
+ case 'AtlasTexture':
756
+ case 'ImageTexture':
757
+ assetType = 'texture';
758
+ break;
759
+ case 'AudioStream':
760
+ case 'AudioStreamMP3':
761
+ case 'AudioStreamOGGVorbis':
762
+ case 'AudioStreamWAV':
763
+ assetType = 'audio';
764
+ break;
765
+ case 'SpriteFrames':
766
+ case 'Animation':
767
+ case 'AnimationLibrary':
768
+ assetType = 'animation';
769
+ break;
770
+ case 'TileSet':
771
+ assetType = 'tileset';
772
+ break;
773
+ case 'Script':
774
+ case 'GDScript':
775
+ case 'CSharpScript':
776
+ assetType = 'script';
777
+ break;
778
+ case 'Shader':
779
+ case 'VisualShader':
780
+ assetType = 'shader';
781
+ break;
782
+ case 'Font':
783
+ case 'FontFile':
784
+ case 'SystemFont':
785
+ assetType = 'font';
786
+ break;
787
+ }
788
+ assets.push({
789
+ id: this.generateId(),
790
+ name: ((_a = extRes.path
791
+ .split('/')
792
+ .pop()) === null || _a === void 0 ? void 0 : _a.replace(/\.\w+$/, '')) || `resource_${id}`,
793
+ type: assetType,
794
+ path: extRes.path,
795
+ data: {
796
+ godotType: extRes.type,
797
+ extResourceId: id,
798
+ uid: extRes.uid,
799
+ },
800
+ });
801
+ }
802
+ return assets;
803
+ }
804
+ // ----------------------------------------
805
+ // Helper Methods
806
+ // ----------------------------------------
807
+ async readFile(path) {
808
+ var _a;
809
+ if (typeof globalThis.process !== 'undefined' && ((_a = globalThis.process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
810
+ const fs = await import('fs');
811
+ return fs.readFileSync(path, 'utf-8');
812
+ }
813
+ else if (typeof fetch !== 'undefined') {
814
+ const response = await fetch(path);
815
+ return response.text();
816
+ }
817
+ throw new Error('Unable to read file in current environment');
818
+ }
819
+ }
820
+
821
+ export { GodotSceneImporter };
822
+ //# sourceMappingURL=GodotSceneImporter.js.map