editor_export_godot3.cpp 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765
  1. /*************************************************************************/
  2. /* editor_export_godot3.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_export_godot3.h"
  31. #include "drivers/nrex/regex.h"
  32. #include "editor_node.h"
  33. #include "io/resource_format_binary.h"
  34. #include "io/resource_format_xml.h"
  35. #include "scene/resources/scene_format_text.h"
  36. static const char *globals_renames[][2] = {
  37. /* [application] */
  38. { "application/name", "application/config/name" },
  39. { "application/auto_accept_quit", "application/config/auto_accept_quit" },
  40. { "application/boot_splash", "application/boot_splash/image" },
  41. { "application/boot_splash_fullsize", "application/boot_splash/fullsize" },
  42. { "application/icon", "application/config/icon" },
  43. { "application/main_scene", "application/run/main_scene" },
  44. { "application/main_loop_type", "application/run/main_loop_type" },
  45. { "application/disable_stdout", "application/run/disable_stdout" },
  46. { "application/disable_stderr", "application/run/disable_stderr" },
  47. { "application/frame_delay_msec", "application/run/frame_delay_msec" },
  48. /* [debug] */
  49. { "debug/profiler_max_functions", "debug/settings/profiler/max_functions" },
  50. { "debug/max_remote_stdout_chars_per_second", "network/limits/debugger_stdout/max_chars_per_second" },
  51. { "debug/force_fps", "debug/settings/fps/force_fps" },
  52. { "debug/verbose_stdout", "debug/settings/stdout/verbose_stdout" },
  53. //{ "debug/max_texture_size", "debug/" },
  54. //{ "debug/max_texture_size_alert", "debug/" },
  55. //{ "debug/image_load_times", "debug/" },
  56. { "debug/script_max_call_stack", "debug/settings/gdscript/max_call_stack" },
  57. { "debug/collision_shape_color", "debug/shapes/collision/shape_color" },
  58. { "debug/collision_contact_color", "debug/shapes/collision/contact_color" },
  59. { "debug/navigation_geometry_color", "debug/shapes/navigation/geometry_color" },
  60. { "debug/navigation_disabled_geometry_color", "debug/shapes/navigation/disabled_geometry_color" },
  61. { "debug/collision_max_contacts_displayed", "debug/shapes/collision/max_contacts_displayed" },
  62. //{ "debug/indicators_enabled", "debug/" },
  63. { "debug/print_fps", "debug/settings/stdout/print_fps" },
  64. //{ "debug/print_metrics", "debug/" },
  65. /* [display] */
  66. { "display/driver", "display/driver/name" },
  67. { "display/width", "display/window/size/width" },
  68. { "display/height", "display/window/size/height" },
  69. { "display/allow_hidpi", "display/window/dpi/allow_hidpi" },
  70. { "display/fullscreen", "display/window/size/fullscreen" },
  71. { "display/resizable", "display/window/size/resizable" },
  72. { "display/borderless_window", "display/window/size/borderless" },
  73. { "display/use_vsync", "display/window/vsync/use_vsync" },
  74. { "display/test_width", "display/window/size/test_width" },
  75. { "display/test_height", "display/window/size/test_height" },
  76. { "display/use_2d_pixel_snap", "rendering/quality/2d/use_pixel_snap" },
  77. { "display/keep_screen_on", "display/window/energy_saving/keep_screen_on" },
  78. { "display/orientation", "display/window/handheld/orientation" },
  79. { "display/emulate_touchscreen", "display/window/handheld/emulate_touchscreen" },
  80. { "display/use_hidpi_theme", "gui/theme/use_hidpi" },
  81. { "display/custom_theme", "gui/theme/custom" },
  82. { "display/custom_theme_font", "gui/theme/custom_font" },
  83. { "display/swap_ok_cancel", "gui/common/swap_ok_cancel" },
  84. { "display/tooltip_delay", "gui/timers/tooltip_delay_sec" },
  85. { "display/text_edit_idle_detect_sec", "gui/timers/text_edit_idle_detect_sec" },
  86. { "display/stretch_mode", "display/window/stretch/mode" },
  87. { "display/stretch_aspect", "display/window/stretch/aspect" },
  88. /* [render] */
  89. { "render/thread_model", "rendering/threads/thread_model" },
  90. //{ "render/mipmap_policy", "" },
  91. //{ "render/thread_textures_prealloc", "" },
  92. //{ "render/shadows_enabled", "" },
  93. //{ "render/aabb_random_points", "" },
  94. { "render/default_clear_color", "rendering/environment/default_clear_color" },
  95. //{ "render/room_cull_enabled", "" },
  96. //{ "render/light_discard_enabled", "" },
  97. /* [audio] */
  98. // partly unchanged
  99. //{ "audio/mixer_interp", "" },
  100. //{ "audio/use_chorus_reverb", "" },
  101. //{ "audio/stream_volume_scale", "" },
  102. //{ "audio/fx_volume_scale", "" },
  103. //{ "audio/event_voice_volume_scale", "" },
  104. //{ "audio/stream_buffering_ms", "" },
  105. //{ "audio/video_delay_compensation_ms", "" },
  106. //{ "audio/mixer_latency", "" },
  107. /* [physics] */
  108. { "physics/fixed_fps", "physics/common/physics_fps" },
  109. { "physics/remove_collision_helpers_at_runtime", "physics/" },
  110. { "physics/sleep_threshold_linear", "physics/3d/sleep_threshold_linear" },
  111. { "physics/sleep_threshold_angular", "physics/3d/sleep_threshold_angular" },
  112. { "physics/time_before_sleep", "physics/3d/time_before_sleep" },
  113. { "physics/default_gravity", "physics/3d/default_gravity" },
  114. { "physics/default_gravity_vector", "physics/3d/default_gravity_vector" },
  115. { "physics/default_linear_damp", "physics/3d/default_linear_damp" },
  116. { "physics/default_angular_damp", "physics/3d/default_angular_damp" },
  117. { "physics/enable_object_picking", "physics/common/enable_object_picking" },
  118. /* [core] */
  119. //{ "core/message_queue_size_kb", "" },
  120. //{ "core/rid_pool_prealloc", "" },
  121. //{ "core/thread_rid_pool_prealloc", "" },
  122. { "core/packet_stream_peer_max_buffer_po2", "network/limits/packet_peer_stream/max_buffer_po2" },
  123. /* [rasterizer.Android] */
  124. //{ "rasterizer.Android/use_fragment_lighting", "" },
  125. //{ "rasterizer.Android/fp16_framebuffer", "" },
  126. /* [display.Android] */
  127. //{ "display.Android/driver", "" },
  128. /* [rasterizer.iOS] */
  129. //{ "rasterizer.iOS/use_fragment_lighting", "" },
  130. //{ "rasterizer.iOS/fp16_framebuffer", "" },
  131. /* [display.iOS] */
  132. //{ "display.iOS/driver", "" },
  133. //{ "display.iOS/use_cadisplaylink", "" },
  134. /* [rasterizer] */
  135. // most don't have an equivalent or are not meaningful to port
  136. { "rasterizer/anisotropic_filter_level", "rendering/quality/filter/anisotropic_filter_level" },
  137. /* [physics_2d] */
  138. { "physics_2d/thread_model", "physics/2d/thread_model" },
  139. //{ "physics_2d/motion_fix_enabled", "" },
  140. { "physics_2d/sleep_threashold_linear", "physics/2d/sleep_threshold_linear" },
  141. { "physics_2d/sleep_threshold_angular", "physics/2d/sleep_threshold_angular" },
  142. { "physics_2d/time_before_sleep", "physics/2d/time_before_sleep" },
  143. { "physics_2d/bp_hash_table_size", "physics/2d/bp_hash_table_size" },
  144. { "physics_2d/cell_size", "physics/2d/cell_size" },
  145. { "physics_2d/large_object_surface_treshold_in_cells", "physics/2d/large_object_surface_threshold_in_cells" },
  146. { "physics_2d/default_gravity", "physics/2d/default_gravity" },
  147. { "physics_2d/default_gravity_vector", "physics/2d/default_gravity_vector" },
  148. { "physics_2d/default_linear_damp", "physics/2d/default_linear_damp" },
  149. { "physics_2d/default_angular_damp", "physics/2d/default_angular_damp" },
  150. /* [image_loader] */
  151. //{ "image_loader/filter", "" },
  152. //{ "image_loader/gen_mipmaps", "" },
  153. //{ "image_loader/repeat", "" },
  154. /* [ssl] */
  155. { "ssl/certificates", "network/ssl/certificates" },
  156. { "ssl/config", "network/ssl/config" },
  157. /* [locale] */
  158. // no change
  159. /* [global] */
  160. { "editor_active", "editor/active" },
  161. /* [editor] */
  162. { "editor/main_run_args", "editor/main_run_args" },
  163. //{ "editor/import_shared_textures", "" },
  164. /* [gui] */
  165. { "gui/incr_search_max_interval_msec", "gui/timers/incremental_search_max_interval_msec" },
  166. { NULL, NULL }
  167. };
  168. static const char *prop_renames[][2] = {
  169. { "anchor/bottom", "anchor_bottom" }, // Control
  170. { "anchor/left", "anchor_left" }, // Control
  171. { "anchor/right", "anchor_right" }, // Control
  172. { "anchor/top", "anchor_top" }, // Control
  173. { "bbcode/bbcode", "bbcode_text" }, // RichTextLabel
  174. { "bbcode/enabled", "bbcode_enabled" }, // RichTextLabel
  175. { "bias/bias", "bias" }, // Joints2D
  176. { "caret/block_caret", "caret_block_mode" }, // TextEdit
  177. { "caret/caret_blink", "caret_blink" }, // LineEdit, TextEdit
  178. { "caret/caret_blink_speed", "caret_blink_speed" }, // LineEdit, TextEdit
  179. { "cell/center_x", "cell_center_x" }, // GridMap
  180. { "cell/center_y", "cell_center_y" }, // GridMap
  181. { "cell/center_z", "cell_center_z" }, // GridMap
  182. { "cell/custom_transform", "cell_custom_transform" }, // TileMap
  183. { "cell/half_offset", "cell_half_offset" }, // TileMap
  184. { "cell/octant_size", "cell_octant_size" }, // GridMap
  185. { "cell/quadrant_size", "cell_quadrant_size" }, // TileMap
  186. { "cell/scale", "cell_scale" }, // GridMap
  187. { "cell/size", "cell_size" }, // GridMap, TileMap
  188. { "cell/tile_origin", "cell_tile_origin" }, // TileMap
  189. { "cell/y_sort", "cell_y_sort" }, // TileMap
  190. { "collision/bounce", "collision_bounce" }, // TileMap
  191. //{ "collision/exclude_nodes", "disable_collision" }, // Joint, Joint2D // Joint2D can be converted, not Joint, handle manually
  192. { "collision/friction", "collision_friction" }, // TileMap
  193. { "collision/layers", "collision_layer" }, // Area, Area2D, PhysicsBody, PhysicsBody2D, TileMap
  194. { "collision/margin", "collision/safe_margin" }, // PhysicsBody, PhysicsBody2D
  195. { "collision/mask", "collision_mask" }, // Area, Area2D, PhysicsBody, PhysicsBody2D, TileMap
  196. { "collision/use_kinematic", "collision_use_kinematic" }, // TileMap
  197. { "config/amount", "amount" }, // Particles2D
  198. { "config/emitting", "emitting" }, // Particles2D
  199. { "config/explosiveness", "explosiveness" }, // Particles2D
  200. { "config/h_frames", "h_frames" }, // Particles2D
  201. { "config/lifetime", "lifetime" }, // Particles2D
  202. { "config/local_space", "local_coords" }, // Particles2D
  203. { "config/preprocess", "preprocess" }, // Particles2D
  204. { "config/texture", "texture" }, // Particles2D
  205. { "config/time_scale", "speed_scale" }, // Particles2D
  206. { "config/v_frames", "v_frames" }, // Particles2D
  207. { "content_margin/bottom", "content_margin_bottom" }, // StyleBox
  208. { "content_margin/left", "content_margin_left" }, // StyleBox
  209. { "content_margin/right", "content_margin_right" }, // StyleBox
  210. { "content_margin/top", "content_margin_top" }, // StyleBox
  211. { "damping/compression", "damping_compression" }, // VehicleWheel
  212. { "damping/relaxation", "damping_relaxation" }, // VehicleWheel
  213. { "damp_override/angular", "angular_damp" }, // PhysicsBody, PhysicsBody2D
  214. { "damp_override/linear", "linear_damp" }, // PhysicsBody, PhysicsBody2D
  215. { "dialog/hide_on_ok", "dialog_hide_on_ok" }, // AcceptDialog
  216. { "dialog/text", "dialog_text" }, // AcceptDialog
  217. { "drag_margin/bottom", "drag_margin_bottom" }, // Camera2D
  218. { "drag_margin/h_enabled", "drag_margin_h_enabled" }, // Camera2D
  219. { "drag_margin/left", "drag_margin_left" }, // Camera2D
  220. { "drag_margin/right", "drag_margin_right" }, // Camera2D
  221. { "drag_margin/top", "drag_margin_top" }, // Camera2D
  222. { "drag_margin/v_enabled", "drag_margin_v_enabled" }, // Camera2D
  223. { "enabler/fixed_process_parent", "physics_process_parent" }, // VisibilityEnabler2D
  224. { "enabler/freeze_bodies", "freeze_bodies" }, // VisibilityEnabler, VisibilityEnabler2D
  225. { "enabler/pause_animated_sprites", "pause_animated_sprites" }, // VisibilityEnabler2D
  226. { "enabler/pause_animations", "pause_animations" }, // VisibilityEnabler, VisibilityEnabler2D
  227. { "enabler/pause_particles", "pause_particles" }, // VisibilityEnabler2D
  228. { "enabler/process_parent", "process_parent" }, // VisibilityEnabler2D
  229. { "expand_margin/bottom", "expand_margin_bottom" }, // StyleBox
  230. { "expand_margin/left", "expand_margin_left" }, // StyleBox
  231. { "expand_margin/right", "expand_margin_right" }, // StyleBox
  232. { "expand_margin/top", "expand_margin_top" }, // StyleBox
  233. { "extra_spacing/bottom", "extra_spacing_bottom" }, // DynamicFont
  234. { "extra_spacing/char", "extra_spacing_char" }, // DynamicFont
  235. { "extra_spacing/space", "extra_spacing_space" }, // DynamicFont
  236. { "extra_spacing/top", "extra_spacing_top" }, // DynamicFont
  237. { "flags/alpha_cut", "alpha_cut" }, // Sprite3D
  238. { "flags/double_sided", "double_sided" }, // Sprite3D
  239. { "flags/shaded", "shaded" }, // Sprite3D
  240. { "flags/transparent", "transparent" }, // Sprite3D
  241. { "focus_neighbour/bottom", "focus_neighbour_bottom" }, // Control
  242. { "focus_neighbour/left", "focus_neighbour_left" }, // Control
  243. { "focus_neighbour/right", "focus_neighbour_right" }, // Control
  244. { "focus_neighbour/top", "focus_neighbour_top" }, // Control
  245. { "font/font", "font_data" }, // DynamicFont
  246. { "font/size", "size" }, // DynamicFont
  247. { "font/use_filter", "use_filter" }, // DynamicFont
  248. { "font/use_mipmaps", "use_mipmaps" }, // DynamicFont
  249. { "geometry/cast_shadow", "cast_shadow" }, // GeometryInstance
  250. { "geometry/extra_cull_margin", "extra_cull_margin" }, // GeometryInstance
  251. { "geometry/material_override", "material_override" }, // GeometryInstance
  252. { "geometry/use_baked_light", "use_in_baked_light" }, // GeometryInstance
  253. { "hint/tooltip", "hint_tooltip" }, // Control
  254. { "input/capture_on_drag", "input_capture_on_drag" }, // CollisionObject
  255. { "input/pickable", "input_pickable" }, // CollisionObject2D
  256. { "input/ray_pickable", "input_ray_pickable" }, // CollisionObject
  257. { "invert/border", "invert_border" }, // Polygon2D
  258. { "invert/enable", "invert_enable" }, // Polygon2D
  259. { "is_pressed", "pressed" }, // BaseButton
  260. { "limit/bottom", "limit_bottom" }, // Camera2D
  261. { "limit/left", "limit_left" }, // Camera2D
  262. { "limit/right", "limit_right" }, // Camera2D
  263. { "limit/top", "limit_top" }, // Camera2D
  264. { "margin/bottom", "margin_bottom" }, // Control, StyleBox
  265. { "margin/left", "margin_left" }, // Control, StyleBox
  266. { "margin/right", "margin_right" }, // Control, StyleBox
  267. { "margin/top", "margin_top" }, // Control, StyleBox
  268. { "material/material", "material" }, // CanvasItem
  269. { "material/use_parent", "use_parent_material" }, // CanvasItem
  270. { "mesh/mesh", "mesh" }, // MeshInstance
  271. { "mesh/skeleton", "skeleton" }, // MeshInstance
  272. //{ "mode", "fill_mode" }, // TextureProgress & others // Would break TileMap and others, handle manually
  273. { "motion/brake", "brake" }, // VehicleBody
  274. { "motion/engine_force", "engine_force" }, // VehicleBody
  275. { "motion/mirroring", "motion_mirroring" }, // ParallaxLayer
  276. { "motion/offset", "motion_offset" }, // ParallaxLayer
  277. { "motion/scale", "motion_scale" }, // ParallaxLayer
  278. { "motion/steering", "steering" }, // VehicleBody
  279. { "occluder/light_mask", "occluder_light_mask" }, // TileMap
  280. { "params/attenuation/distance_exp", "attenuation_distance_exp" },
  281. { "params/attenuation/max_distance", "attenuation_max_distance" },
  282. { "params/attenuation/min_distance", "attenuation_min_distance" },
  283. { "params/emission_cone/attenuation_db", "emission_cone_attenuation_db" },
  284. { "params/emission_cone/degrees", "emission_cone_degrees" },
  285. { "params/modulate", "self_modulate" },
  286. { "params/pitch_scale", "pitch_scale" },
  287. { "params/scale", "texture_scale" },
  288. { "params/volume_db", "volume_db" },
  289. { "patch_margin/bottom", "patch_margin_bottom" }, // Patch9Frame
  290. { "patch_margin/left", "patch_margin_left" }, // Patch9Frame
  291. { "patch_margin/right", "patch_margin_right" }, // Patch9Frame
  292. { "patch_margin/top", "patch_margin_top" }, // Patch9Frame
  293. { "percent/visible", "percent_visible" }, // ProgressBar
  294. { "placeholder/alpha", "placeholder_alpha" }, // LineEdit
  295. { "placeholder/text", "placeholder_text" }, // LineEdit
  296. //{ "playback/active", "playback_active" }, // AnimationPlayer, AnimationTreePlayer // properly renamed for AnimationPlayer, but not AnimationTreePlayer, handle manually
  297. { "playback/default_blend_time", "playback_default_blend_time" }, // AnimationPlayer
  298. { "playback/process_mode", "playback_process_mode" }, // AnimationPlayer, AnimationTreePlayer, Tween
  299. { "playback/speed", "playback_speed" }, // AnimationPlayer, Tween
  300. { "playback/repeat", "playback_speed" }, // AnimationPlayer
  301. { "popup/exclusive", "popup_exclusive" }, // Popup
  302. { "process/pause_mode", "pause_mode" }, // Node
  303. { "radial_fill/center_offset", "radial_center_offset" }, // TextureProgress
  304. { "radial_fill/fill_degrees", "radial_fill_degrees" }, // TextureProgress
  305. { "radial_fill/initial_angle", "radial_initial_angle" }, // TextureProgress
  306. { "range/exp_edit", "exp_edit" }, // Range
  307. { "range/height", "range_height" }, // Light2D
  308. { "range/item_mask", "range_item_cull_mask" }, // Light2D
  309. { "range/layer_max", "range_layer_max" }, // Light2D
  310. { "range/layer_min", "range_layer_min" }, // Light2D
  311. { "range/max", "max_value" }, // Range
  312. { "range/min", "min_value" }, // Range
  313. { "range/page", "page" }, // Range
  314. { "range/rounded", "rounded" }, // Range
  315. { "range/step", "step" }, // Range
  316. { "range/value", "value" }, // Range
  317. { "range/z_max", "range_z_max" }, // Light2D
  318. { "range/z_min", "range_z_min" }, // Light2D
  319. { "rect/min_size", "rect_min_size" }, // Control
  320. { "rect/pos", "rect_position" }, // Control
  321. { "rect/rotation", "rect_rotation" }, // Control
  322. { "rect/scale", "rect_scale" }, // Control
  323. { "rect/size", "rect_size" }, // Control
  324. //{ "region", "region_enabled" }, // Sprite, Sprite3D // Not renamed for Texture, handle manually
  325. { "resource/name", "resource_name" }, // Resource
  326. { "resource/path", "resource_path" }, // Resource
  327. { "root/root", "root_node" }, // AnimationPlayer
  328. { "script/script", "script" }, // Object
  329. { "scroll/base_offset", "scroll_base_offset" }, // ParallaxBackground
  330. { "scroll/base_scale", "scroll_base_scale" }, // ParallaxBackground
  331. { "scroll/horizontal", "scroll_horizontal_enabled" }, // ScrollContainer
  332. { "scroll/ignore_camera_zoom", "scroll_ignore_camera_zoom" }, // ParallaxBackground
  333. { "scroll/limit_begin", "scroll_limit_begin" }, // ParallaxBackground
  334. { "scroll/limit_end", "scroll_limit_end" }, // ParallaxBackground
  335. { "scroll/offset", "scroll_offset" }, // ParallaxBackground
  336. { "scroll/vertical", "scroll_vertical_enabled" }, // ScrollContainer
  337. { "shadow/buffer_size", "shadow_buffer_size" }, // Light2D
  338. { "shadow/color", "shadow_color" }, // Light2D
  339. { "shadow/enabled", "shadow_enabled" }, // Light2D
  340. { "shadow/item_mask", "shadow_item_cull_mask" }, // Light2D
  341. { "size_flags/horizontal", "size_flags_horizontal" }, // Control // Enum order got inverted Expand,Fill -> Fill,Expand, handle manually after rename
  342. { "size_flags/stretch_ratio", "size_flags_stretch_ratio" }, // Control
  343. { "size_flags/vertical", "size_flags_vertical" }, // Control // Enum order got inverted Expand,Fill -> Fill,Expand, handle manually after rename
  344. { "smoothing/enable", "smoothing_enabled" }, // Camera2D
  345. { "smoothing/speed", "smoothing_speed" }, // Camera2D
  346. { "sort/enabled", "sort_enabled" }, // YSort
  347. { "split/collapsed", "collapsed" }, // SplitContainer
  348. { "split/dragger_visibility", "dragger_visibility" }, // SplitContainer
  349. { "split/offset", "split_offset" }, // SplitContainer
  350. { "stream/audio_track", "audio_track" }, // VideoPlayer
  351. { "stream/autoplay", "autoplay" }, // VideoPlayer
  352. { "stream/buffering_ms", "buffering_msec" }, // VideoPlayer
  353. { "stream/loop", "loop" }, // Audio*
  354. { "stream/loop_restart_time", "loop_offset" }, // Audio*
  355. { "stream/paused", "paused" }, // VideoPlayer
  356. { "stream/pitch_scale", "pitch_scale" }, // Audio*
  357. { "stream/play", "playing" }, // Audio*
  358. { "stream/stream", "stream" }, // VideoPlayer
  359. { "stream/volume_db", "volume_db" }, // VideoPlayer
  360. { "suspension/max_force", "suspension_max_force" }, // VehicleWheel
  361. { "suspension/stiffness", "suspension_stiffness" }, // VehicleWheel
  362. { "suspension/travel", "suspension_travel" }, // VehicleWheel
  363. { "texture/offset", "texture_offset" }, // Polygon2D
  364. { "texture/over", "texture_over" }, // TextureProgress
  365. { "texture/progress", "texture_progress" }, // TextureProgress
  366. { "texture/rotation", "texture_rotation_degrees" }, // Polygon2D
  367. { "texture/scale", "texture_scale" }, // Polygon2D
  368. { "textures/click_mask", "texture_click_mask" }, // TextureButton
  369. { "textures/disabled", "texture_disabled" }, // TextureButton
  370. { "textures/focused", "texture_focused" }, // TextureButton
  371. { "textures/hover", "texture_hover" }, // TextureButton
  372. { "textures/normal", "texture_normal" }, // TextureButton
  373. { "textures/pressed", "texture_pressed" }, // TextureButton
  374. { "texture/texture", "texture" }, // Polygon2D
  375. { "texture/under", "texture_under" }, // TextureProgress
  376. { "theme/theme", "theme" }, // Control
  377. { "transform/local", "transform" }, // Spatial
  378. { "transform/pos", "position" }, // Node2D
  379. { "transform/rotation", "rotation_degrees" }, // Spatial
  380. { "transform/rotation_rad", "rotation" }, // Spatial
  381. { "transform/rot", "rotation_degrees" }, // Node2D
  382. { "transform/scale", "scale" }, // Node2D, Spatial
  383. { "transform/translation", "translation" }, // Spatial
  384. { "type/steering", "use_as_steering" }, // VehicleWheel
  385. { "type/traction", "use_as_traction" }, // VehicleWheel
  386. { "vars/lifetime", "lifetime" }, // Particles
  387. { "velocity/angular", "angular_velocity" }, // PhysicsBody, PhysicsBody2D
  388. { "velocity/linear", "linear_velocity" }, // PhysicsBody, PhysicsBody2D
  389. { "visibility", "visibility_aabb" }, // Particles
  390. { "visibility/behind_parent", "show_behind_parent" }, // CanvasItem
  391. { "visibility/light_mask", "light_mask" }, // CanvasItem
  392. { "visibility/on_top", "show_on_top" }, // CanvasItem
  393. //{ "visibility/opacity", "modulate" }, // CanvasItem // Can't be converted this way, handle manually
  394. //{ "visibility/self_opacity", "self_modulate" }, // CanvasItem // Can't be converted this way, handle manually
  395. { "visibility/visible", "visible" }, // CanvasItem, Spatial
  396. { "wheel/friction_slip", "wheel_friction_slip" }, // VehicleWheel
  397. { "wheel/radius", "wheel_radius" }, // VehicleWheel
  398. { "wheel/rest_length", "wheel_rest_length" }, // VehicleWheel
  399. { "wheel/roll_influence", "wheel_roll_influence" }, // VehicleWheel
  400. { "window/title", "window_title" }, // Dialogs
  401. { "z/relative", "z_as_relative" }, // Node2D
  402. { "z/z", "z_index" }, // Node2D
  403. { NULL, NULL }
  404. };
  405. static const char *type_renames[][2] = {
  406. { "CanvasItemMaterial", "ShaderMaterial" },
  407. { "CanvasItemShader", "Shader" },
  408. { "ColorFrame", "ColorRect" },
  409. { "ColorRamp", "Gradient" },
  410. { "FixedMaterial", "SpatialMaterial" },
  411. { "Patch9Frame", "NinePatchRect" },
  412. { "ReferenceFrame", "ReferenceRect" },
  413. { "SampleLibrary", "Resource" },
  414. { "SamplePlayer2D", "AudioStreamPlayer2D" },
  415. { "SamplePlayer", "Node" },
  416. { "SoundPlayer2D", "Node2D" },
  417. { "SpatialSamplePlayer", "AudioStreamPlayer3D" },
  418. { "SpatialStreamPlayer", "AudioStreamPlayer3D" },
  419. { "StreamPlayer", "AudioStreamPlayer" },
  420. { "TestCube", "MeshInstance" },
  421. { "TextureFrame", "TextureRect" },
  422. // Only for scripts
  423. { "Matrix32", "Transform2D" },
  424. { "Matrix3", "Basis" },
  425. { "RawArray", "PoolByteArray" },
  426. { "IntArray", "PoolIntArray" },
  427. { "RealArray", "PoolRealArray" },
  428. { "StringArray", "PoolStringArray" },
  429. { "Vector2Array", "PoolVector2Array" },
  430. { "Vector3Array", "PoolVector3Array" },
  431. { "ColorArray", "PoolColorArray" },
  432. { NULL, NULL }
  433. };
  434. static const char *signal_renames[][2] = {
  435. { "area_enter", "area_entered" }, // Area, Area2D
  436. { "area_enter_shape", "area_shape_entered" }, // Area, Area2D
  437. { "area_exit", "area_exited" }, // Area, Area2D
  438. { "area_exit_shape", "area_shape_exited" }, // Area, Area2D
  439. { "body_enter", "body_entered" }, // Area, Area2D, PhysicsBody, PhysicsBody2D
  440. { "body_enter_shape", "body_shape_entered" }, // Area, Area2D, PhysicsBody, PhysicsBody2D
  441. { "body_exit", "body_exited" }, // Area, Area2D, PhysicsBody, PhysicsBody2D
  442. { "body_exit_shape", "body_shape_exited" }, // Area, Area2D, PhysicsBody, PhysicsBody2D
  443. { "enter_camera", "camera_entered" }, // VisibilityNotifier
  444. { "enter_screen", "screen_entered" }, // VisibilityNotifier, VisibilityNotifier2D
  445. { "enter_tree", "tree_entered" }, // Node
  446. { "enter_viewport", "viewport_entered" }, // VisibilityNotifier2D
  447. { "exit_camera", "camera_exited" }, // VisibilityNotifier
  448. { "exit_screen", "screen_exited" }, // VisibilityNotifier, VisibilityNotifier2D
  449. { "exit_tree", "tree_exited" }, // Node
  450. { "exit_viewport", "viewport_exited" }, // VisibilityNotifier2D
  451. //{ "finished", "animation_finished" }, // AnimationPlayer, AnimatedSprite, but not StreamPlayer, handle manually
  452. { "fixed_frame", "physics_frame" }, // SceneTree
  453. { "focus_enter", "focus_entered" }, // Control
  454. { "focus_exit", "focus_exited" }, // Control
  455. { "input_event", "gui_input" }, // Control // FIXME: but not CollisionObject and CollisionObject2D, it should be handled manually
  456. { "item_pressed", "id_pressed" }, // PopupMenu
  457. { "modal_close", "modal_closed" }, // Control
  458. { "mouse_enter", "mouse_entered" }, // CollisionObject, CollisionObject2D, Control
  459. { "mouse_exit", "mouse_exited" }, // CollisionObject, CollisionObject2D, Control
  460. { "tween_start", "tween_started" }, // Tween
  461. { "tween_complete", "tween_completed" }, // Tween
  462. { NULL, NULL }
  463. };
  464. void EditorExportGodot3::_find_files(EditorFileSystemDirectory *p_dir, List<String> *r_files) {
  465. for (int i = 0; i < p_dir->get_subdir_count(); i++) {
  466. _find_files(p_dir->get_subdir(i), r_files);
  467. }
  468. for (int i = 0; i < p_dir->get_file_count(); i++) {
  469. r_files->push_back(p_dir->get_file_path(i));
  470. }
  471. }
  472. void EditorExportGodot3::_rename_properties(const String &p_type, List<ExportData::PropertyData> *p_props) {
  473. // We need specific hacks to fix compatibility breakage in the tracks of Animations
  474. bool fix_animation_tracks = (p_type == "Animation");
  475. String found_track_number = "";
  476. // Anchors/margins changed in 3.0 from always-positive to relative to their ratio anchor,
  477. // so we need to flip the sign of margins based on their anchor mode.
  478. int flip_margin_left = false;
  479. int flip_margin_right = false;
  480. int flip_margin_top = false;
  481. int flip_margin_bottom = false;
  482. for (List<ExportData::PropertyData>::Element *E = p_props->front(); E; E = E->next()) {
  483. /* Fixes for 2D rotations */
  484. // 2D rotations are now clockwise to match the downward Y base
  485. // Do this before the renaming, as afterwards we can't distinguish
  486. // between 2D and 3D rotations_degrees
  487. if (E->get().name == "transform/rot") {
  488. E->get().value = (real_t)E->get().value * -1.0;
  489. }
  490. // To fix 2D rotations in the properties of Animation tracks (see below),
  491. // we need to locate stuff like this:
  492. // tracks/0/path = NodePath("Sprite:transform/rot")
  493. // And then modify the 'values' key of 'tracks/0/keys'.
  494. // This is going to be hacky.
  495. // We'll assume that we get properties in the correct order, so that the path will come before the keys
  496. // Otherwise we'd have to keep a stack of the track keys we found to later compare them to track paths
  497. // that match rotation_deg...
  498. if (fix_animation_tracks) {
  499. String prop_name = E->get().name;
  500. if (prop_name.begins_with("tracks/") && prop_name.ends_with("/path")) {
  501. String path_value = E->get().value;
  502. // Check if it's a rotation and save the track number to fix its assigned values
  503. if (path_value.find("transform/rot") != -1) {
  504. // We found a track 'path' with a "transform/rot" NodePath, its 'keys' need to be fixed
  505. found_track_number = prop_name.get_slice("/", 1);
  506. print_line("Found Animation track with 2D rotations: " + prop_name + " = " + path_value);
  507. }
  508. // In animation tracks, NodePaths can refer to properties that need to be renamed
  509. int sep = path_value.find(":");
  510. if (sep != -1) {
  511. String track_nodepath = path_value.substr(0, sep);
  512. String track_prop = path_value.substr(sep + 1, path_value.length());
  513. if (prop_rename_map.has(track_prop)) {
  514. track_prop = prop_rename_map[track_prop];
  515. }
  516. // "[self_]opacity" was removed, and is replaced by the alpha component of "[self_]modulate"
  517. // "modulate" may already exist, but we posit that the "opacity" value is more important
  518. // Thankfully in NodePaths we can access the alpha property directly
  519. if (track_prop == "visibility/opacity") {
  520. track_prop = "modulate:a";
  521. } else if (track_prop == "visibility/self_opacity") {
  522. track_prop = "self_modulate:a";
  523. }
  524. E->get().value = NodePath(track_nodepath + ":" + track_prop);
  525. }
  526. } else if (found_track_number != "" && prop_name == "tracks/" + found_track_number + "/keys") {
  527. // Bingo! We found keys matching the track number we had spotted
  528. print_line("Fixing sign of 2D rotations in animation track " + found_track_number);
  529. Dictionary track_keys = E->get().value;
  530. if (track_keys.has("values")) {
  531. Array values = track_keys["values"];
  532. for (int i = 0; i < values.size(); i++) {
  533. values[i] = (real_t)values[i] * -1.0;
  534. }
  535. track_keys["values"] = values;
  536. E->get().value = track_keys;
  537. found_track_number = "";
  538. } else {
  539. print_line("Tried to change rotation in Animation tracks, but no value set found.");
  540. }
  541. }
  542. }
  543. /* Do the actual renaming */
  544. if (prop_rename_map.has(E->get().name)) {
  545. E->get().name = prop_rename_map[E->get().name];
  546. }
  547. /* Hardcoded fixups for properties that changed definition in 3.0 */
  548. // Anchors changed from Begin,End,Ratio,Center to only a ratio
  549. if (E->get().name.begins_with("anchor_")) {
  550. String side = E->get().name.substr(7, E->get().name.length() - 1);
  551. int prop_value = (int)E->get().value;
  552. switch (prop_value) {
  553. case 0: { // Begin
  554. E->get().value = 0.0;
  555. } break;
  556. case 1: { // End
  557. E->get().value = 1.0;
  558. // Flip corresponding margin's sign
  559. if (side == "left")
  560. flip_margin_left = true;
  561. else if (side == "right")
  562. flip_margin_right = true;
  563. else if (side == "top")
  564. flip_margin_top = true;
  565. else if (side == "bottom")
  566. flip_margin_bottom = true;
  567. } break;
  568. case 2: { // Ratio
  569. E->get().value = 0.0;
  570. print_line("WARNING: Property '" + E->get().name + "' with value 'Ratio' cannot be converted to the format used in Godot 3. Convert it to 'Begin' or 'End' to avoid losing the corresponding margin value.");
  571. } break;
  572. case 3: { // Center
  573. E->get().value = 0.5;
  574. // Flip corresponding margin's sign
  575. if (side == "left")
  576. flip_margin_left = true;
  577. else if (side == "right")
  578. flip_margin_right = true;
  579. else if (side == "top")
  580. flip_margin_top = true;
  581. else if (side == "bottom")
  582. flip_margin_bottom = true;
  583. } break;
  584. }
  585. }
  586. // Size flags enum changed ordering from "Expand,Fill" to "Fill,Expand,..."
  587. // So we swap 1 (Expand) and 2 (Fill), keep 0 (none) and 3 (Expand + Fill)
  588. if (E->get().name == "size_flags_horizontal" || E->get().name == "size_flags_vertical") {
  589. int prop_value = (int)E->get().value;
  590. switch (prop_value) {
  591. case 1: // Expand -> Fill
  592. E->get().value = 2;
  593. case 2: // Fill -> Expand
  594. E->get().value = 1;
  595. default: // none or both, keep
  596. break;
  597. }
  598. }
  599. // "[self_]opacity" was removed, and is replaced by the alpha component of "[self_]modulate"
  600. // "modulate" may already exist, but we posit that the "opacity" value is more important
  601. if (E->get().name == "visibility/opacity" || E->get().name == "visibility/self_opacity") {
  602. if (E->get().name == "visibility/self_opacity") {
  603. E->get().name = "self_modulate";
  604. } else {
  605. E->get().name = "modulate";
  606. }
  607. E->get().value = Color(1.0, 1.0, 1.0, (float)E->get().value);
  608. }
  609. // AnimationPlayer's "playback/active" was renamed to "playback_active", but not AnimationTreePlayer's
  610. if (p_type == "AnimationPlayer" && E->get().name == "playback/active") {
  611. E->get().name = "playback_active";
  612. }
  613. // Joint2D's "collision/exclude_nodes" was renamed to "disable_collision", but not Joint's
  614. if (p_type == "Joint2D" && E->get().name == "collision/exclude_nodes") {
  615. E->get().name = "disable_collision";
  616. }
  617. // TextureProgress' "mode" was renamed to "fill_mode", but not that of other nodes like TileMap
  618. if (p_type == "TextureProgress" && E->get().name == "mode") {
  619. E->get().name = "fill_mode";
  620. }
  621. // Sprite and Sprite3D's "region" was renamed to "region_enabled", but not Texture's
  622. if ((p_type == "Sprite" || p_type == "Sprite3D") && E->get().name == "region") {
  623. E->get().name = "region_enabled";
  624. }
  625. // "click_on_pressed" was renamed to "action_mode" and is now a enum
  626. if (E->get().name == "click_on_press") {
  627. E->get().name = "action_mode";
  628. if (E->get().value) {
  629. E->get().value = 0; // ACTION_MODE_BUTTON_PRESS
  630. } else {
  631. E->get().value = 1; // ACTION_MODE_BUTTON_RELEASE
  632. }
  633. }
  634. }
  635. // Flip margins based on the previously fixed anchor modes
  636. if (flip_margin_left || flip_margin_right || flip_margin_top || flip_margin_bottom) {
  637. // Loop again and fix the margins
  638. for (List<ExportData::PropertyData>::Element *E = p_props->front(); E; E = E->next()) {
  639. if (!E->get().name.begins_with("margin_")) {
  640. continue;
  641. }
  642. if ((flip_margin_left && E->get().name == "margin_left") ||
  643. (flip_margin_right && E->get().name == "margin_right") ||
  644. (flip_margin_top && E->get().name == "margin_top") ||
  645. (flip_margin_bottom && E->get().name == "margin_bottom")) {
  646. E->get().value = (real_t)E->get().value * -1.0;
  647. }
  648. }
  649. }
  650. }
  651. void EditorExportGodot3::_add_new_properties(const String &p_type, List<ExportData::PropertyData> *p_props) {
  652. bool add_mouse_filter = false;
  653. bool ignore_mouse = false;
  654. bool stop_mouse = false;
  655. for (List<ExportData::PropertyData>::Element *E = p_props->front(); E; E = E->next()) {
  656. String prop_name = E->get().name;
  657. if (prop_name == "focus/ignore_mouse" || prop_name == "focus/stop_mouse") {
  658. add_mouse_filter = true;
  659. if (prop_name == "focus/ignore_mouse") {
  660. ignore_mouse = E->get().value;
  661. } else if (prop_name == "focus/stop_mouse") {
  662. stop_mouse = E->get().value;
  663. }
  664. }
  665. }
  666. if (add_mouse_filter) {
  667. ExportData::PropertyData pdata;
  668. pdata.name = "mouse_filter";
  669. if (ignore_mouse && stop_mouse) {
  670. pdata.value = 1; // MOUSE_FILTER_PASS
  671. } else if (ignore_mouse && !stop_mouse) {
  672. pdata.value = 2; // MOUSE_FILTER_IGNORE
  673. } else {
  674. pdata.value = 0; // MOUSE_FILTER_STOP
  675. }
  676. p_props->push_back(pdata);
  677. }
  678. }
  679. void EditorExportGodot3::_convert_resources(ExportData &resource) {
  680. for (int i = 0; i < resource.resources.size(); i++) {
  681. _add_new_properties(resource.resources[i].type, &resource.resources[i].properties);
  682. _rename_properties(resource.resources[i].type, &resource.resources[i].properties);
  683. if (type_rename_map.has(resource.resources[i].type)) {
  684. resource.resources[i].type = type_rename_map[resource.resources[i].type];
  685. }
  686. }
  687. for (int i = 0; i < resource.nodes.size(); i++) {
  688. _add_new_properties(resource.nodes[i].type, &resource.nodes[i].properties);
  689. _rename_properties(resource.nodes[i].type, &resource.nodes[i].properties);
  690. if (type_rename_map.has(resource.nodes[i].type)) {
  691. resource.nodes[i].type = type_rename_map[resource.nodes[i].type];
  692. }
  693. }
  694. for (int i = 0; i < resource.connections.size(); i++) {
  695. if (signal_rename_map.has(resource.connections[i].signal)) {
  696. resource.connections[i].signal = signal_rename_map[resource.connections[i].signal];
  697. }
  698. /* Manual handling for signals which need to be conditionally renamed based on their Node's type */
  699. // AnimationPlayer and AnimatedSprite's "finished" signal was renamed to "animation_finished",
  700. // but not that of StreamPlayer. Since node information is missing from the connection data
  701. // (we only have the NodePath), we'll have to compare against the nodes array to find out.
  702. if (resource.connections[i].signal == "finished") {
  703. String from = resource.connections[i].from;
  704. // NodePath "from" is relative to root node, can be direct child (no '/') or further down
  705. int slice_count = from.get_slice_count("/");
  706. String parent = ".";
  707. String nodename = from;
  708. if (slice_count > 1) {
  709. parent = from.get_slice("/", slice_count - 2);
  710. nodename = from.get_slice("/", slice_count - 1);
  711. }
  712. for (int j = 0; j < resource.nodes.size(); j++) {
  713. if (resource.nodes[j].name == nodename && resource.nodes[j].parent == parent) {
  714. if (resource.nodes[j].type == "AnimationPlayer" || resource.nodes[j].type == "AnimatedSprite") {
  715. resource.connections[i].signal = "animation_finished";
  716. break;
  717. }
  718. }
  719. }
  720. }
  721. }
  722. }
  723. void EditorExportGodot3::_unpack_packed_scene(ExportData &resource) {
  724. Dictionary d;
  725. for (List<ExportData::PropertyData>::Element *E = resource.resources[resource.resources.size() - 1].properties.front(); E; E = E->next()) {
  726. if (E->get().name == "_bundled") {
  727. d = E->get().value;
  728. }
  729. }
  730. ERR_FAIL_COND(d.empty());
  731. ERR_FAIL_COND(!d.has("names"));
  732. ERR_FAIL_COND(!d.has("variants"));
  733. ERR_FAIL_COND(!d.has("node_count"));
  734. ERR_FAIL_COND(!d.has("nodes"));
  735. ERR_FAIL_COND(!d.has("conn_count"));
  736. ERR_FAIL_COND(!d.has("conns"));
  737. Vector<String> names;
  738. DVector<String> snames = d["names"];
  739. if (snames.size()) {
  740. int namecount = snames.size();
  741. names.resize(namecount);
  742. DVector<String>::Read r = snames.read();
  743. for (int i = 0; i < names.size(); i++)
  744. names[i] = r[i];
  745. }
  746. Array variants = d["variants"];
  747. resource.nodes.resize(d["node_count"]);
  748. int nc = resource.nodes.size();
  749. if (nc) {
  750. DVector<int> snodes = d["nodes"];
  751. DVector<int>::Read r = snodes.read();
  752. int idx = 0;
  753. for (int i = 0; i < nc; i++) {
  754. int parent = r[idx++];
  755. int owner = r[idx++];
  756. int type = r[idx++];
  757. int name = r[idx++];
  758. int instance = r[idx++];
  759. ExportData::NodeData &node_data = resource.nodes[i];
  760. node_data.text_data = false;
  761. node_data.name = names[name];
  762. if (type == 0x7FFFFFFF) {
  763. node_data.instanced = true;
  764. } else {
  765. node_data.instanced = false;
  766. node_data.type = names[type];
  767. }
  768. node_data.parent_int = parent;
  769. node_data.owner_int = owner;
  770. if (instance >= 0) {
  771. node_data.instance_is_placeholder = instance & SceneState::FLAG_INSTANCE_IS_PLACEHOLDER;
  772. node_data.instance = variants[instance & SceneState::FLAG_MASK];
  773. }
  774. int prop_count = r[idx++];
  775. for (int j = 0; j < prop_count; j++) {
  776. int prop_name = r[idx++];
  777. int prop_value = r[idx++];
  778. ExportData::PropertyData pdata;
  779. pdata.name = names[prop_name];
  780. pdata.value = variants[prop_value];
  781. node_data.properties.push_back(pdata);
  782. }
  783. int group_count = r[idx++];
  784. for (int j = 0; j < group_count; j++) {
  785. int group_name = r[idx++];
  786. node_data.groups.push_back(names[group_name]);
  787. }
  788. }
  789. }
  790. int cc = d["conn_count"];
  791. if (cc) {
  792. DVector<int> sconns = d["conns"];
  793. DVector<int>::Read r = sconns.read();
  794. int idx = 0;
  795. for (int i = 0; i < cc; i++) {
  796. ExportData::Connection conn;
  797. conn.from_int = r[idx++];
  798. conn.to_int = r[idx++];
  799. conn.signal = names[r[idx++]];
  800. conn.method = names[r[idx++]];
  801. conn.flags = r[idx++];
  802. int bindcount = r[idx++];
  803. for (int j = 0; j < bindcount; j++) {
  804. conn.binds.push_back(variants[r[idx++]]);
  805. }
  806. resource.connections.push_back(conn);
  807. }
  808. }
  809. Array np;
  810. if (d.has("node_paths")) {
  811. np = d["node_paths"];
  812. }
  813. for (int i = 0; i < np.size(); i++) {
  814. resource.node_paths.push_back(np[i]);
  815. }
  816. Array ei;
  817. if (d.has("editable_instances")) {
  818. ei = d["editable_instances"];
  819. for (int i = 0; i < ei.size(); i++) {
  820. resource.editables.push_back(ei[i]);
  821. }
  822. }
  823. if (d.has("base_scene")) {
  824. resource.base_scene = variants[d["base_scene"]];
  825. }
  826. resource.resources.resize(resource.resources.size() - 1); //erase packed
  827. }
  828. void EditorExportGodot3::_pack_packed_scene(ExportData &resource) {
  829. pack_names.clear();
  830. pack_values.clear();
  831. Dictionary d;
  832. d["node_count"] = resource.nodes.size();
  833. Vector<int> node_data;
  834. for (int i = 0; i < resource.nodes.size(); i++) {
  835. const ExportData::NodeData &node = resource.nodes[i];
  836. node_data.push_back(node.parent_int);
  837. node_data.push_back(node.owner_int);
  838. if (node.instanced) {
  839. node_data.push_back(0x7FFFFFFF);
  840. } else {
  841. int name = _pack_name(node.type);
  842. node_data.push_back(name);
  843. }
  844. node_data.push_back(_pack_name(node.name));
  845. int instance = -1;
  846. if (node.instance != String()) {
  847. instance = _pack_value(node.instance);
  848. if (node.instance_is_placeholder) {
  849. instance |= SceneState::FLAG_INSTANCE_IS_PLACEHOLDER;
  850. }
  851. }
  852. node_data.push_back(instance);
  853. node_data.push_back(node.properties.size());
  854. for (int j = 0; j < node.properties.size(); j++) {
  855. node_data.push_back(_pack_name(node.properties[j].name));
  856. node_data.push_back(_pack_value(node.properties[j].value));
  857. }
  858. node_data.push_back(node.groups.size());
  859. for (int j = 0; j < node.groups.size(); j++) {
  860. node_data.push_back(_pack_name(node.groups[j]));
  861. }
  862. }
  863. d["nodes"] = node_data;
  864. d["conn_count"] = resource.connections.size();
  865. Vector<int> connections;
  866. for (int i = 0; i < resource.connections.size(); i++) {
  867. const ExportData::Connection &conn = resource.connections[i];
  868. connections.push_back(conn.from_int);
  869. connections.push_back(conn.to_int);
  870. connections.push_back(_pack_name(conn.signal));
  871. connections.push_back(_pack_name(conn.method));
  872. connections.push_back(conn.flags);
  873. connections.push_back(conn.binds.size());
  874. for (int j = 0; j < conn.binds.size(); j++) {
  875. connections.push_back(_pack_value(conn.binds[j]));
  876. }
  877. }
  878. d["conns"] = connections;
  879. Array np;
  880. for (int i = 0; i < resource.node_paths.size(); i++) {
  881. np.push_back(resource.node_paths[i]);
  882. }
  883. d["node_paths"] = np;
  884. Array ei;
  885. for (int i = 0; i < resource.editables.size(); i++) {
  886. ei.push_back(resource.editables[i]);
  887. }
  888. d["editable_instances"] = ei;
  889. if (resource.base_scene.get_type()) {
  890. d["base_scene"] = _pack_value(resource.base_scene);
  891. }
  892. DVector<String> names;
  893. names.resize(pack_names.size());
  894. {
  895. DVector<String>::Write w = names.write();
  896. for (Map<String, int>::Element *E = pack_names.front(); E; E = E->next()) {
  897. w[E->get()] = E->key();
  898. }
  899. }
  900. d["names"] = names;
  901. Array values;
  902. values.resize(pack_values.size());
  903. const Variant *K = NULL;
  904. while ((K = pack_values.next(K))) {
  905. int index = pack_values[*K];
  906. values[index] = *K;
  907. }
  908. d["variants"] = values;
  909. ExportData::ResourceData packed_scene;
  910. packed_scene.type = "PackedScene";
  911. packed_scene.index = -1;
  912. ExportData::PropertyData pd;
  913. pd.name = "_bundled";
  914. pd.value = d;
  915. packed_scene.properties.push_back(pd);
  916. resource.resources.push_back(packed_scene);
  917. resource.nodes.clear();
  918. resource.connections.clear();
  919. resource.editables.clear();
  920. resource.node_paths.clear();
  921. ;
  922. resource.base_scene = Variant();
  923. }
  924. static String rtosfix(double p_value) {
  925. if (p_value == 0.0)
  926. return "0"; //avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist.
  927. else
  928. return rtoss(p_value);
  929. }
  930. Error EditorExportGodot3::_get_property_as_text(const Variant &p_variant, String &p_string) {
  931. switch (p_variant.get_type()) {
  932. case Variant::NIL: {
  933. p_string += ("null");
  934. } break;
  935. case Variant::BOOL: {
  936. p_string += (p_variant.operator bool() ? "true" : "false");
  937. } break;
  938. case Variant::INT: {
  939. p_string += (itos(p_variant.operator int()));
  940. } break;
  941. case Variant::REAL: {
  942. String s = rtosfix(p_variant.operator real_t());
  943. if (s.find(".") == -1 && s.find("e") == -1)
  944. s += ".0";
  945. p_string += (s);
  946. } break;
  947. case Variant::STRING: {
  948. String str = p_variant;
  949. if (str.begins_with("@RESLOCAL:")) {
  950. p_string += "SubResource( " + str.get_slice(":", 1) + " )";
  951. } else if (str.begins_with("@RESEXTERNAL:")) {
  952. p_string += "ExtResource( " + str.get_slice(":", 1) + " )";
  953. } else {
  954. // Call _replace_resource in case it's a path to a scene/resource
  955. str = "\"" + _replace_resource(str).c_escape_multiline() + "\"";
  956. p_string += (str);
  957. }
  958. } break;
  959. case Variant::VECTOR2: {
  960. Vector2 v = p_variant;
  961. p_string += ("Vector2( " + rtosfix(v.x) + ", " + rtosfix(v.y) + " )");
  962. } break;
  963. case Variant::RECT2: {
  964. Rect2 aabb = p_variant;
  965. p_string += ("Rect2( " + rtosfix(aabb.pos.x) + ", " + rtosfix(aabb.pos.y) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + " )");
  966. } break;
  967. case Variant::VECTOR3: {
  968. Vector3 v = p_variant;
  969. p_string += ("Vector3( " + rtosfix(v.x) + ", " + rtosfix(v.y) + ", " + rtosfix(v.z) + " )");
  970. } break;
  971. case Variant::PLANE: {
  972. Plane p = p_variant;
  973. p_string += ("Plane( " + rtosfix(p.normal.x) + ", " + rtosfix(p.normal.y) + ", " + rtosfix(p.normal.z) + ", " + rtosfix(p.d) + " )");
  974. } break;
  975. case Variant::_AABB: {
  976. Rect3 aabb = p_variant;
  977. p_string += ("Rect3( " + rtosfix(aabb.pos.x) + ", " + rtosfix(aabb.pos.y) + ", " + rtosfix(aabb.pos.z) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + ", " + rtosfix(aabb.size.z) + " )");
  978. } break;
  979. case Variant::QUAT: {
  980. Quat quat = p_variant;
  981. p_string += ("Quat( " + rtosfix(quat.x) + ", " + rtosfix(quat.y) + ", " + rtosfix(quat.z) + ", " + rtosfix(quat.w) + " )");
  982. } break;
  983. case Variant::MATRIX32: {
  984. String s = "Transform2D( ";
  985. Matrix32 m3 = p_variant;
  986. for (int i = 0; i < 3; i++) {
  987. for (int j = 0; j < 2; j++) {
  988. if (i != 0 || j != 0)
  989. s += ", ";
  990. s += rtosfix(m3.elements[i][j]);
  991. }
  992. }
  993. p_string += (s + " )");
  994. } break;
  995. case Variant::MATRIX3: {
  996. String s = "Basis( ";
  997. Matrix3 m3 = p_variant;
  998. for (int i = 0; i < 3; i++) {
  999. for (int j = 0; j < 3; j++) {
  1000. if (i != 0 || j != 0)
  1001. s += ", ";
  1002. s += rtosfix(m3.elements[i][j]);
  1003. }
  1004. }
  1005. p_string += (s + " )");
  1006. } break;
  1007. case Variant::TRANSFORM: {
  1008. String s = "Transform( ";
  1009. Transform t = p_variant;
  1010. Matrix3 &m3 = t.basis;
  1011. for (int i = 0; i < 3; i++) {
  1012. for (int j = 0; j < 3; j++) {
  1013. if (i != 0 || j != 0)
  1014. s += ", ";
  1015. s += rtosfix(m3.elements[i][j]);
  1016. }
  1017. }
  1018. s = s + ", " + rtosfix(t.origin.x) + ", " + rtosfix(t.origin.y) + ", " + rtosfix(t.origin.z);
  1019. p_string += (s + " )");
  1020. } break;
  1021. // misc types
  1022. case Variant::COLOR: {
  1023. Color c = p_variant;
  1024. p_string += ("Color( " + rtosfix(c.r) + ", " + rtosfix(c.g) + ", " + rtosfix(c.b) + ", " + rtosfix(c.a) + " )");
  1025. } break;
  1026. case Variant::IMAGE: {
  1027. Image img = p_variant;
  1028. if (img.empty()) {
  1029. p_string += ("Image()");
  1030. break;
  1031. }
  1032. String imgstr = "Image()";
  1033. p_string += imgstr; //do not convert this for now
  1034. /*imgstr+=itos(img.get_width());
  1035. imgstr+=", "+itos(img.get_height());
  1036. imgstr+=", "+String(img.get_mipmaps()?"true":"false");
  1037. imgstr+=", "+Image::get_format_name(img.get_format());
  1038. String s;
  1039. DVector<uint8_t> data = img.get_data();
  1040. int len = data.size();
  1041. DVector<uint8_t>::Read r = data.read();
  1042. const uint8_t *ptr=r.ptr();
  1043. for (int i=0;i<len;i++) {
  1044. if (i>0)
  1045. s+=", ";
  1046. s+=itos(ptr[i]);
  1047. }
  1048. imgstr+=", ";
  1049. p_string+=(imgstr);
  1050. p_string+=(s);
  1051. p_string+=(" )");*/
  1052. } break;
  1053. case Variant::NODE_PATH: {
  1054. String str = p_variant;
  1055. str = "NodePath(\"" + str.c_escape() + "\")";
  1056. p_string += (str);
  1057. } break;
  1058. case Variant::OBJECT: {
  1059. //should never arrive here!
  1060. ERR_FAIL_V(ERR_BUG);
  1061. } break;
  1062. case Variant::INPUT_EVENT: {
  1063. String str = "InputEvent(";
  1064. InputEvent ev = p_variant;
  1065. switch (ev.type) {
  1066. case InputEvent::KEY: {
  1067. str += "KEY," + itos(ev.key.scancode);
  1068. String mod;
  1069. if (ev.key.mod.alt)
  1070. mod += "A";
  1071. if (ev.key.mod.shift)
  1072. mod += "S";
  1073. if (ev.key.mod.control)
  1074. mod += "C";
  1075. if (ev.key.mod.meta)
  1076. mod += "M";
  1077. if (mod != String())
  1078. str += "," + mod;
  1079. } break;
  1080. case InputEvent::MOUSE_BUTTON: {
  1081. str += "MBUTTON," + itos(ev.mouse_button.button_index);
  1082. } break;
  1083. case InputEvent::JOYSTICK_BUTTON: {
  1084. str += "JBUTTON," + itos(ev.joy_button.button_index);
  1085. } break;
  1086. case InputEvent::JOYSTICK_MOTION: {
  1087. str += "JAXIS," + itos(ev.joy_motion.axis) + "," + itos(ev.joy_motion.axis_value);
  1088. } break;
  1089. case InputEvent::NONE: {
  1090. str += "NONE";
  1091. } break;
  1092. default: {
  1093. }
  1094. }
  1095. str += ")";
  1096. p_string += (str); //will be added later
  1097. } break;
  1098. case Variant::DICTIONARY: {
  1099. Dictionary dict = p_variant;
  1100. List<Variant> keys;
  1101. dict.get_key_list(&keys);
  1102. keys.sort();
  1103. p_string += ("{\n");
  1104. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  1105. /*
  1106. if (!_check_type(dict[E->get()]))
  1107. continue;
  1108. */
  1109. _get_property_as_text(E->get(), p_string);
  1110. p_string += (": ");
  1111. _get_property_as_text(dict[E->get()], p_string);
  1112. if (E->next())
  1113. p_string += (",\n");
  1114. }
  1115. p_string += ("\n}");
  1116. } break;
  1117. case Variant::ARRAY: {
  1118. p_string += ("[ ");
  1119. Array array = p_variant;
  1120. int len = array.size();
  1121. for (int i = 0; i < len; i++) {
  1122. if (i > 0)
  1123. p_string += (", ");
  1124. _get_property_as_text(array[i], p_string);
  1125. }
  1126. p_string += (" ]");
  1127. } break;
  1128. case Variant::RAW_ARRAY: {
  1129. p_string += ("PoolByteArray( ");
  1130. String s;
  1131. DVector<uint8_t> data = p_variant;
  1132. int len = data.size();
  1133. DVector<uint8_t>::Read r = data.read();
  1134. const uint8_t *ptr = r.ptr();
  1135. for (int i = 0; i < len; i++) {
  1136. if (i > 0)
  1137. p_string += (", ");
  1138. p_string += (itos(ptr[i]));
  1139. }
  1140. p_string += (" )");
  1141. } break;
  1142. case Variant::INT_ARRAY: {
  1143. p_string += ("PoolIntArray( ");
  1144. DVector<int> data = p_variant;
  1145. int len = data.size();
  1146. DVector<int>::Read r = data.read();
  1147. const int *ptr = r.ptr();
  1148. for (int i = 0; i < len; i++) {
  1149. if (i > 0)
  1150. p_string += (", ");
  1151. p_string += (itos(ptr[i]));
  1152. }
  1153. p_string += (" )");
  1154. } break;
  1155. case Variant::REAL_ARRAY: {
  1156. p_string += ("PoolRealArray( ");
  1157. DVector<real_t> data = p_variant;
  1158. int len = data.size();
  1159. DVector<real_t>::Read r = data.read();
  1160. const real_t *ptr = r.ptr();
  1161. for (int i = 0; i < len; i++) {
  1162. if (i > 0)
  1163. p_string += (", ");
  1164. p_string += (rtosfix(ptr[i]));
  1165. }
  1166. p_string += (" )");
  1167. } break;
  1168. case Variant::STRING_ARRAY: {
  1169. p_string += ("PoolStringArray( ");
  1170. DVector<String> data = p_variant;
  1171. int len = data.size();
  1172. DVector<String>::Read r = data.read();
  1173. const String *ptr = r.ptr();
  1174. String s;
  1175. //write_string("\n");
  1176. for (int i = 0; i < len; i++) {
  1177. if (i > 0)
  1178. p_string += (", ");
  1179. String str = ptr[i];
  1180. p_string += ("\"" + str.c_escape() + "\"");
  1181. }
  1182. p_string += (" )");
  1183. } break;
  1184. case Variant::VECTOR2_ARRAY: {
  1185. p_string += ("PoolVector2Array( ");
  1186. DVector<Vector2> data = p_variant;
  1187. int len = data.size();
  1188. DVector<Vector2>::Read r = data.read();
  1189. const Vector2 *ptr = r.ptr();
  1190. for (int i = 0; i < len; i++) {
  1191. if (i > 0)
  1192. p_string += (", ");
  1193. p_string += (rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y));
  1194. }
  1195. p_string += (" )");
  1196. } break;
  1197. case Variant::VECTOR3_ARRAY: {
  1198. p_string += ("PoolVector3Array( ");
  1199. DVector<Vector3> data = p_variant;
  1200. int len = data.size();
  1201. DVector<Vector3>::Read r = data.read();
  1202. const Vector3 *ptr = r.ptr();
  1203. for (int i = 0; i < len; i++) {
  1204. if (i > 0)
  1205. p_string += (", ");
  1206. p_string += (rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y) + ", " + rtosfix(ptr[i].z));
  1207. }
  1208. p_string += (" )");
  1209. } break;
  1210. case Variant::COLOR_ARRAY: {
  1211. p_string += ("PoolColorArray( ");
  1212. DVector<Color> data = p_variant;
  1213. int len = data.size();
  1214. DVector<Color>::Read r = data.read();
  1215. const Color *ptr = r.ptr();
  1216. for (int i = 0; i < len; i++) {
  1217. if (i > 0)
  1218. p_string += (", ");
  1219. p_string += (rtosfix(ptr[i].r) + ", " + rtosfix(ptr[i].g) + ", " + rtosfix(ptr[i].b) + ", " + rtosfix(ptr[i].a));
  1220. }
  1221. p_string += (" )");
  1222. } break;
  1223. default: {
  1224. }
  1225. }
  1226. return OK;
  1227. }
  1228. static String _valprop(const String &p_name) {
  1229. // Escape and quote strings with extended ASCII or further Unicode characters
  1230. // as well as '"', '=' or ' ' (32)
  1231. const CharType *cstr = p_name.c_str();
  1232. for (int i = 0; cstr[i]; i++) {
  1233. if (cstr[i] == '=' || cstr[i] == '"' || cstr[i] < 33 || cstr[i] > 126) {
  1234. return "\"" + p_name.c_escape_multiline() + "\"";
  1235. }
  1236. }
  1237. // Keep as is
  1238. return p_name;
  1239. }
  1240. void EditorExportGodot3::_save_text(const String &p_path, ExportData &resource) {
  1241. FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
  1242. if (resource.nodes.size()) {
  1243. f->store_line("[gd_scene load_steps=" + itos(resource.nodes.size() + resource.resources.size()) + " format=2]\n");
  1244. } else {
  1245. f->store_line("[gd_resource type=\"" + resource.resources[resource.resources.size() - 1].type + "\" load_steps=" + itos(resource.resources.size()) + " format=2]\n");
  1246. }
  1247. for (Map<int, ExportData::Dependency>::Element *E = resource.dependencies.front(); E; E = E->next()) {
  1248. f->store_line("[ext_resource path=\"" + resource_replace_map[E->get().path] + "\" type=\"" + E->get().type + "\" id=" + itos(E->key()) + "]");
  1249. }
  1250. for (int i = 0; i < resource.resources.size(); i++) {
  1251. if (resource.nodes.size() || i < resource.resources.size() - 1) {
  1252. f->store_line("\n[sub_resource type=\"" + resource.resources[i].type + "\" id=" + itos(resource.resources[i].index) + "]\n");
  1253. } else {
  1254. f->store_line("\n[resource]\n");
  1255. }
  1256. for (List<ExportData::PropertyData>::Element *E = resource.resources[i].properties.front(); E; E = E->next()) {
  1257. String prop;
  1258. _get_property_as_text(E->get().value, prop);
  1259. f->store_line(_valprop(E->get().name) + " = " + prop);
  1260. }
  1261. }
  1262. for (int i = 0; i < resource.nodes.size(); i++) {
  1263. String node_txt = "\n[node";
  1264. if (resource.nodes[i].name != String()) {
  1265. node_txt += " name=\"" + String(resource.nodes[i].name).c_escape() + "\"";
  1266. }
  1267. if (resource.nodes[i].owner != NodePath()) {
  1268. node_txt += " owner=\"" + String(resource.nodes[i].owner).c_escape() + "\"";
  1269. }
  1270. if (resource.nodes[i].type != String()) {
  1271. node_txt += " type=\"" + resource.nodes[i].type + "\"";
  1272. }
  1273. if (resource.nodes[i].parent != NodePath()) {
  1274. node_txt += " parent=\"" + String(resource.nodes[i].parent).c_escape() + "\"";
  1275. }
  1276. if (resource.nodes[i].instance != String()) {
  1277. String prop;
  1278. _get_property_as_text(resource.nodes[i].instance, prop);
  1279. node_txt += " instance=" + prop + "";
  1280. }
  1281. if (!resource.nodes[i].groups.empty()) {
  1282. node_txt += " groups=[\n";
  1283. for (int j = 0; j < resource.nodes[i].groups.size(); j++) {
  1284. node_txt += "\"" + resource.nodes[i].groups[j] + "\",\n";
  1285. }
  1286. node_txt += "]";
  1287. }
  1288. node_txt += "]\n";
  1289. f->store_line(node_txt);
  1290. for (List<ExportData::PropertyData>::Element *E = resource.nodes[i].properties.front(); E; E = E->next()) {
  1291. String prop;
  1292. _get_property_as_text(E->get().value, prop);
  1293. f->store_line(_valprop(E->get().name) + " = " + prop);
  1294. }
  1295. }
  1296. for (int i = 0; i < resource.connections.size(); i++) {
  1297. String binds_array;
  1298. _get_property_as_text(resource.connections[i].binds, binds_array);
  1299. f->store_line("\n[connection signal=\"" + resource.connections[i].signal + "\" from=\"" + String(resource.connections[i].from).c_escape() + "\" to=\"" + String(resource.connections[i].to).c_escape() + "\" method=\"" + resource.connections[i].method + "\" binds=" + binds_array + "]");
  1300. }
  1301. for (int i = 0; i < resource.editables.size(); i++) {
  1302. f->store_line("[editable path=\"" + String(resource.editables[i]).c_escape() + "\"]");
  1303. }
  1304. }
  1305. enum {
  1306. //numbering must be different from variant, in case new variant types are added (variant must be always contiguous for jumptable optimization)
  1307. VARIANT_NIL = 1,
  1308. VARIANT_BOOL = 2,
  1309. VARIANT_INT = 3,
  1310. VARIANT_REAL = 4,
  1311. VARIANT_STRING = 5,
  1312. VARIANT_VECTOR2 = 10,
  1313. VARIANT_RECT2 = 11,
  1314. VARIANT_VECTOR3 = 12,
  1315. VARIANT_PLANE = 13,
  1316. VARIANT_QUAT = 14,
  1317. VARIANT_AABB = 15,
  1318. VARIANT_MATRIX3 = 16,
  1319. VARIANT_TRANSFORM = 17,
  1320. VARIANT_MATRIX32 = 18,
  1321. VARIANT_COLOR = 20,
  1322. VARIANT_IMAGE = 21,
  1323. VARIANT_NODE_PATH = 22,
  1324. VARIANT_RID = 23,
  1325. VARIANT_OBJECT = 24,
  1326. VARIANT_INPUT_EVENT = 25,
  1327. VARIANT_DICTIONARY = 26,
  1328. VARIANT_ARRAY = 30,
  1329. VARIANT_RAW_ARRAY = 31,
  1330. VARIANT_INT_ARRAY = 32,
  1331. VARIANT_REAL_ARRAY = 33,
  1332. VARIANT_STRING_ARRAY = 34,
  1333. VARIANT_VECTOR3_ARRAY = 35,
  1334. VARIANT_COLOR_ARRAY = 36,
  1335. VARIANT_VECTOR2_ARRAY = 37,
  1336. VARIANT_INT64 = 40,
  1337. VARIANT_DOUBLE = 41,
  1338. IMAGE_ENCODING_EMPTY = 0,
  1339. IMAGE_ENCODING_RAW = 1,
  1340. IMAGE_ENCODING_LOSSLESS = 2,
  1341. IMAGE_ENCODING_LOSSY = 3,
  1342. OBJECT_EMPTY = 0,
  1343. OBJECT_EXTERNAL_RESOURCE = 1,
  1344. OBJECT_INTERNAL_RESOURCE = 2,
  1345. OBJECT_EXTERNAL_RESOURCE_INDEX = 3,
  1346. //version 2: added 64 bits support for float and int
  1347. FORMAT_VERSION = 2,
  1348. FORMAT_VERSION_CAN_RENAME_DEPS = 1
  1349. };
  1350. enum {
  1351. IMAGE_FORMAT_L8, //luminance
  1352. IMAGE_FORMAT_LA8, //luminance-alpha
  1353. IMAGE_FORMAT_R8,
  1354. IMAGE_FORMAT_RG8,
  1355. IMAGE_FORMAT_RGB8,
  1356. IMAGE_FORMAT_RGBA8,
  1357. IMAGE_FORMAT_RGB565, //16 bit
  1358. IMAGE_FORMAT_RGBA4444,
  1359. IMAGE_FORMAT_RGBA5551,
  1360. IMAGE_FORMAT_RF, //float
  1361. IMAGE_FORMAT_RGF,
  1362. IMAGE_FORMAT_RGBF,
  1363. IMAGE_FORMAT_RGBAF,
  1364. IMAGE_FORMAT_RH, //half float
  1365. IMAGE_FORMAT_RGH,
  1366. IMAGE_FORMAT_RGBH,
  1367. IMAGE_FORMAT_RGBAH,
  1368. IMAGE_FORMAT_DXT1, //s3tc bc1
  1369. IMAGE_FORMAT_DXT3, //bc2
  1370. IMAGE_FORMAT_DXT5, //bc3
  1371. IMAGE_FORMAT_ATI1, //bc4
  1372. IMAGE_FORMAT_ATI2, //bc5
  1373. IMAGE_FORMAT_BPTC_RGBA, //btpc bc6h
  1374. IMAGE_FORMAT_BPTC_RGBF, //float /
  1375. IMAGE_FORMAT_BPTC_RGBFU, //unsigned float
  1376. IMAGE_FORMAT_PVRTC2, //pvrtc
  1377. IMAGE_FORMAT_PVRTC2A,
  1378. IMAGE_FORMAT_PVRTC4,
  1379. IMAGE_FORMAT_PVRTC4A,
  1380. IMAGE_FORMAT_ETC, //etc1
  1381. IMAGE_FORMAT_ETC2_R11, //etc2
  1382. IMAGE_FORMAT_ETC2_R11S, //signed, NOT srgb.
  1383. IMAGE_FORMAT_ETC2_RG11,
  1384. IMAGE_FORMAT_ETC2_RG11S,
  1385. IMAGE_FORMAT_ETC2_RGB8,
  1386. IMAGE_FORMAT_ETC2_RGBA8,
  1387. IMAGE_FORMAT_ETC2_RGB8A1,
  1388. };
  1389. static void _pad_buffer(int p_bytes, FileAccess *f) {
  1390. int extra = 4 - (p_bytes % 4);
  1391. if (extra < 4) {
  1392. for (int i = 0; i < extra; i++)
  1393. f->store_8(0); //pad to 32
  1394. }
  1395. }
  1396. static void save_unicode_string(const String &p_string, FileAccess *f, bool p_hi_bit = false) {
  1397. CharString utf8 = p_string.utf8();
  1398. f->store_32(uint32_t(utf8.length() + 1) | (p_hi_bit ? 0x80000000 : 0));
  1399. f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1);
  1400. }
  1401. void EditorExportGodot3::_save_binary_property(const Variant &p_property, FileAccess *f) {
  1402. switch (p_property.get_type()) {
  1403. case Variant::NIL: {
  1404. f->store_32(VARIANT_NIL);
  1405. // don't store anything
  1406. } break;
  1407. case Variant::BOOL: {
  1408. f->store_32(VARIANT_BOOL);
  1409. bool val = p_property;
  1410. f->store_32(val);
  1411. } break;
  1412. case Variant::INT: {
  1413. f->store_32(VARIANT_INT);
  1414. int val = p_property;
  1415. f->store_32(int32_t(val));
  1416. } break;
  1417. case Variant::REAL: {
  1418. f->store_32(VARIANT_REAL);
  1419. f->store_real(p_property);
  1420. } break;
  1421. case Variant::STRING: {
  1422. String str = p_property;
  1423. if (str.begins_with("@RESLOCAL:")) {
  1424. f->store_32(VARIANT_OBJECT);
  1425. f->store_32(OBJECT_INTERNAL_RESOURCE);
  1426. f->store_32(str.get_slice(":", 1).to_int());
  1427. } else if (str.begins_with("@RESEXTERNAL:")) {
  1428. f->store_32(VARIANT_OBJECT);
  1429. f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX);
  1430. f->store_32(str.get_slice(":", 1).to_int());
  1431. } else {
  1432. f->store_32(VARIANT_STRING);
  1433. save_unicode_string(str, f);
  1434. }
  1435. } break;
  1436. case Variant::VECTOR2: {
  1437. f->store_32(VARIANT_VECTOR2);
  1438. Vector2 val = p_property;
  1439. f->store_real(val.x);
  1440. f->store_real(val.y);
  1441. } break;
  1442. case Variant::RECT2: {
  1443. f->store_32(VARIANT_RECT2);
  1444. Rect2 val = p_property;
  1445. f->store_real(val.pos.x);
  1446. f->store_real(val.pos.y);
  1447. f->store_real(val.size.x);
  1448. f->store_real(val.size.y);
  1449. } break;
  1450. case Variant::VECTOR3: {
  1451. f->store_32(VARIANT_VECTOR3);
  1452. Vector3 val = p_property;
  1453. f->store_real(val.x);
  1454. f->store_real(val.y);
  1455. f->store_real(val.z);
  1456. } break;
  1457. case Variant::PLANE: {
  1458. f->store_32(VARIANT_PLANE);
  1459. Plane val = p_property;
  1460. f->store_real(val.normal.x);
  1461. f->store_real(val.normal.y);
  1462. f->store_real(val.normal.z);
  1463. f->store_real(val.d);
  1464. } break;
  1465. case Variant::QUAT: {
  1466. f->store_32(VARIANT_QUAT);
  1467. Quat val = p_property;
  1468. f->store_real(val.x);
  1469. f->store_real(val.y);
  1470. f->store_real(val.z);
  1471. f->store_real(val.w);
  1472. } break;
  1473. case Variant::_AABB: {
  1474. f->store_32(VARIANT_AABB);
  1475. Rect3 val = p_property;
  1476. f->store_real(val.pos.x);
  1477. f->store_real(val.pos.y);
  1478. f->store_real(val.pos.z);
  1479. f->store_real(val.size.x);
  1480. f->store_real(val.size.y);
  1481. f->store_real(val.size.z);
  1482. } break;
  1483. case Variant::MATRIX32: {
  1484. f->store_32(VARIANT_MATRIX32);
  1485. Matrix32 val = p_property;
  1486. f->store_real(val.elements[0].x);
  1487. f->store_real(val.elements[0].y);
  1488. f->store_real(val.elements[1].x);
  1489. f->store_real(val.elements[1].y);
  1490. f->store_real(val.elements[2].x);
  1491. f->store_real(val.elements[2].y);
  1492. } break;
  1493. case Variant::MATRIX3: {
  1494. f->store_32(VARIANT_MATRIX3);
  1495. Matrix3 val = p_property;
  1496. f->store_real(val.elements[0].x);
  1497. f->store_real(val.elements[0].y);
  1498. f->store_real(val.elements[0].z);
  1499. f->store_real(val.elements[1].x);
  1500. f->store_real(val.elements[1].y);
  1501. f->store_real(val.elements[1].z);
  1502. f->store_real(val.elements[2].x);
  1503. f->store_real(val.elements[2].y);
  1504. f->store_real(val.elements[2].z);
  1505. } break;
  1506. case Variant::TRANSFORM: {
  1507. f->store_32(VARIANT_TRANSFORM);
  1508. Transform val = p_property;
  1509. f->store_real(val.basis.elements[0].x);
  1510. f->store_real(val.basis.elements[0].y);
  1511. f->store_real(val.basis.elements[0].z);
  1512. f->store_real(val.basis.elements[1].x);
  1513. f->store_real(val.basis.elements[1].y);
  1514. f->store_real(val.basis.elements[1].z);
  1515. f->store_real(val.basis.elements[2].x);
  1516. f->store_real(val.basis.elements[2].y);
  1517. f->store_real(val.basis.elements[2].z);
  1518. f->store_real(val.origin.x);
  1519. f->store_real(val.origin.y);
  1520. f->store_real(val.origin.z);
  1521. } break;
  1522. case Variant::COLOR: {
  1523. f->store_32(VARIANT_COLOR);
  1524. Color val = p_property;
  1525. f->store_real(val.r);
  1526. f->store_real(val.g);
  1527. f->store_real(val.b);
  1528. f->store_real(val.a);
  1529. } break;
  1530. case Variant::IMAGE: {
  1531. f->store_32(VARIANT_IMAGE);
  1532. Image val = p_property;
  1533. if (val.empty()) {
  1534. f->store_32(IMAGE_ENCODING_EMPTY);
  1535. break;
  1536. }
  1537. f->store_32(IMAGE_ENCODING_RAW);
  1538. f->store_32(val.get_width());
  1539. f->store_32(val.get_height());
  1540. f->store_32(val.get_mipmaps() ? 1 : 0);
  1541. switch (val.get_format()) {
  1542. case Image::FORMAT_GRAYSCALE:
  1543. f->store_32(IMAGE_FORMAT_L8);
  1544. break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
  1545. case Image::FORMAT_INTENSITY:
  1546. f->store_32(IMAGE_FORMAT_L8);
  1547. break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
  1548. case Image::FORMAT_GRAYSCALE_ALPHA:
  1549. f->store_32(IMAGE_FORMAT_LA8);
  1550. break; ///< two bytes per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255. alpha 0-255
  1551. case Image::FORMAT_RGB:
  1552. f->store_32(IMAGE_FORMAT_RGB8);
  1553. break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B
  1554. case Image::FORMAT_RGBA:
  1555. f->store_32(IMAGE_FORMAT_RGBA8);
  1556. break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B: f->store_32(IMAGE_FORMAT_ ); break; one byte A
  1557. case Image::FORMAT_BC1:
  1558. f->store_32(IMAGE_FORMAT_DXT1);
  1559. break; // DXT1
  1560. case Image::FORMAT_BC2:
  1561. f->store_32(IMAGE_FORMAT_DXT3);
  1562. break; // DXT3
  1563. case Image::FORMAT_BC3:
  1564. f->store_32(IMAGE_FORMAT_DXT5);
  1565. break; // DXT5
  1566. case Image::FORMAT_BC4:
  1567. f->store_32(IMAGE_FORMAT_ATI1);
  1568. break; // ATI1
  1569. case Image::FORMAT_BC5:
  1570. f->store_32(IMAGE_FORMAT_ATI2);
  1571. break; // ATI2
  1572. case Image::FORMAT_PVRTC2: f->store_32(IMAGE_FORMAT_PVRTC2); break;
  1573. case Image::FORMAT_PVRTC2_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC2A); break;
  1574. case Image::FORMAT_PVRTC4: f->store_32(IMAGE_FORMAT_PVRTC4); break;
  1575. case Image::FORMAT_PVRTC4_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC4A); break;
  1576. case Image::FORMAT_ETC:
  1577. f->store_32(IMAGE_FORMAT_ETC);
  1578. break; // regular ETC: f->store_32(IMAGE_FORMAT_ ); break; no transparency
  1579. default: f->store_32(IMAGE_FORMAT_L8); break;
  1580. }
  1581. int dlen = val.get_data().size();
  1582. f->store_32(dlen);
  1583. DVector<uint8_t>::Read r = val.get_data().read();
  1584. f->store_buffer(r.ptr(), dlen);
  1585. _pad_buffer(dlen, f);
  1586. } break;
  1587. case Variant::NODE_PATH: {
  1588. f->store_32(VARIANT_NODE_PATH);
  1589. NodePath np = p_property;
  1590. f->store_16(np.get_name_count());
  1591. uint16_t snc = np.get_subname_count();
  1592. if (np.is_absolute())
  1593. snc |= 0x8000;
  1594. f->store_16(snc);
  1595. for (int i = 0; i < np.get_name_count(); i++) {
  1596. save_unicode_string(np.get_name(i), f, true);
  1597. }
  1598. for (int i = 0; i < np.get_subname_count(); i++) {
  1599. save_unicode_string(np.get_subname(i), f, true);
  1600. }
  1601. save_unicode_string(np.get_property(), f, true);
  1602. } break;
  1603. case Variant::_RID: {
  1604. f->store_32(VARIANT_RID);
  1605. WARN_PRINT("Can't save RIDs");
  1606. RID val = p_property;
  1607. f->store_32(val.get_id());
  1608. } break;
  1609. case Variant::OBJECT: {
  1610. ERR_FAIL();
  1611. } break;
  1612. case Variant::INPUT_EVENT: {
  1613. f->store_32(VARIANT_INPUT_EVENT);
  1614. //InputEvent event = p_property;
  1615. f->store_32(0); //event type none, nothing else supported for now.
  1616. } break;
  1617. case Variant::DICTIONARY: {
  1618. f->store_32(VARIANT_DICTIONARY);
  1619. Dictionary d = p_property;
  1620. f->store_32(uint32_t(d.size()));
  1621. List<Variant> keys;
  1622. d.get_key_list(&keys);
  1623. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  1624. /*
  1625. if (!_check_type(dict[E->get()]))
  1626. continue;
  1627. */
  1628. _save_binary_property(E->get(), f);
  1629. _save_binary_property(d[E->get()], f);
  1630. }
  1631. } break;
  1632. case Variant::ARRAY: {
  1633. f->store_32(VARIANT_ARRAY);
  1634. Array a = p_property;
  1635. f->store_32(uint32_t(a.size()));
  1636. for (int i = 0; i < a.size(); i++) {
  1637. _save_binary_property(a[i], f);
  1638. }
  1639. } break;
  1640. case Variant::RAW_ARRAY: {
  1641. f->store_32(VARIANT_RAW_ARRAY);
  1642. DVector<uint8_t> arr = p_property;
  1643. int len = arr.size();
  1644. f->store_32(len);
  1645. DVector<uint8_t>::Read r = arr.read();
  1646. f->store_buffer(r.ptr(), len);
  1647. _pad_buffer(len, f);
  1648. } break;
  1649. case Variant::INT_ARRAY: {
  1650. f->store_32(VARIANT_INT_ARRAY);
  1651. DVector<int> arr = p_property;
  1652. int len = arr.size();
  1653. f->store_32(len);
  1654. DVector<int>::Read r = arr.read();
  1655. for (int i = 0; i < len; i++)
  1656. f->store_32(r[i]);
  1657. } break;
  1658. case Variant::REAL_ARRAY: {
  1659. f->store_32(VARIANT_REAL_ARRAY);
  1660. DVector<real_t> arr = p_property;
  1661. int len = arr.size();
  1662. f->store_32(len);
  1663. DVector<real_t>::Read r = arr.read();
  1664. for (int i = 0; i < len; i++) {
  1665. f->store_real(r[i]);
  1666. }
  1667. } break;
  1668. case Variant::STRING_ARRAY: {
  1669. f->store_32(VARIANT_STRING_ARRAY);
  1670. DVector<String> arr = p_property;
  1671. int len = arr.size();
  1672. f->store_32(len);
  1673. DVector<String>::Read r = arr.read();
  1674. for (int i = 0; i < len; i++) {
  1675. save_unicode_string(r[i], f);
  1676. }
  1677. } break;
  1678. case Variant::VECTOR3_ARRAY: {
  1679. f->store_32(VARIANT_VECTOR3_ARRAY);
  1680. DVector<Vector3> arr = p_property;
  1681. int len = arr.size();
  1682. f->store_32(len);
  1683. DVector<Vector3>::Read r = arr.read();
  1684. for (int i = 0; i < len; i++) {
  1685. f->store_real(r[i].x);
  1686. f->store_real(r[i].y);
  1687. f->store_real(r[i].z);
  1688. }
  1689. } break;
  1690. case Variant::VECTOR2_ARRAY: {
  1691. f->store_32(VARIANT_VECTOR2_ARRAY);
  1692. DVector<Vector2> arr = p_property;
  1693. int len = arr.size();
  1694. f->store_32(len);
  1695. DVector<Vector2>::Read r = arr.read();
  1696. for (int i = 0; i < len; i++) {
  1697. f->store_real(r[i].x);
  1698. f->store_real(r[i].y);
  1699. }
  1700. } break;
  1701. case Variant::COLOR_ARRAY: {
  1702. f->store_32(VARIANT_COLOR_ARRAY);
  1703. DVector<Color> arr = p_property;
  1704. int len = arr.size();
  1705. f->store_32(len);
  1706. DVector<Color>::Read r = arr.read();
  1707. for (int i = 0; i < len; i++) {
  1708. f->store_real(r[i].r);
  1709. f->store_real(r[i].g);
  1710. f->store_real(r[i].b);
  1711. f->store_real(r[i].a);
  1712. }
  1713. } break;
  1714. default: {
  1715. ERR_EXPLAIN("Invalid variant");
  1716. ERR_FAIL();
  1717. }
  1718. }
  1719. }
  1720. void EditorExportGodot3::_save_binary(const String &p_path, ExportData &resource) {
  1721. FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
  1722. ERR_FAIL_COND(!f.operator->());
  1723. //save header compressed
  1724. static const uint8_t header[4] = { 'R', 'S', 'R', 'C' };
  1725. f->store_buffer(header, 4);
  1726. f->store_32(0);
  1727. f->store_32(0); //64 bits file, false for now
  1728. f->store_32(3); //major
  1729. f->store_32(0); //minor
  1730. f->store_32(2); //format version (2 is for 3.0)
  1731. //f->store_32(saved_resources.size()+external_resources.size()); // load steps -not needed
  1732. save_unicode_string(resource.resources[resource.resources.size() - 1].type, f.operator->());
  1733. for (int i = 0; i < 16; i++)
  1734. f->store_32(0); // unused
  1735. f->store_32(0); //no names saved
  1736. f->store_32(resource.dependencies.size()); //amount of external resources
  1737. for (Map<int, ExportData::Dependency>::Element *E = resource.dependencies.front(); E; E = E->next()) {
  1738. save_unicode_string(E->get().type, f.operator->());
  1739. save_unicode_string(resource_replace_map[E->get().path], f.operator->());
  1740. }
  1741. // save internal resource table
  1742. Vector<uint64_t> ofs_pos;
  1743. f->store_32(resource.resources.size()); //amount of internal resources
  1744. for (int i = 0; i < resource.resources.size(); i++) {
  1745. save_unicode_string("local://" + itos(resource.resources[i].index), f.operator->());
  1746. ofs_pos.push_back(f->get_pos());
  1747. f->store_64(0);
  1748. }
  1749. Vector<uint64_t> ofs_table;
  1750. // int saved_idx=0;
  1751. //now actually save the resources
  1752. for (int i = 0; i < resource.resources.size(); i++) {
  1753. ofs_table.push_back(f->get_pos());
  1754. save_unicode_string(resource.resources[i].type, f.operator->());
  1755. f->store_32(resource.resources[i].properties.size());
  1756. for (List<ExportData::PropertyData>::Element *E = resource.resources[i].properties.front(); E; E = E->next()) {
  1757. save_unicode_string(E->get().name, f.operator->(), true);
  1758. _save_binary_property(E->get().value, f.operator->());
  1759. }
  1760. }
  1761. for (int i = 0; i < ofs_table.size(); i++) {
  1762. f->seek(ofs_pos[i]);
  1763. f->store_64(ofs_table[i]);
  1764. }
  1765. f->seek_end();
  1766. f->store_buffer((const uint8_t *)"RSRC", 4); //magic at end
  1767. ERR_FAIL_COND(f->get_error() != OK);
  1768. }
  1769. void EditorExportGodot3::_save_config(const String &p_path) {
  1770. // Parse existing config, convert persisting properties and store in ConfigFile
  1771. ConfigFile new_cfg = ConfigFile();
  1772. List<PropertyInfo> props;
  1773. Globals::get_singleton()->get_property_list(&props);
  1774. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  1775. if (!Globals::get_singleton()->has(E->get().name))
  1776. continue;
  1777. if (Globals::get_singleton()->is_persisting(E->get().name)) {
  1778. String newname;
  1779. if (globals_rename_map.has(E->get().name)) {
  1780. newname = globals_rename_map[E->get().name];
  1781. } else {
  1782. newname = E->get().name;
  1783. }
  1784. int sep = newname.find("/");
  1785. String section = newname.substr(0, sep);
  1786. String subname = newname.substr(sep + 1, newname.length());
  1787. String value;
  1788. _get_property_as_text(Globals::get_singleton()->get(E->get().name), value);
  1789. new_cfg.set_value(section, subname, value);
  1790. }
  1791. }
  1792. String str = "{\n\"flags/filter\": " + String(GLOBAL_DEF("image_loader/filter", true) ? "true" : "false");
  1793. str += ",\n\"flags/mipmaps\": " + String(GLOBAL_DEF("image_loader/gen_mipmaps", true) ? "true" : "false");
  1794. str += "\n}";
  1795. new_cfg.set_value("importer_defaults", "texture", str);
  1796. // Write the collected ConfigFile manually - we need to use _get_property_as_text()
  1797. // above, so we can't rely on ConfigFile.save() to properly store the raw strings.
  1798. FileAccessRef f = FileAccess::open(p_path.plus_file("project.godot"), FileAccess::WRITE);
  1799. List<String> sections;
  1800. new_cfg.get_sections(&sections);
  1801. for (List<String>::Element *E = sections.front(); E; E = E->next()) {
  1802. f->store_line("[" + E->get() + "]\n");
  1803. List<String> keys;
  1804. new_cfg.get_section_keys(E->get(), &keys);
  1805. for (List<String>::Element *F = keys.front(); F; F = F->next()) {
  1806. f->store_line(F->get() + " = " + new_cfg.get_value(E->get(), F->get()));
  1807. }
  1808. f->store_line("");
  1809. }
  1810. f->close();
  1811. }
  1812. Error EditorExportGodot3::_convert_script(const String &p_path, const String &p_target_path, bool mark_converted_lines) {
  1813. FileAccessRef src = FileAccess::open(p_path, FileAccess::READ);
  1814. ERR_FAIL_COND_V(!src.operator->(), FAILED);
  1815. FileAccessRef dst = FileAccess::open(p_target_path, FileAccess::WRITE);
  1816. ERR_FAIL_COND_V(!dst.operator->(), FAILED);
  1817. String http_var = "";
  1818. const String note = " #-- NOTE: Automatically converted by Godot 2 to 3 converter, please review";
  1819. while (!src->eof_reached()) {
  1820. String line = src->get_line();
  1821. String origline = line;
  1822. // Convert _fixed_process( => _physics_process(
  1823. RegEx regexp("(.*)_fixed_process\\((.*)");
  1824. int res = regexp.find(line);
  1825. if (res >= 0 && regexp.get_capture_count() == 3) {
  1826. line = regexp.get_capture(1) + "_physics_process(" + regexp.get_capture(2);
  1827. }
  1828. regexp.clear();
  1829. // Convert _input_event( => _gui_input(
  1830. regexp.compile("(.*)_input_event\\((.*)");
  1831. res = regexp.find(line);
  1832. if (res >= 0 && regexp.get_capture_count() == 3) {
  1833. line = regexp.get_capture(1) + "_gui_input(" + regexp.get_capture(2);
  1834. }
  1835. regexp.clear();
  1836. // Try to detect a HTTPClient object
  1837. regexp.compile("[ \t]*([a-zA-Z0-9_]*)[ ]*=[ ]*HTTPClient\\.new\\(\\)");
  1838. res = regexp.find(line);
  1839. if (res >= 0 && regexp.get_capture_count() == 2) {
  1840. http_var = regexp.get_capture(1).strip_edges();
  1841. }
  1842. regexp.clear();
  1843. if (http_var != "") {
  1844. // Convert .connect( => .connect_to_host(
  1845. regexp.compile("(.*)" + http_var + "\\.connect\\((.*)");
  1846. res = regexp.find(line);
  1847. if (res >= 0 && regexp.get_capture_count() == 3) {
  1848. line = regexp.get_capture(1) + http_var + ".connect_to_host(" + regexp.get_capture(2);
  1849. }
  1850. regexp.clear();
  1851. }
  1852. // The following replacements may be needed more than once per line, hence the loop
  1853. int count;
  1854. int tries = 0;
  1855. do {
  1856. count = 0;
  1857. // Convert all types to fix instances of renamed Nodes, or renamed core types (Pool*Array, Basis, etc.)
  1858. for (Map<String, String>::Element *E = type_rename_map.front(); E; E = E->next()) {
  1859. //regexp.compile("(.*[^a-zA-Z0-9_])" + E->key() + "([^a-zA-Z0-9_].*)");
  1860. regexp.compile("(.*\\b)" + E->key() + "(\\b.*)");
  1861. res = regexp.find(line);
  1862. if (res >= 0 && regexp.get_capture_count() == 3) {
  1863. line = regexp.get_capture(1) + E->get() + regexp.get_capture(2);
  1864. count++;
  1865. }
  1866. regexp.clear();
  1867. }
  1868. // Convert _pos( => _position(
  1869. regexp.compile("(.*)_pos\\((.*)");
  1870. res = regexp.find(line);
  1871. if (res >= 0 && regexp.get_capture_count() == 3) {
  1872. line = regexp.get_capture(1) + "_position(" + regexp.get_capture(2);
  1873. count++;
  1874. }
  1875. regexp.clear();
  1876. // Convert .pos => .position
  1877. regexp.compile("(.*)\\.pos([^a-zA-Z0-9_-].*)");
  1878. res = regexp.find(line);
  1879. if (res >= 0 && regexp.get_capture_count() == 3) {
  1880. line = regexp.get_capture(1) + ".position" + regexp.get_capture(2);
  1881. count++;
  1882. }
  1883. regexp.clear();
  1884. // Convert _rot( => _rotation(
  1885. regexp.compile("(.*)_rot\\((.*)");
  1886. res = regexp.find(line);
  1887. if (res >= 0 && regexp.get_capture_count() == 3) {
  1888. line = regexp.get_capture(1) + "_rotation(" + regexp.get_capture(2);
  1889. count++;
  1890. }
  1891. regexp.clear();
  1892. // Convert _speed( => _speed_scale(
  1893. regexp.compile("(.*)_speed\\((.*)");
  1894. res = regexp.find(line);
  1895. if (res >= 0 && regexp.get_capture_count() == 3) {
  1896. line = regexp.get_capture(1) + "_speed_scale(" + regexp.get_capture(2);
  1897. count++;
  1898. }
  1899. regexp.clear();
  1900. // Convert KEY_RETURN => KEY_ENTER
  1901. regexp.compile("(.*)KEY_RETURN(.*)");
  1902. res = regexp.find(line);
  1903. if (res >= 0 && regexp.get_capture_count() == 3) {
  1904. line = regexp.get_capture(1) + "KEY_ENTER" + regexp.get_capture(2);
  1905. count++;
  1906. }
  1907. regexp.clear();
  1908. // Convert get_opacity() => modulate.a
  1909. regexp.compile("(.*)get_opacity\\(\\)(.*)");
  1910. res = regexp.find(line);
  1911. if (res >= 0 && regexp.get_capture_count() == 3) {
  1912. line = regexp.get_capture(1) + "modulate.a" + regexp.get_capture(2);
  1913. count++;
  1914. }
  1915. regexp.clear();
  1916. // Convert set_opacity(var) => modulate.a = var
  1917. regexp.compile("(.*)set_opacity\\((.*)\\)(.*)");
  1918. res = regexp.find(line);
  1919. if (res >= 0 && regexp.get_capture_count() == 4) {
  1920. line = regexp.get_capture(1) + "modulate.a = " + regexp.get_capture(2) + regexp.get_capture(3);
  1921. count++;
  1922. }
  1923. regexp.clear();
  1924. // Convert get_self_opacity() => self_modulate.a
  1925. regexp.compile("(.*)get_self_opacity\\(\\)(.*)");
  1926. res = regexp.find(line);
  1927. if (res >= 0 && regexp.get_capture_count() == 3) {
  1928. line = regexp.get_capture(1) + "self_modulate.a" + regexp.get_capture(2);
  1929. count++;
  1930. }
  1931. regexp.clear();
  1932. // Convert set_self_opacity(var) => self_modulate.a = var
  1933. regexp.compile("(.*)set_self_opacity\\((.*)\\)(.*)");
  1934. res = regexp.find(line);
  1935. if (res >= 0 && regexp.get_capture_count() == 4) {
  1936. line = regexp.get_capture(1) + "self_modulate.a = " + regexp.get_capture(2) + regexp.get_capture(3);
  1937. count++;
  1938. }
  1939. regexp.clear();
  1940. // Convert set_hidden(var) => visible = !(var)
  1941. regexp.compile("(.*)set_hidden\\((.*)\\)(.*)");
  1942. res = regexp.find(line);
  1943. if (res >= 0 && regexp.get_capture_count() == 4) {
  1944. line = regexp.get_capture(1) + "visible = !(" + regexp.get_capture(2) + ")" + regexp.get_capture(3);
  1945. count++;
  1946. }
  1947. regexp.clear();
  1948. // Convert var.type == InputEvent.KEY => var is InputEventKey
  1949. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.KEY(.*)");
  1950. res = regexp.find(line);
  1951. if (res >= 0 && regexp.get_capture_count() == 3) {
  1952. line = regexp.get_capture(1) + " is InputEventKey" + regexp.get_capture(2);
  1953. count++;
  1954. }
  1955. regexp.clear();
  1956. // Convert var.type == InputEvent.MOUSE_MOTION => var is InputEventMouseMotion
  1957. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.MOUSE_MOTION(.*)");
  1958. res = regexp.find(line);
  1959. if (res >= 0 && regexp.get_capture_count() == 3) {
  1960. line = regexp.get_capture(1) + " is InputEventMouseMotion" + regexp.get_capture(2);
  1961. count++;
  1962. }
  1963. regexp.clear();
  1964. // Convert var.type == InputEvent.MOUSE_BUTTON => var is InputEventMouseButton
  1965. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.MOUSE_BUTTON(.*)");
  1966. res = regexp.find(line);
  1967. if (res >= 0 && regexp.get_capture_count() == 3) {
  1968. line = regexp.get_capture(1) + " is InputEventMouseButton" + regexp.get_capture(2);
  1969. count++;
  1970. }
  1971. regexp.clear();
  1972. // Convert var.type == InputEvent.JOYSTICK_MOTION => var is InputEventJoypadMotion
  1973. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.JOYSTICK_MOTION(.*)");
  1974. res = regexp.find(line);
  1975. if (res >= 0 && regexp.get_capture_count() == 3) {
  1976. line = regexp.get_capture(1) + " is InputEventJoypadMotion" + regexp.get_capture(2);
  1977. count++;
  1978. }
  1979. regexp.clear();
  1980. // Convert var.type == InputEvent.JOYSTICK_BUTTON => var is InputEventJoypadButton
  1981. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.JOYSTICK_BUTTON(.*)");
  1982. res = regexp.find(line);
  1983. if (res >= 0 && regexp.get_capture_count() == 3) {
  1984. line = regexp.get_capture(1) + " is InputEventJoypadButton" + regexp.get_capture(2);
  1985. count++;
  1986. }
  1987. regexp.clear();
  1988. // Convert var.type == InputEvent.SCREEN_TOUCH => var is InputEventScreenTouch
  1989. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.SCREEN_TOUCH(.*)");
  1990. res = regexp.find(line);
  1991. if (res >= 0 && regexp.get_capture_count() == 3) {
  1992. line = regexp.get_capture(1) + " is InputEventScreenTouch" + regexp.get_capture(2);
  1993. count++;
  1994. }
  1995. regexp.clear();
  1996. // Convert var.type == InputEvent.SCREEN_DRAG => var is InputEventScreenDrag
  1997. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.SCREEN_DRAG(.*)");
  1998. res = regexp.find(line);
  1999. if (res >= 0 && regexp.get_capture_count() == 3) {
  2000. line = regexp.get_capture(1) + " is InputEventScreenDrag" + regexp.get_capture(2);
  2001. count++;
  2002. }
  2003. regexp.clear();
  2004. // Convert move( => move_and_collide(
  2005. regexp.compile("(.*)move\\((.*)");
  2006. res = regexp.find(line);
  2007. if (res >= 0 && regexp.get_capture_count() == 3) {
  2008. line = regexp.get_capture(1) + "move_and_collide(" + regexp.get_capture(2);
  2009. count++;
  2010. }
  2011. regexp.clear();
  2012. // Convert is_move_and_slide_on_floor() => is_on_floor()
  2013. regexp.compile("(.*)is_move_and_slide_on_floor\\(\\)(.*)");
  2014. res = regexp.find(line);
  2015. if (res >= 0 && regexp.get_capture_count() == 3) {
  2016. line = regexp.get_capture(1) + "is_on_floor()" + regexp.get_capture(2);
  2017. count++;
  2018. }
  2019. regexp.clear();
  2020. // Convert is_move_and_slide_on_ceiling() => is_on_ceiling()
  2021. regexp.compile("(.*)is_move_and_slide_on_ceiling\\(\\)(.*)");
  2022. res = regexp.find(line);
  2023. if (res >= 0 && regexp.get_capture_count() == 3) {
  2024. line = regexp.get_capture(1) + "is_on_ceiling()" + regexp.get_capture(2);
  2025. count++;
  2026. }
  2027. regexp.clear();
  2028. // Convert is_move_and_slide_on_wall() => is_on_wall()
  2029. regexp.compile("(.*)is_move_and_slide_on_wall\\(\\)(.*)");
  2030. res = regexp.find(line);
  2031. if (res >= 0 && regexp.get_capture_count() == 3) {
  2032. line = regexp.get_capture(1) + "is_on_wall()" + regexp.get_capture(2);
  2033. count++;
  2034. }
  2035. regexp.clear();
  2036. // Convert <any chars but none> extends => <any chars but none> is
  2037. // The only case where we don't want to convert it is `^extends <Node>`
  2038. regexp.compile("(^.+ )extends(.*)");
  2039. res = regexp.find(line);
  2040. if (res >= 0 && regexp.get_capture_count() == 3) {
  2041. line = regexp.get_capture(1) + "is" + regexp.get_capture(2);
  2042. count++;
  2043. }
  2044. regexp.clear();
  2045. } while (count >= 1 && tries++ < 10);
  2046. if (mark_converted_lines && line != origline) {
  2047. // Add explanatory comment on the changed line
  2048. line += note;
  2049. }
  2050. dst->store_line(line);
  2051. }
  2052. return OK;
  2053. }
  2054. Error EditorExportGodot3::export_godot3(const String &p_path, bool convert_scripts, bool mark_converted_lines) {
  2055. List<String> files;
  2056. _find_files(EditorFileSystem::get_singleton()->get_filesystem(), &files);
  2057. EditorProgress progress("exporting", "Exporting the project to Godot 3.0", files.size());
  2058. //find XML resources
  2059. resource_replace_map.clear();
  2060. Set<String> xml_extensions;
  2061. Set<String> binary_extensions;
  2062. Set<String> text_extensions;
  2063. {
  2064. List<String> xml_exts;
  2065. ResourceFormatLoaderXML::singleton->get_recognized_extensions(&xml_exts);
  2066. for (List<String>::Element *E = xml_exts.front(); E; E = E->next()) {
  2067. xml_extensions.insert(E->get());
  2068. }
  2069. }
  2070. {
  2071. List<String> binary_exts;
  2072. ResourceFormatLoaderBinary::singleton->get_recognized_extensions(&binary_exts);
  2073. for (List<String>::Element *E = binary_exts.front(); E; E = E->next()) {
  2074. binary_extensions.insert(E->get());
  2075. }
  2076. }
  2077. {
  2078. List<String> text_exts;
  2079. ResourceFormatLoaderText::singleton->get_recognized_extensions(&text_exts);
  2080. for (List<String>::Element *E = text_exts.front(); E; E = E->next()) {
  2081. text_extensions.insert(E->get());
  2082. }
  2083. }
  2084. for (List<String>::Element *E = files.front(); E; E = E->next()) {
  2085. String file = E->get();
  2086. String file_local = file.replace("res://", "");
  2087. resource_replace_map[file] = file;
  2088. resource_replace_map[file_local] = file_local;
  2089. if (xml_extensions.has(file.extension().to_lower())) {
  2090. if (ResourceLoader::get_resource_type(file) == "PackedScene") {
  2091. resource_replace_map[file] = file.basename() + ".tscn";
  2092. resource_replace_map[file_local] = file_local.basename() + ".tscn";
  2093. } else {
  2094. resource_replace_map[file] = file.basename() + ".tres";
  2095. resource_replace_map[file_local] = file_local.basename() + ".tres";
  2096. }
  2097. }
  2098. // Changing all the old extensions to new Godot 3.0 extensions.
  2099. // Refer PR #9201
  2100. String extension = file.extension().to_lower();
  2101. if (extension == "anm") {
  2102. resource_replace_map[file] = file.basename() + ".anim";
  2103. resource_replace_map[file_local] = file_local.basename() + ".anim";
  2104. } else if (extension == "asogg") {
  2105. resource_replace_map[file] = file.basename() + ".oggstr";
  2106. resource_replace_map[file_local] = file_local.basename() + ".oggstr";
  2107. } else if (extension == "atex") {
  2108. resource_replace_map[file] = file.basename() + ".atlastex";
  2109. resource_replace_map[file_local] = file_local.basename() + ".atlastex";
  2110. } else if (extension == "cbm") {
  2111. resource_replace_map[file] = file.basename() + ".cubemap";
  2112. resource_replace_map[file_local] = file_local.basename() + ".cubemap";
  2113. } else if (extension == "cvtex") {
  2114. resource_replace_map[file] = file.basename() + ".curvetex";
  2115. resource_replace_map[file_local] = file_local.basename() + ".curvetex";
  2116. } else if (extension == "fnt") {
  2117. resource_replace_map[file] = file.basename() + ".font";
  2118. resource_replace_map[file_local] = file_local.basename() + ".font";
  2119. } else if (extension == "gt") {
  2120. resource_replace_map[file] = file.basename() + ".meshlib";
  2121. resource_replace_map[file_local] = file_local.basename() + ".meshlib";
  2122. } else if (extension == "ltex") {
  2123. resource_replace_map[file] = file.basename() + ".largetex";
  2124. resource_replace_map[file_local] = file_local.basename() + ".largetex";
  2125. } else if (extension == "mmsh") {
  2126. resource_replace_map[file] = file.basename() + ".multimesh";
  2127. resource_replace_map[file_local] = file_local.basename() + ".multimesh";
  2128. } else if (extension == "msh") {
  2129. resource_replace_map[file] = file.basename() + ".mesh";
  2130. resource_replace_map[file_local] = file_local.basename() + ".mesh";
  2131. } else if (extension == "mtl") {
  2132. resource_replace_map[file] = file.basename() + ".material";
  2133. resource_replace_map[file_local] = file_local.basename() + ".material";
  2134. } else if (extension == "sbx") {
  2135. resource_replace_map[file] = file.basename() + ".stylebox";
  2136. resource_replace_map[file_local] = file_local.basename() + ".stylebox";
  2137. } else if (extension == "sgp") {
  2138. resource_replace_map[file] = file.basename() + ".vshader";
  2139. resource_replace_map[file_local] = file_local.basename() + ".vshader";
  2140. } else if (extension == "shd") {
  2141. resource_replace_map[file] = file.basename() + ".shader";
  2142. resource_replace_map[file_local] = file_local.basename() + ".shader";
  2143. } else if (extension == "shp") {
  2144. resource_replace_map[file] = file.basename() + ".shape";
  2145. resource_replace_map[file_local] = file_local.basename() + ".shape";
  2146. } else if (extension == "smp") {
  2147. resource_replace_map[file] = file.basename() + ".sample";
  2148. resource_replace_map[file_local] = file_local.basename() + ".sample";
  2149. } else if (extension == "tex") {
  2150. resource_replace_map[file] = file.basename() + ".texture";
  2151. resource_replace_map[file_local] = file_local.basename() + ".texture";
  2152. } else if (extension == "thm") {
  2153. resource_replace_map[file] = file.basename() + ".theme";
  2154. resource_replace_map[file_local] = file_local.basename() + ".theme";
  2155. } else if (extension == "wrd") {
  2156. resource_replace_map[file] = file.basename() + ".world";
  2157. resource_replace_map[file_local] = file_local.basename() + ".world";
  2158. } else if (extension == "xl") {
  2159. resource_replace_map[file] = file.basename() + ".translation";
  2160. resource_replace_map[file_local] = file_local.basename() + ".translation";
  2161. }
  2162. }
  2163. DirAccess *directory = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2164. if (directory->change_dir(p_path) != OK) {
  2165. memdelete(directory);
  2166. ERR_FAIL_V(ERR_CANT_OPEN);
  2167. }
  2168. int idx = 0;
  2169. for (List<String>::Element *E = files.front(); E; E = E->next()) {
  2170. String path = E->get();
  2171. String extension = path.extension().to_lower();
  2172. String target_path;
  2173. bool repack = false;
  2174. target_path = p_path.plus_file(path.replace("res://", ""));
  2175. // Changing all the old extensions to new Godot 3.0 extensions.
  2176. // Refer PR #9201
  2177. if (extension == "fnt") {
  2178. target_path = target_path.basename() + ".font";
  2179. } else if (extension == "asogg") {
  2180. target_path = target_path.basename() + ".oggstr";
  2181. } else if (extension == "atex") {
  2182. target_path = target_path.basename() + ".atlastex";
  2183. } else if (extension == "cbm") {
  2184. target_path = target_path.basename() + ".cubemap";
  2185. } else if (extension == "cvtex") {
  2186. target_path = target_path.basename() + ".curvetex";
  2187. } else if (extension == "fnt") {
  2188. target_path = target_path.basename() + ".font";
  2189. } else if (extension == "gt") {
  2190. target_path = target_path.basename() + ".meshlib";
  2191. } else if (extension == "ltex") {
  2192. target_path = target_path.basename() + ".largetex";
  2193. } else if (extension == "mmsh") {
  2194. target_path = target_path.basename() + ".multimesh";
  2195. } else if (extension == "msh") {
  2196. target_path = target_path.basename() + ".mesh";
  2197. } else if (extension == "mtl") {
  2198. target_path = target_path.basename() + ".material";
  2199. } else if (extension == "sbx") {
  2200. target_path = target_path.basename() + ".stylebox";
  2201. } else if (extension == "sgp") {
  2202. target_path = target_path.basename() + ".vshader";
  2203. } else if (extension == "shd") {
  2204. target_path = target_path.basename() + ".shader";
  2205. } else if (extension == "shp") {
  2206. target_path = target_path.basename() + ".shape";
  2207. } else if (extension == "smp") {
  2208. target_path = target_path.basename() + ".sample";
  2209. } else if (extension == "tex") {
  2210. target_path = target_path.basename() + ".texture";
  2211. } else if (extension == "thm") {
  2212. target_path = target_path.basename() + ".theme";
  2213. } else if (extension == "wrd") {
  2214. target_path = target_path.basename() + ".world";
  2215. } else if (extension == "xl") {
  2216. target_path = target_path.basename() + ".translation";
  2217. }
  2218. progress.step(target_path.get_file(), idx++);
  2219. print_line("-- Exporting file: " + target_path);
  2220. if (directory->make_dir_recursive(target_path.get_base_dir()) != OK) {
  2221. memdelete(directory);
  2222. ERR_FAIL_V(ERR_CANT_CREATE);
  2223. }
  2224. ExportData resource_data;
  2225. Error err;
  2226. bool cont = false;
  2227. if (xml_extensions.has(extension)) {
  2228. err = ResourceLoader::get_export_data(path, resource_data);
  2229. } else if (text_extensions.has(extension)) {
  2230. err = ResourceLoader::get_export_data(path, resource_data);
  2231. } else if (binary_extensions.has(extension)) {
  2232. err = ResourceLoader::get_export_data(path, resource_data);
  2233. } else {
  2234. if (convert_scripts && extension == "gd") {
  2235. err = _convert_script(path, target_path, mark_converted_lines);
  2236. } else {
  2237. //single file, copy it
  2238. err = directory->copy(path, target_path);
  2239. }
  2240. cont = true; //no longer needed to do anything, just copied the file!
  2241. }
  2242. if (err != OK) {
  2243. memdelete(directory);
  2244. ERR_FAIL_V(err);
  2245. }
  2246. if (cont) {
  2247. continue;
  2248. }
  2249. if (resource_data.nodes.size() == 0 && resource_data.resources[resource_data.resources.size() - 1].type == "PackedScene") {
  2250. //must unpack a PackedScene
  2251. _unpack_packed_scene(resource_data);
  2252. repack = true;
  2253. }
  2254. _convert_resources(resource_data);
  2255. if (repack) {
  2256. _pack_packed_scene(resource_data);
  2257. }
  2258. if (xml_extensions.has(extension)) {
  2259. String save_path = resource_replace_map[target_path];
  2260. _save_text(save_path, resource_data);
  2261. } else if (text_extensions.has(extension)) {
  2262. _save_text(target_path, resource_data);
  2263. } else if (binary_extensions.has(extension)) {
  2264. _save_binary(target_path, resource_data);
  2265. }
  2266. }
  2267. memdelete(directory);
  2268. _save_config(p_path);
  2269. return OK;
  2270. }
  2271. EditorExportGodot3::EditorExportGodot3() {
  2272. int idx = 0;
  2273. while (globals_renames[idx][0] != NULL) {
  2274. globals_rename_map[globals_renames[idx][0]] = globals_renames[idx][1];
  2275. idx++;
  2276. }
  2277. idx = 0;
  2278. while (prop_renames[idx][0] != NULL) {
  2279. prop_rename_map[prop_renames[idx][0]] = prop_renames[idx][1];
  2280. idx++;
  2281. }
  2282. idx = 0;
  2283. while (type_renames[idx][0] != NULL) {
  2284. type_rename_map[type_renames[idx][0]] = type_renames[idx][1];
  2285. idx++;
  2286. }
  2287. idx = 0;
  2288. while (signal_renames[idx][0] != NULL) {
  2289. signal_rename_map[signal_renames[idx][0]] = signal_renames[idx][1];
  2290. idx++;
  2291. }
  2292. }