editor_export_godot3.cpp 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761
  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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. str += ")";
  1095. p_string += (str); //will be added later
  1096. } break;
  1097. case Variant::DICTIONARY: {
  1098. Dictionary dict = p_variant;
  1099. List<Variant> keys;
  1100. dict.get_key_list(&keys);
  1101. keys.sort();
  1102. p_string += ("{\n");
  1103. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  1104. /*
  1105. if (!_check_type(dict[E->get()]))
  1106. continue;
  1107. */
  1108. _get_property_as_text(E->get(), p_string);
  1109. p_string += (": ");
  1110. _get_property_as_text(dict[E->get()], p_string);
  1111. if (E->next())
  1112. p_string += (",\n");
  1113. }
  1114. p_string += ("\n}");
  1115. } break;
  1116. case Variant::ARRAY: {
  1117. p_string += ("[ ");
  1118. Array array = p_variant;
  1119. int len = array.size();
  1120. for (int i = 0; i < len; i++) {
  1121. if (i > 0)
  1122. p_string += (", ");
  1123. _get_property_as_text(array[i], p_string);
  1124. }
  1125. p_string += (" ]");
  1126. } break;
  1127. case Variant::RAW_ARRAY: {
  1128. p_string += ("PoolByteArray( ");
  1129. String s;
  1130. DVector<uint8_t> data = p_variant;
  1131. int len = data.size();
  1132. DVector<uint8_t>::Read r = data.read();
  1133. const uint8_t *ptr = r.ptr();
  1134. for (int i = 0; i < len; i++) {
  1135. if (i > 0)
  1136. p_string += (", ");
  1137. p_string += (itos(ptr[i]));
  1138. }
  1139. p_string += (" )");
  1140. } break;
  1141. case Variant::INT_ARRAY: {
  1142. p_string += ("PoolIntArray( ");
  1143. DVector<int> data = p_variant;
  1144. int len = data.size();
  1145. DVector<int>::Read r = data.read();
  1146. const int *ptr = r.ptr();
  1147. for (int i = 0; i < len; i++) {
  1148. if (i > 0)
  1149. p_string += (", ");
  1150. p_string += (itos(ptr[i]));
  1151. }
  1152. p_string += (" )");
  1153. } break;
  1154. case Variant::REAL_ARRAY: {
  1155. p_string += ("PoolRealArray( ");
  1156. DVector<real_t> data = p_variant;
  1157. int len = data.size();
  1158. DVector<real_t>::Read r = data.read();
  1159. const real_t *ptr = r.ptr();
  1160. for (int i = 0; i < len; i++) {
  1161. if (i > 0)
  1162. p_string += (", ");
  1163. p_string += (rtosfix(ptr[i]));
  1164. }
  1165. p_string += (" )");
  1166. } break;
  1167. case Variant::STRING_ARRAY: {
  1168. p_string += ("PoolStringArray( ");
  1169. DVector<String> data = p_variant;
  1170. int len = data.size();
  1171. DVector<String>::Read r = data.read();
  1172. const String *ptr = r.ptr();
  1173. String s;
  1174. //write_string("\n");
  1175. for (int i = 0; i < len; i++) {
  1176. if (i > 0)
  1177. p_string += (", ");
  1178. String str = ptr[i];
  1179. p_string += ("\"" + str.c_escape() + "\"");
  1180. }
  1181. p_string += (" )");
  1182. } break;
  1183. case Variant::VECTOR2_ARRAY: {
  1184. p_string += ("PoolVector2Array( ");
  1185. DVector<Vector2> data = p_variant;
  1186. int len = data.size();
  1187. DVector<Vector2>::Read r = data.read();
  1188. const Vector2 *ptr = r.ptr();
  1189. for (int i = 0; i < len; i++) {
  1190. if (i > 0)
  1191. p_string += (", ");
  1192. p_string += (rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y));
  1193. }
  1194. p_string += (" )");
  1195. } break;
  1196. case Variant::VECTOR3_ARRAY: {
  1197. p_string += ("PoolVector3Array( ");
  1198. DVector<Vector3> data = p_variant;
  1199. int len = data.size();
  1200. DVector<Vector3>::Read r = data.read();
  1201. const Vector3 *ptr = r.ptr();
  1202. for (int i = 0; i < len; i++) {
  1203. if (i > 0)
  1204. p_string += (", ");
  1205. p_string += (rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y) + ", " + rtosfix(ptr[i].z));
  1206. }
  1207. p_string += (" )");
  1208. } break;
  1209. case Variant::COLOR_ARRAY: {
  1210. p_string += ("PoolColorArray( ");
  1211. DVector<Color> data = p_variant;
  1212. int len = data.size();
  1213. DVector<Color>::Read r = data.read();
  1214. const Color *ptr = r.ptr();
  1215. for (int i = 0; i < len; i++) {
  1216. if (i > 0)
  1217. p_string += (", ");
  1218. p_string += (rtosfix(ptr[i].r) + ", " + rtosfix(ptr[i].g) + ", " + rtosfix(ptr[i].b) + ", " + rtosfix(ptr[i].a));
  1219. }
  1220. p_string += (" )");
  1221. } break;
  1222. default: {}
  1223. }
  1224. return OK;
  1225. }
  1226. static String _valprop(const String &p_name) {
  1227. // Escape and quote strings with extended ASCII or further Unicode characters
  1228. // as well as '"', '=' or ' ' (32)
  1229. const CharType *cstr = p_name.c_str();
  1230. for (int i = 0; cstr[i]; i++) {
  1231. if (cstr[i] == '=' || cstr[i] == '"' || cstr[i] < 33 || cstr[i] > 126) {
  1232. return "\"" + p_name.c_escape_multiline() + "\"";
  1233. }
  1234. }
  1235. // Keep as is
  1236. return p_name;
  1237. }
  1238. void EditorExportGodot3::_save_text(const String &p_path, ExportData &resource) {
  1239. FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
  1240. if (resource.nodes.size()) {
  1241. f->store_line("[gd_scene load_steps=" + itos(resource.nodes.size() + resource.resources.size()) + " format=2]\n");
  1242. } else {
  1243. f->store_line("[gd_resource type=\"" + resource.resources[resource.resources.size() - 1].type + "\" load_steps=" + itos(resource.resources.size()) + " format=2]\n");
  1244. }
  1245. for (Map<int, ExportData::Dependency>::Element *E = resource.dependencies.front(); E; E = E->next()) {
  1246. f->store_line("[ext_resource path=\"" + resource_replace_map[E->get().path] + "\" type=\"" + E->get().type + "\" id=" + itos(E->key()) + "]");
  1247. }
  1248. for (int i = 0; i < resource.resources.size(); i++) {
  1249. if (resource.nodes.size() || i < resource.resources.size() - 1) {
  1250. f->store_line("\n[sub_resource type=\"" + resource.resources[i].type + "\" id=" + itos(resource.resources[i].index) + "]\n");
  1251. } else {
  1252. f->store_line("\n[resource]\n");
  1253. }
  1254. for (List<ExportData::PropertyData>::Element *E = resource.resources[i].properties.front(); E; E = E->next()) {
  1255. String prop;
  1256. _get_property_as_text(E->get().value, prop);
  1257. f->store_line(_valprop(E->get().name) + " = " + prop);
  1258. }
  1259. }
  1260. for (int i = 0; i < resource.nodes.size(); i++) {
  1261. String node_txt = "\n[node";
  1262. if (resource.nodes[i].name != String()) {
  1263. node_txt += " name=\"" + String(resource.nodes[i].name).c_escape() + "\"";
  1264. }
  1265. if (resource.nodes[i].owner != NodePath()) {
  1266. node_txt += " owner=\"" + String(resource.nodes[i].owner).c_escape() + "\"";
  1267. }
  1268. if (resource.nodes[i].type != String()) {
  1269. node_txt += " type=\"" + resource.nodes[i].type + "\"";
  1270. }
  1271. if (resource.nodes[i].parent != NodePath()) {
  1272. node_txt += " parent=\"" + String(resource.nodes[i].parent).c_escape() + "\"";
  1273. }
  1274. if (resource.nodes[i].instance != String()) {
  1275. String prop;
  1276. _get_property_as_text(resource.nodes[i].instance, prop);
  1277. node_txt += " instance=" + prop + "";
  1278. }
  1279. if (!resource.nodes[i].groups.empty()) {
  1280. node_txt += " groups=[\n";
  1281. for (int j = 0; j < resource.nodes[i].groups.size(); j++) {
  1282. node_txt += "\"" + resource.nodes[i].groups[j] + "\",\n";
  1283. }
  1284. node_txt += "]";
  1285. }
  1286. node_txt += "]\n";
  1287. f->store_line(node_txt);
  1288. for (List<ExportData::PropertyData>::Element *E = resource.nodes[i].properties.front(); E; E = E->next()) {
  1289. String prop;
  1290. _get_property_as_text(E->get().value, prop);
  1291. f->store_line(_valprop(E->get().name) + " = " + prop);
  1292. }
  1293. }
  1294. for (int i = 0; i < resource.connections.size(); i++) {
  1295. String binds_array;
  1296. _get_property_as_text(resource.connections[i].binds, binds_array);
  1297. 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 + "]");
  1298. }
  1299. for (int i = 0; i < resource.editables.size(); i++) {
  1300. f->store_line("[editable path=\"" + String(resource.editables[i]).c_escape() + "\"]");
  1301. }
  1302. }
  1303. enum {
  1304. //numbering must be different from variant, in case new variant types are added (variant must be always contiguous for jumptable optimization)
  1305. VARIANT_NIL = 1,
  1306. VARIANT_BOOL = 2,
  1307. VARIANT_INT = 3,
  1308. VARIANT_REAL = 4,
  1309. VARIANT_STRING = 5,
  1310. VARIANT_VECTOR2 = 10,
  1311. VARIANT_RECT2 = 11,
  1312. VARIANT_VECTOR3 = 12,
  1313. VARIANT_PLANE = 13,
  1314. VARIANT_QUAT = 14,
  1315. VARIANT_AABB = 15,
  1316. VARIANT_MATRIX3 = 16,
  1317. VARIANT_TRANSFORM = 17,
  1318. VARIANT_MATRIX32 = 18,
  1319. VARIANT_COLOR = 20,
  1320. VARIANT_IMAGE = 21,
  1321. VARIANT_NODE_PATH = 22,
  1322. VARIANT_RID = 23,
  1323. VARIANT_OBJECT = 24,
  1324. VARIANT_INPUT_EVENT = 25,
  1325. VARIANT_DICTIONARY = 26,
  1326. VARIANT_ARRAY = 30,
  1327. VARIANT_RAW_ARRAY = 31,
  1328. VARIANT_INT_ARRAY = 32,
  1329. VARIANT_REAL_ARRAY = 33,
  1330. VARIANT_STRING_ARRAY = 34,
  1331. VARIANT_VECTOR3_ARRAY = 35,
  1332. VARIANT_COLOR_ARRAY = 36,
  1333. VARIANT_VECTOR2_ARRAY = 37,
  1334. VARIANT_INT64 = 40,
  1335. VARIANT_DOUBLE = 41,
  1336. IMAGE_ENCODING_EMPTY = 0,
  1337. IMAGE_ENCODING_RAW = 1,
  1338. IMAGE_ENCODING_LOSSLESS = 2,
  1339. IMAGE_ENCODING_LOSSY = 3,
  1340. OBJECT_EMPTY = 0,
  1341. OBJECT_EXTERNAL_RESOURCE = 1,
  1342. OBJECT_INTERNAL_RESOURCE = 2,
  1343. OBJECT_EXTERNAL_RESOURCE_INDEX = 3,
  1344. //version 2: added 64 bits support for float and int
  1345. FORMAT_VERSION = 2,
  1346. FORMAT_VERSION_CAN_RENAME_DEPS = 1
  1347. };
  1348. enum {
  1349. IMAGE_FORMAT_L8, //luminance
  1350. IMAGE_FORMAT_LA8, //luminance-alpha
  1351. IMAGE_FORMAT_R8,
  1352. IMAGE_FORMAT_RG8,
  1353. IMAGE_FORMAT_RGB8,
  1354. IMAGE_FORMAT_RGBA8,
  1355. IMAGE_FORMAT_RGB565, //16 bit
  1356. IMAGE_FORMAT_RGBA4444,
  1357. IMAGE_FORMAT_RGBA5551,
  1358. IMAGE_FORMAT_RF, //float
  1359. IMAGE_FORMAT_RGF,
  1360. IMAGE_FORMAT_RGBF,
  1361. IMAGE_FORMAT_RGBAF,
  1362. IMAGE_FORMAT_RH, //half float
  1363. IMAGE_FORMAT_RGH,
  1364. IMAGE_FORMAT_RGBH,
  1365. IMAGE_FORMAT_RGBAH,
  1366. IMAGE_FORMAT_DXT1, //s3tc bc1
  1367. IMAGE_FORMAT_DXT3, //bc2
  1368. IMAGE_FORMAT_DXT5, //bc3
  1369. IMAGE_FORMAT_ATI1, //bc4
  1370. IMAGE_FORMAT_ATI2, //bc5
  1371. IMAGE_FORMAT_BPTC_RGBA, //btpc bc6h
  1372. IMAGE_FORMAT_BPTC_RGBF, //float /
  1373. IMAGE_FORMAT_BPTC_RGBFU, //unsigned float
  1374. IMAGE_FORMAT_PVRTC2, //pvrtc
  1375. IMAGE_FORMAT_PVRTC2A,
  1376. IMAGE_FORMAT_PVRTC4,
  1377. IMAGE_FORMAT_PVRTC4A,
  1378. IMAGE_FORMAT_ETC, //etc1
  1379. IMAGE_FORMAT_ETC2_R11, //etc2
  1380. IMAGE_FORMAT_ETC2_R11S, //signed, NOT srgb.
  1381. IMAGE_FORMAT_ETC2_RG11,
  1382. IMAGE_FORMAT_ETC2_RG11S,
  1383. IMAGE_FORMAT_ETC2_RGB8,
  1384. IMAGE_FORMAT_ETC2_RGBA8,
  1385. IMAGE_FORMAT_ETC2_RGB8A1,
  1386. };
  1387. static void _pad_buffer(int p_bytes, FileAccess *f) {
  1388. int extra = 4 - (p_bytes % 4);
  1389. if (extra < 4) {
  1390. for (int i = 0; i < extra; i++)
  1391. f->store_8(0); //pad to 32
  1392. }
  1393. }
  1394. static void save_unicode_string(const String &p_string, FileAccess *f, bool p_hi_bit = false) {
  1395. CharString utf8 = p_string.utf8();
  1396. f->store_32(uint32_t(utf8.length() + 1) | (p_hi_bit ? 0x80000000 : 0));
  1397. f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1);
  1398. }
  1399. void EditorExportGodot3::_save_binary_property(const Variant &p_property, FileAccess *f) {
  1400. switch (p_property.get_type()) {
  1401. case Variant::NIL: {
  1402. f->store_32(VARIANT_NIL);
  1403. // don't store anything
  1404. } break;
  1405. case Variant::BOOL: {
  1406. f->store_32(VARIANT_BOOL);
  1407. bool val = p_property;
  1408. f->store_32(val);
  1409. } break;
  1410. case Variant::INT: {
  1411. f->store_32(VARIANT_INT);
  1412. int val = p_property;
  1413. f->store_32(int32_t(val));
  1414. } break;
  1415. case Variant::REAL: {
  1416. f->store_32(VARIANT_REAL);
  1417. f->store_real(p_property);
  1418. } break;
  1419. case Variant::STRING: {
  1420. String str = p_property;
  1421. if (str.begins_with("@RESLOCAL:")) {
  1422. f->store_32(VARIANT_OBJECT);
  1423. f->store_32(OBJECT_INTERNAL_RESOURCE);
  1424. f->store_32(str.get_slice(":", 1).to_int());
  1425. } else if (str.begins_with("@RESEXTERNAL:")) {
  1426. f->store_32(VARIANT_OBJECT);
  1427. f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX);
  1428. f->store_32(str.get_slice(":", 1).to_int());
  1429. } else {
  1430. f->store_32(VARIANT_STRING);
  1431. save_unicode_string(str, f);
  1432. }
  1433. } break;
  1434. case Variant::VECTOR2: {
  1435. f->store_32(VARIANT_VECTOR2);
  1436. Vector2 val = p_property;
  1437. f->store_real(val.x);
  1438. f->store_real(val.y);
  1439. } break;
  1440. case Variant::RECT2: {
  1441. f->store_32(VARIANT_RECT2);
  1442. Rect2 val = p_property;
  1443. f->store_real(val.pos.x);
  1444. f->store_real(val.pos.y);
  1445. f->store_real(val.size.x);
  1446. f->store_real(val.size.y);
  1447. } break;
  1448. case Variant::VECTOR3: {
  1449. f->store_32(VARIANT_VECTOR3);
  1450. Vector3 val = p_property;
  1451. f->store_real(val.x);
  1452. f->store_real(val.y);
  1453. f->store_real(val.z);
  1454. } break;
  1455. case Variant::PLANE: {
  1456. f->store_32(VARIANT_PLANE);
  1457. Plane val = p_property;
  1458. f->store_real(val.normal.x);
  1459. f->store_real(val.normal.y);
  1460. f->store_real(val.normal.z);
  1461. f->store_real(val.d);
  1462. } break;
  1463. case Variant::QUAT: {
  1464. f->store_32(VARIANT_QUAT);
  1465. Quat val = p_property;
  1466. f->store_real(val.x);
  1467. f->store_real(val.y);
  1468. f->store_real(val.z);
  1469. f->store_real(val.w);
  1470. } break;
  1471. case Variant::_AABB: {
  1472. f->store_32(VARIANT_AABB);
  1473. Rect3 val = p_property;
  1474. f->store_real(val.pos.x);
  1475. f->store_real(val.pos.y);
  1476. f->store_real(val.pos.z);
  1477. f->store_real(val.size.x);
  1478. f->store_real(val.size.y);
  1479. f->store_real(val.size.z);
  1480. } break;
  1481. case Variant::MATRIX32: {
  1482. f->store_32(VARIANT_MATRIX32);
  1483. Matrix32 val = p_property;
  1484. f->store_real(val.elements[0].x);
  1485. f->store_real(val.elements[0].y);
  1486. f->store_real(val.elements[1].x);
  1487. f->store_real(val.elements[1].y);
  1488. f->store_real(val.elements[2].x);
  1489. f->store_real(val.elements[2].y);
  1490. } break;
  1491. case Variant::MATRIX3: {
  1492. f->store_32(VARIANT_MATRIX3);
  1493. Matrix3 val = p_property;
  1494. f->store_real(val.elements[0].x);
  1495. f->store_real(val.elements[0].y);
  1496. f->store_real(val.elements[0].z);
  1497. f->store_real(val.elements[1].x);
  1498. f->store_real(val.elements[1].y);
  1499. f->store_real(val.elements[1].z);
  1500. f->store_real(val.elements[2].x);
  1501. f->store_real(val.elements[2].y);
  1502. f->store_real(val.elements[2].z);
  1503. } break;
  1504. case Variant::TRANSFORM: {
  1505. f->store_32(VARIANT_TRANSFORM);
  1506. Transform val = p_property;
  1507. f->store_real(val.basis.elements[0].x);
  1508. f->store_real(val.basis.elements[0].y);
  1509. f->store_real(val.basis.elements[0].z);
  1510. f->store_real(val.basis.elements[1].x);
  1511. f->store_real(val.basis.elements[1].y);
  1512. f->store_real(val.basis.elements[1].z);
  1513. f->store_real(val.basis.elements[2].x);
  1514. f->store_real(val.basis.elements[2].y);
  1515. f->store_real(val.basis.elements[2].z);
  1516. f->store_real(val.origin.x);
  1517. f->store_real(val.origin.y);
  1518. f->store_real(val.origin.z);
  1519. } break;
  1520. case Variant::COLOR: {
  1521. f->store_32(VARIANT_COLOR);
  1522. Color val = p_property;
  1523. f->store_real(val.r);
  1524. f->store_real(val.g);
  1525. f->store_real(val.b);
  1526. f->store_real(val.a);
  1527. } break;
  1528. case Variant::IMAGE: {
  1529. f->store_32(VARIANT_IMAGE);
  1530. Image val = p_property;
  1531. if (val.empty()) {
  1532. f->store_32(IMAGE_ENCODING_EMPTY);
  1533. break;
  1534. }
  1535. f->store_32(IMAGE_ENCODING_RAW);
  1536. f->store_32(val.get_width());
  1537. f->store_32(val.get_height());
  1538. f->store_32(val.get_mipmaps() ? 1 : 0);
  1539. switch (val.get_format()) {
  1540. case Image::FORMAT_GRAYSCALE:
  1541. f->store_32(IMAGE_FORMAT_L8);
  1542. break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
  1543. case Image::FORMAT_INTENSITY:
  1544. f->store_32(IMAGE_FORMAT_L8);
  1545. break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
  1546. case Image::FORMAT_GRAYSCALE_ALPHA:
  1547. f->store_32(IMAGE_FORMAT_LA8);
  1548. break; ///< two bytes per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255. alpha 0-255
  1549. case Image::FORMAT_RGB:
  1550. f->store_32(IMAGE_FORMAT_RGB8);
  1551. break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B
  1552. case Image::FORMAT_RGBA:
  1553. f->store_32(IMAGE_FORMAT_RGBA8);
  1554. 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
  1555. case Image::FORMAT_BC1:
  1556. f->store_32(IMAGE_FORMAT_DXT1);
  1557. break; // DXT1
  1558. case Image::FORMAT_BC2:
  1559. f->store_32(IMAGE_FORMAT_DXT3);
  1560. break; // DXT3
  1561. case Image::FORMAT_BC3:
  1562. f->store_32(IMAGE_FORMAT_DXT5);
  1563. break; // DXT5
  1564. case Image::FORMAT_BC4:
  1565. f->store_32(IMAGE_FORMAT_ATI1);
  1566. break; // ATI1
  1567. case Image::FORMAT_BC5:
  1568. f->store_32(IMAGE_FORMAT_ATI2);
  1569. break; // ATI2
  1570. case Image::FORMAT_PVRTC2: f->store_32(IMAGE_FORMAT_PVRTC2); break;
  1571. case Image::FORMAT_PVRTC2_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC2A); break;
  1572. case Image::FORMAT_PVRTC4: f->store_32(IMAGE_FORMAT_PVRTC4); break;
  1573. case Image::FORMAT_PVRTC4_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC4A); break;
  1574. case Image::FORMAT_ETC:
  1575. f->store_32(IMAGE_FORMAT_ETC);
  1576. break; // regular ETC: f->store_32(IMAGE_FORMAT_ ); break; no transparency
  1577. default: f->store_32(IMAGE_FORMAT_L8); break;
  1578. }
  1579. int dlen = val.get_data().size();
  1580. f->store_32(dlen);
  1581. DVector<uint8_t>::Read r = val.get_data().read();
  1582. f->store_buffer(r.ptr(), dlen);
  1583. _pad_buffer(dlen, f);
  1584. } break;
  1585. case Variant::NODE_PATH: {
  1586. f->store_32(VARIANT_NODE_PATH);
  1587. NodePath np = p_property;
  1588. f->store_16(np.get_name_count());
  1589. uint16_t snc = np.get_subname_count();
  1590. if (np.is_absolute())
  1591. snc |= 0x8000;
  1592. f->store_16(snc);
  1593. for (int i = 0; i < np.get_name_count(); i++) {
  1594. save_unicode_string(np.get_name(i), f, true);
  1595. }
  1596. for (int i = 0; i < np.get_subname_count(); i++) {
  1597. save_unicode_string(np.get_subname(i), f, true);
  1598. }
  1599. save_unicode_string(np.get_property(), f, true);
  1600. } break;
  1601. case Variant::_RID: {
  1602. f->store_32(VARIANT_RID);
  1603. WARN_PRINT("Can't save RIDs");
  1604. RID val = p_property;
  1605. f->store_32(val.get_id());
  1606. } break;
  1607. case Variant::OBJECT: {
  1608. ERR_FAIL();
  1609. } break;
  1610. case Variant::INPUT_EVENT: {
  1611. f->store_32(VARIANT_INPUT_EVENT);
  1612. //InputEvent event = p_property;
  1613. f->store_32(0); //event type none, nothing else supported for now.
  1614. } break;
  1615. case Variant::DICTIONARY: {
  1616. f->store_32(VARIANT_DICTIONARY);
  1617. Dictionary d = p_property;
  1618. f->store_32(uint32_t(d.size()));
  1619. List<Variant> keys;
  1620. d.get_key_list(&keys);
  1621. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  1622. /*
  1623. if (!_check_type(dict[E->get()]))
  1624. continue;
  1625. */
  1626. _save_binary_property(E->get(), f);
  1627. _save_binary_property(d[E->get()], f);
  1628. }
  1629. } break;
  1630. case Variant::ARRAY: {
  1631. f->store_32(VARIANT_ARRAY);
  1632. Array a = p_property;
  1633. f->store_32(uint32_t(a.size()));
  1634. for (int i = 0; i < a.size(); i++) {
  1635. _save_binary_property(a[i], f);
  1636. }
  1637. } break;
  1638. case Variant::RAW_ARRAY: {
  1639. f->store_32(VARIANT_RAW_ARRAY);
  1640. DVector<uint8_t> arr = p_property;
  1641. int len = arr.size();
  1642. f->store_32(len);
  1643. DVector<uint8_t>::Read r = arr.read();
  1644. f->store_buffer(r.ptr(), len);
  1645. _pad_buffer(len, f);
  1646. } break;
  1647. case Variant::INT_ARRAY: {
  1648. f->store_32(VARIANT_INT_ARRAY);
  1649. DVector<int> arr = p_property;
  1650. int len = arr.size();
  1651. f->store_32(len);
  1652. DVector<int>::Read r = arr.read();
  1653. for (int i = 0; i < len; i++)
  1654. f->store_32(r[i]);
  1655. } break;
  1656. case Variant::REAL_ARRAY: {
  1657. f->store_32(VARIANT_REAL_ARRAY);
  1658. DVector<real_t> arr = p_property;
  1659. int len = arr.size();
  1660. f->store_32(len);
  1661. DVector<real_t>::Read r = arr.read();
  1662. for (int i = 0; i < len; i++) {
  1663. f->store_real(r[i]);
  1664. }
  1665. } break;
  1666. case Variant::STRING_ARRAY: {
  1667. f->store_32(VARIANT_STRING_ARRAY);
  1668. DVector<String> arr = p_property;
  1669. int len = arr.size();
  1670. f->store_32(len);
  1671. DVector<String>::Read r = arr.read();
  1672. for (int i = 0; i < len; i++) {
  1673. save_unicode_string(r[i], f);
  1674. }
  1675. } break;
  1676. case Variant::VECTOR3_ARRAY: {
  1677. f->store_32(VARIANT_VECTOR3_ARRAY);
  1678. DVector<Vector3> arr = p_property;
  1679. int len = arr.size();
  1680. f->store_32(len);
  1681. DVector<Vector3>::Read r = arr.read();
  1682. for (int i = 0; i < len; i++) {
  1683. f->store_real(r[i].x);
  1684. f->store_real(r[i].y);
  1685. f->store_real(r[i].z);
  1686. }
  1687. } break;
  1688. case Variant::VECTOR2_ARRAY: {
  1689. f->store_32(VARIANT_VECTOR2_ARRAY);
  1690. DVector<Vector2> arr = p_property;
  1691. int len = arr.size();
  1692. f->store_32(len);
  1693. DVector<Vector2>::Read r = arr.read();
  1694. for (int i = 0; i < len; i++) {
  1695. f->store_real(r[i].x);
  1696. f->store_real(r[i].y);
  1697. }
  1698. } break;
  1699. case Variant::COLOR_ARRAY: {
  1700. f->store_32(VARIANT_COLOR_ARRAY);
  1701. DVector<Color> arr = p_property;
  1702. int len = arr.size();
  1703. f->store_32(len);
  1704. DVector<Color>::Read r = arr.read();
  1705. for (int i = 0; i < len; i++) {
  1706. f->store_real(r[i].r);
  1707. f->store_real(r[i].g);
  1708. f->store_real(r[i].b);
  1709. f->store_real(r[i].a);
  1710. }
  1711. } break;
  1712. default: {
  1713. ERR_EXPLAIN("Invalid variant");
  1714. ERR_FAIL();
  1715. }
  1716. }
  1717. }
  1718. void EditorExportGodot3::_save_binary(const String &p_path, ExportData &resource) {
  1719. FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
  1720. ERR_FAIL_COND(!f.operator->());
  1721. //save header compressed
  1722. static const uint8_t header[4] = { 'R', 'S', 'R', 'C' };
  1723. f->store_buffer(header, 4);
  1724. f->store_32(0);
  1725. f->store_32(0); //64 bits file, false for now
  1726. f->store_32(3); //major
  1727. f->store_32(0); //minor
  1728. f->store_32(2); //format version (2 is for 3.0)
  1729. //f->store_32(saved_resources.size()+external_resources.size()); // load steps -not needed
  1730. save_unicode_string(resource.resources[resource.resources.size() - 1].type, f.operator->());
  1731. for (int i = 0; i < 16; i++)
  1732. f->store_32(0); // unused
  1733. f->store_32(0); //no names saved
  1734. f->store_32(resource.dependencies.size()); //amount of external resources
  1735. for (Map<int, ExportData::Dependency>::Element *E = resource.dependencies.front(); E; E = E->next()) {
  1736. save_unicode_string(E->get().type, f.operator->());
  1737. save_unicode_string(resource_replace_map[E->get().path], f.operator->());
  1738. }
  1739. // save internal resource table
  1740. Vector<uint64_t> ofs_pos;
  1741. f->store_32(resource.resources.size()); //amount of internal resources
  1742. for (int i = 0; i < resource.resources.size(); i++) {
  1743. save_unicode_string("local://" + itos(resource.resources[i].index), f.operator->());
  1744. ofs_pos.push_back(f->get_pos());
  1745. f->store_64(0);
  1746. }
  1747. Vector<uint64_t> ofs_table;
  1748. // int saved_idx=0;
  1749. //now actually save the resources
  1750. for (int i = 0; i < resource.resources.size(); i++) {
  1751. ofs_table.push_back(f->get_pos());
  1752. save_unicode_string(resource.resources[i].type, f.operator->());
  1753. f->store_32(resource.resources[i].properties.size());
  1754. for (List<ExportData::PropertyData>::Element *E = resource.resources[i].properties.front(); E; E = E->next()) {
  1755. save_unicode_string(E->get().name, f.operator->(), true);
  1756. _save_binary_property(E->get().value, f.operator->());
  1757. }
  1758. }
  1759. for (int i = 0; i < ofs_table.size(); i++) {
  1760. f->seek(ofs_pos[i]);
  1761. f->store_64(ofs_table[i]);
  1762. }
  1763. f->seek_end();
  1764. f->store_buffer((const uint8_t *)"RSRC", 4); //magic at end
  1765. ERR_FAIL_COND(f->get_error() != OK);
  1766. }
  1767. void EditorExportGodot3::_save_config(const String &p_path) {
  1768. // Parse existing config, convert persisting properties and store in ConfigFile
  1769. ConfigFile new_cfg = ConfigFile();
  1770. List<PropertyInfo> props;
  1771. Globals::get_singleton()->get_property_list(&props);
  1772. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  1773. if (!Globals::get_singleton()->has(E->get().name))
  1774. continue;
  1775. if (Globals::get_singleton()->is_persisting(E->get().name)) {
  1776. String newname;
  1777. if (globals_rename_map.has(E->get().name)) {
  1778. newname = globals_rename_map[E->get().name];
  1779. } else {
  1780. newname = E->get().name;
  1781. }
  1782. int sep = newname.find("/");
  1783. String section = newname.substr(0, sep);
  1784. String subname = newname.substr(sep + 1, newname.length());
  1785. String value;
  1786. _get_property_as_text(Globals::get_singleton()->get(E->get().name), value);
  1787. new_cfg.set_value(section, subname, value);
  1788. }
  1789. }
  1790. String str = "{\n\"flags/filter\": " + String(GLOBAL_DEF("image_loader/filter", true) ? "true" : "false");
  1791. str += ",\n\"flags/mipmaps\": " + String(GLOBAL_DEF("image_loader/gen_mipmaps", true) ? "true" : "false");
  1792. str += "\n}";
  1793. new_cfg.set_value("importer_defaults", "texture", str);
  1794. // Write the collected ConfigFile manually - we need to use _get_property_as_text()
  1795. // above, so we can't rely on ConfigFile.save() to properly store the raw strings.
  1796. FileAccessRef f = FileAccess::open(p_path.plus_file("project.godot"), FileAccess::WRITE);
  1797. List<String> sections;
  1798. new_cfg.get_sections(&sections);
  1799. for (List<String>::Element *E = sections.front(); E; E = E->next()) {
  1800. f->store_line("[" + E->get() + "]\n");
  1801. List<String> keys;
  1802. new_cfg.get_section_keys(E->get(), &keys);
  1803. for (List<String>::Element *F = keys.front(); F; F = F->next()) {
  1804. f->store_line(F->get() + " = " + new_cfg.get_value(E->get(), F->get()));
  1805. }
  1806. f->store_line("");
  1807. }
  1808. f->close();
  1809. }
  1810. Error EditorExportGodot3::_convert_script(const String &p_path, const String &p_target_path, bool mark_converted_lines) {
  1811. FileAccessRef src = FileAccess::open(p_path, FileAccess::READ);
  1812. ERR_FAIL_COND_V(!src.operator->(), FAILED);
  1813. FileAccessRef dst = FileAccess::open(p_target_path, FileAccess::WRITE);
  1814. ERR_FAIL_COND_V(!dst.operator->(), FAILED);
  1815. String http_var = "";
  1816. const String note = " #-- NOTE: Automatically converted by Godot 2 to 3 converter, please review";
  1817. while (!src->eof_reached()) {
  1818. String line = src->get_line();
  1819. String origline = line;
  1820. // Convert _fixed_process( => _physics_process(
  1821. RegEx regexp("(.*)_fixed_process\\((.*)");
  1822. int res = regexp.find(line);
  1823. if (res >= 0 && regexp.get_capture_count() == 3) {
  1824. line = regexp.get_capture(1) + "_physics_process(" + regexp.get_capture(2);
  1825. }
  1826. regexp.clear();
  1827. // Convert _input_event( => _gui_input(
  1828. regexp.compile("(.*)_input_event\\((.*)");
  1829. res = regexp.find(line);
  1830. if (res >= 0 && regexp.get_capture_count() == 3) {
  1831. line = regexp.get_capture(1) + "_gui_input(" + regexp.get_capture(2);
  1832. }
  1833. regexp.clear();
  1834. // Try to detect a HTTPClient object
  1835. regexp.compile("[ \t]*([a-zA-Z0-9_]*)[ ]*=[ ]*HTTPClient\\.new\\(\\)");
  1836. res = regexp.find(line);
  1837. if (res >= 0 && regexp.get_capture_count() == 2) {
  1838. http_var = regexp.get_capture(1).strip_edges();
  1839. }
  1840. regexp.clear();
  1841. if (http_var != "") {
  1842. // Convert .connect( => .connect_to_host(
  1843. regexp.compile("(.*)" + http_var + "\\.connect\\((.*)");
  1844. res = regexp.find(line);
  1845. if (res >= 0 && regexp.get_capture_count() == 3) {
  1846. line = regexp.get_capture(1) + http_var + ".connect_to_host(" + regexp.get_capture(2);
  1847. }
  1848. regexp.clear();
  1849. }
  1850. // The following replacements may be needed more than once per line, hence the loop
  1851. int count;
  1852. int tries = 0;
  1853. do {
  1854. count = 0;
  1855. // Convert all types to fix instances of renamed Nodes, or renamed core types (Pool*Array, Basis, etc.)
  1856. for (Map<String, String>::Element *E = type_rename_map.front(); E; E = E->next()) {
  1857. //regexp.compile("(.*[^a-zA-Z0-9_])" + E->key() + "([^a-zA-Z0-9_].*)");
  1858. regexp.compile("(.*\\b)" + E->key() + "(\\b.*)");
  1859. res = regexp.find(line);
  1860. if (res >= 0 && regexp.get_capture_count() == 3) {
  1861. line = regexp.get_capture(1) + E->get() + regexp.get_capture(2);
  1862. count++;
  1863. }
  1864. regexp.clear();
  1865. }
  1866. // Convert _pos( => _position(
  1867. regexp.compile("(.*)_pos\\((.*)");
  1868. res = regexp.find(line);
  1869. if (res >= 0 && regexp.get_capture_count() == 3) {
  1870. line = regexp.get_capture(1) + "_position(" + regexp.get_capture(2);
  1871. count++;
  1872. }
  1873. regexp.clear();
  1874. // Convert .pos => .position
  1875. regexp.compile("(.*)\\.pos([^a-zA-Z0-9_-].*)");
  1876. res = regexp.find(line);
  1877. if (res >= 0 && regexp.get_capture_count() == 3) {
  1878. line = regexp.get_capture(1) + ".position" + regexp.get_capture(2);
  1879. count++;
  1880. }
  1881. regexp.clear();
  1882. // Convert _rot( => _rotation(
  1883. regexp.compile("(.*)_rot\\((.*)");
  1884. res = regexp.find(line);
  1885. if (res >= 0 && regexp.get_capture_count() == 3) {
  1886. line = regexp.get_capture(1) + "_rotation(" + regexp.get_capture(2);
  1887. count++;
  1888. }
  1889. regexp.clear();
  1890. // Convert _speed( => _speed_scale(
  1891. regexp.compile("(.*)_speed\\((.*)");
  1892. res = regexp.find(line);
  1893. if (res >= 0 && regexp.get_capture_count() == 3) {
  1894. line = regexp.get_capture(1) + "_speed_scale(" + regexp.get_capture(2);
  1895. count++;
  1896. }
  1897. regexp.clear();
  1898. // Convert KEY_RETURN => KEY_ENTER
  1899. regexp.compile("(.*)KEY_RETURN(.*)");
  1900. res = regexp.find(line);
  1901. if (res >= 0 && regexp.get_capture_count() == 3) {
  1902. line = regexp.get_capture(1) + "KEY_ENTER" + regexp.get_capture(2);
  1903. count++;
  1904. }
  1905. regexp.clear();
  1906. // Convert get_opacity() => modulate.a
  1907. regexp.compile("(.*)get_opacity\\(\\)(.*)");
  1908. res = regexp.find(line);
  1909. if (res >= 0 && regexp.get_capture_count() == 3) {
  1910. line = regexp.get_capture(1) + "modulate.a" + regexp.get_capture(2);
  1911. count++;
  1912. }
  1913. regexp.clear();
  1914. // Convert set_opacity(var) => modulate.a = var
  1915. regexp.compile("(.*)set_opacity\\((.*)\\)(.*)");
  1916. res = regexp.find(line);
  1917. if (res >= 0 && regexp.get_capture_count() == 4) {
  1918. line = regexp.get_capture(1) + "modulate.a = " + regexp.get_capture(2) + regexp.get_capture(3);
  1919. count++;
  1920. }
  1921. regexp.clear();
  1922. // Convert get_self_opacity() => self_modulate.a
  1923. regexp.compile("(.*)get_self_opacity\\(\\)(.*)");
  1924. res = regexp.find(line);
  1925. if (res >= 0 && regexp.get_capture_count() == 3) {
  1926. line = regexp.get_capture(1) + "self_modulate.a" + regexp.get_capture(2);
  1927. count++;
  1928. }
  1929. regexp.clear();
  1930. // Convert set_self_opacity(var) => self_modulate.a = var
  1931. regexp.compile("(.*)set_self_opacity\\((.*)\\)(.*)");
  1932. res = regexp.find(line);
  1933. if (res >= 0 && regexp.get_capture_count() == 4) {
  1934. line = regexp.get_capture(1) + "self_modulate.a = " + regexp.get_capture(2) + regexp.get_capture(3);
  1935. count++;
  1936. }
  1937. regexp.clear();
  1938. // Convert set_hidden(var) => visible = !(var)
  1939. regexp.compile("(.*)set_hidden\\((.*)\\)(.*)");
  1940. res = regexp.find(line);
  1941. if (res >= 0 && regexp.get_capture_count() == 4) {
  1942. line = regexp.get_capture(1) + "visible = !(" + regexp.get_capture(2) + ")" + regexp.get_capture(3);
  1943. count++;
  1944. }
  1945. regexp.clear();
  1946. // Convert var.type == InputEvent.KEY => var is InputEventKey
  1947. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.KEY(.*)");
  1948. res = regexp.find(line);
  1949. if (res >= 0 && regexp.get_capture_count() == 3) {
  1950. line = regexp.get_capture(1) + " is InputEventKey" + regexp.get_capture(2);
  1951. count++;
  1952. }
  1953. regexp.clear();
  1954. // Convert var.type == InputEvent.MOUSE_MOTION => var is InputEventMouseMotion
  1955. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.MOUSE_MOTION(.*)");
  1956. res = regexp.find(line);
  1957. if (res >= 0 && regexp.get_capture_count() == 3) {
  1958. line = regexp.get_capture(1) + " is InputEventMouseMotion" + regexp.get_capture(2);
  1959. count++;
  1960. }
  1961. regexp.clear();
  1962. // Convert var.type == InputEvent.MOUSE_BUTTON => var is InputEventMouseButton
  1963. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.MOUSE_BUTTON(.*)");
  1964. res = regexp.find(line);
  1965. if (res >= 0 && regexp.get_capture_count() == 3) {
  1966. line = regexp.get_capture(1) + " is InputEventMouseButton" + regexp.get_capture(2);
  1967. count++;
  1968. }
  1969. regexp.clear();
  1970. // Convert var.type == InputEvent.JOYSTICK_MOTION => var is InputEventJoypadMotion
  1971. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.JOYSTICK_MOTION(.*)");
  1972. res = regexp.find(line);
  1973. if (res >= 0 && regexp.get_capture_count() == 3) {
  1974. line = regexp.get_capture(1) + " is InputEventJoypadMotion" + regexp.get_capture(2);
  1975. count++;
  1976. }
  1977. regexp.clear();
  1978. // Convert var.type == InputEvent.JOYSTICK_BUTTON => var is InputEventJoypadButton
  1979. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.JOYSTICK_BUTTON(.*)");
  1980. res = regexp.find(line);
  1981. if (res >= 0 && regexp.get_capture_count() == 3) {
  1982. line = regexp.get_capture(1) + " is InputEventJoypadButton" + regexp.get_capture(2);
  1983. count++;
  1984. }
  1985. regexp.clear();
  1986. // Convert var.type == InputEvent.SCREEN_TOUCH => var is InputEventScreenTouch
  1987. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.SCREEN_TOUCH(.*)");
  1988. res = regexp.find(line);
  1989. if (res >= 0 && regexp.get_capture_count() == 3) {
  1990. line = regexp.get_capture(1) + " is InputEventScreenTouch" + regexp.get_capture(2);
  1991. count++;
  1992. }
  1993. regexp.clear();
  1994. // Convert var.type == InputEvent.SCREEN_DRAG => var is InputEventScreenDrag
  1995. regexp.compile("(.*)\\.type[ ]*==[ ]*InputEvent.SCREEN_DRAG(.*)");
  1996. res = regexp.find(line);
  1997. if (res >= 0 && regexp.get_capture_count() == 3) {
  1998. line = regexp.get_capture(1) + " is InputEventScreenDrag" + regexp.get_capture(2);
  1999. count++;
  2000. }
  2001. regexp.clear();
  2002. // Convert move( => move_and_collide(
  2003. regexp.compile("(.*)move\\((.*)");
  2004. res = regexp.find(line);
  2005. if (res >= 0 && regexp.get_capture_count() == 3) {
  2006. line = regexp.get_capture(1) + "move_and_collide(" + regexp.get_capture(2);
  2007. count++;
  2008. }
  2009. regexp.clear();
  2010. // Convert is_move_and_slide_on_floor() => is_on_floor()
  2011. regexp.compile("(.*)is_move_and_slide_on_floor\\(\\)(.*)");
  2012. res = regexp.find(line);
  2013. if (res >= 0 && regexp.get_capture_count() == 3) {
  2014. line = regexp.get_capture(1) + "is_on_floor()" + regexp.get_capture(2);
  2015. count++;
  2016. }
  2017. regexp.clear();
  2018. // Convert is_move_and_slide_on_ceiling() => is_on_ceiling()
  2019. regexp.compile("(.*)is_move_and_slide_on_ceiling\\(\\)(.*)");
  2020. res = regexp.find(line);
  2021. if (res >= 0 && regexp.get_capture_count() == 3) {
  2022. line = regexp.get_capture(1) + "is_on_ceiling()" + regexp.get_capture(2);
  2023. count++;
  2024. }
  2025. regexp.clear();
  2026. // Convert is_move_and_slide_on_wall() => is_on_wall()
  2027. regexp.compile("(.*)is_move_and_slide_on_wall\\(\\)(.*)");
  2028. res = regexp.find(line);
  2029. if (res >= 0 && regexp.get_capture_count() == 3) {
  2030. line = regexp.get_capture(1) + "is_on_wall()" + regexp.get_capture(2);
  2031. count++;
  2032. }
  2033. regexp.clear();
  2034. // Convert <any chars but none> extends => <any chars but none> is
  2035. // The only case where we don't want to convert it is `^extends <Node>`
  2036. regexp.compile("(^.+ )extends(.*)");
  2037. res = regexp.find(line);
  2038. if (res >= 0 && regexp.get_capture_count() == 3) {
  2039. line = regexp.get_capture(1) + "is" + regexp.get_capture(2);
  2040. count++;
  2041. }
  2042. regexp.clear();
  2043. } while (count >= 1 && tries++ < 10);
  2044. if (mark_converted_lines && line != origline) {
  2045. // Add explanatory comment on the changed line
  2046. line += note;
  2047. }
  2048. dst->store_line(line);
  2049. }
  2050. return OK;
  2051. }
  2052. Error EditorExportGodot3::export_godot3(const String &p_path, bool convert_scripts, bool mark_converted_lines) {
  2053. List<String> files;
  2054. _find_files(EditorFileSystem::get_singleton()->get_filesystem(), &files);
  2055. EditorProgress progress("exporting", "Exporting the project to Godot 3.0", files.size());
  2056. //find XML resources
  2057. resource_replace_map.clear();
  2058. Set<String> xml_extensions;
  2059. Set<String> binary_extensions;
  2060. Set<String> text_extensions;
  2061. {
  2062. List<String> xml_exts;
  2063. ResourceFormatLoaderXML::singleton->get_recognized_extensions(&xml_exts);
  2064. for (List<String>::Element *E = xml_exts.front(); E; E = E->next()) {
  2065. xml_extensions.insert(E->get());
  2066. }
  2067. }
  2068. {
  2069. List<String> binary_exts;
  2070. ResourceFormatLoaderBinary::singleton->get_recognized_extensions(&binary_exts);
  2071. for (List<String>::Element *E = binary_exts.front(); E; E = E->next()) {
  2072. binary_extensions.insert(E->get());
  2073. }
  2074. }
  2075. {
  2076. List<String> text_exts;
  2077. ResourceFormatLoaderText::singleton->get_recognized_extensions(&text_exts);
  2078. for (List<String>::Element *E = text_exts.front(); E; E = E->next()) {
  2079. text_extensions.insert(E->get());
  2080. }
  2081. }
  2082. for (List<String>::Element *E = files.front(); E; E = E->next()) {
  2083. String file = E->get();
  2084. String file_local = file.replace("res://", "");
  2085. resource_replace_map[file] = file;
  2086. resource_replace_map[file_local] = file_local;
  2087. if (xml_extensions.has(file.extension().to_lower())) {
  2088. if (ResourceLoader::get_resource_type(file) == "PackedScene") {
  2089. resource_replace_map[file] = file.basename() + ".tscn";
  2090. resource_replace_map[file_local] = file_local.basename() + ".tscn";
  2091. } else {
  2092. resource_replace_map[file] = file.basename() + ".tres";
  2093. resource_replace_map[file_local] = file_local.basename() + ".tres";
  2094. }
  2095. }
  2096. // Changing all the old extensions to new Godot 3.0 extensions.
  2097. // Refer PR #9201
  2098. String extension = file.extension().to_lower();
  2099. if (extension == "anm") {
  2100. resource_replace_map[file] = file.basename() + ".anim";
  2101. resource_replace_map[file_local] = file_local.basename() + ".anim";
  2102. } else if (extension == "asogg") {
  2103. resource_replace_map[file] = file.basename() + ".oggstr";
  2104. resource_replace_map[file_local] = file_local.basename() + ".oggstr";
  2105. } else if (extension == "atex") {
  2106. resource_replace_map[file] = file.basename() + ".atlastex";
  2107. resource_replace_map[file_local] = file_local.basename() + ".atlastex";
  2108. } else if (extension == "cbm") {
  2109. resource_replace_map[file] = file.basename() + ".cubemap";
  2110. resource_replace_map[file_local] = file_local.basename() + ".cubemap";
  2111. } else if (extension == "cvtex") {
  2112. resource_replace_map[file] = file.basename() + ".curvetex";
  2113. resource_replace_map[file_local] = file_local.basename() + ".curvetex";
  2114. } else if (extension == "fnt") {
  2115. resource_replace_map[file] = file.basename() + ".font";
  2116. resource_replace_map[file_local] = file_local.basename() + ".font";
  2117. } else if (extension == "gt") {
  2118. resource_replace_map[file] = file.basename() + ".meshlib";
  2119. resource_replace_map[file_local] = file_local.basename() + ".meshlib";
  2120. } else if (extension == "ltex") {
  2121. resource_replace_map[file] = file.basename() + ".largetex";
  2122. resource_replace_map[file_local] = file_local.basename() + ".largetex";
  2123. } else if (extension == "mmsh") {
  2124. resource_replace_map[file] = file.basename() + ".multimesh";
  2125. resource_replace_map[file_local] = file_local.basename() + ".multimesh";
  2126. } else if (extension == "msh") {
  2127. resource_replace_map[file] = file.basename() + ".mesh";
  2128. resource_replace_map[file_local] = file_local.basename() + ".mesh";
  2129. } else if (extension == "mtl") {
  2130. resource_replace_map[file] = file.basename() + ".material";
  2131. resource_replace_map[file_local] = file_local.basename() + ".material";
  2132. } else if (extension == "sbx") {
  2133. resource_replace_map[file] = file.basename() + ".stylebox";
  2134. resource_replace_map[file_local] = file_local.basename() + ".stylebox";
  2135. } else if (extension == "sgp") {
  2136. resource_replace_map[file] = file.basename() + ".vshader";
  2137. resource_replace_map[file_local] = file_local.basename() + ".vshader";
  2138. } else if (extension == "shd") {
  2139. resource_replace_map[file] = file.basename() + ".shader";
  2140. resource_replace_map[file_local] = file_local.basename() + ".shader";
  2141. } else if (extension == "shp") {
  2142. resource_replace_map[file] = file.basename() + ".shape";
  2143. resource_replace_map[file_local] = file_local.basename() + ".shape";
  2144. } else if (extension == "smp") {
  2145. resource_replace_map[file] = file.basename() + ".sample";
  2146. resource_replace_map[file_local] = file_local.basename() + ".sample";
  2147. } else if (extension == "tex") {
  2148. resource_replace_map[file] = file.basename() + ".texture";
  2149. resource_replace_map[file_local] = file_local.basename() + ".texture";
  2150. } else if (extension == "thm") {
  2151. resource_replace_map[file] = file.basename() + ".theme";
  2152. resource_replace_map[file_local] = file_local.basename() + ".theme";
  2153. } else if (extension == "wrd") {
  2154. resource_replace_map[file] = file.basename() + ".world";
  2155. resource_replace_map[file_local] = file_local.basename() + ".world";
  2156. } else if (extension == "xl") {
  2157. resource_replace_map[file] = file.basename() + ".translation";
  2158. resource_replace_map[file_local] = file_local.basename() + ".translation";
  2159. }
  2160. }
  2161. DirAccess *directory = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2162. if (directory->change_dir(p_path) != OK) {
  2163. memdelete(directory);
  2164. ERR_FAIL_V(ERR_CANT_OPEN);
  2165. }
  2166. int idx = 0;
  2167. for (List<String>::Element *E = files.front(); E; E = E->next()) {
  2168. String path = E->get();
  2169. String extension = path.extension().to_lower();
  2170. String target_path;
  2171. bool repack = false;
  2172. target_path = p_path.plus_file(path.replace("res://", ""));
  2173. // Changing all the old extensions to new Godot 3.0 extensions.
  2174. // Refer PR #9201
  2175. if (extension == "fnt") {
  2176. target_path = target_path.basename() + ".font";
  2177. } else if (extension == "asogg") {
  2178. target_path = target_path.basename() + ".oggstr";
  2179. } else if (extension == "atex") {
  2180. target_path = target_path.basename() + ".atlastex";
  2181. } else if (extension == "cbm") {
  2182. target_path = target_path.basename() + ".cubemap";
  2183. } else if (extension == "cvtex") {
  2184. target_path = target_path.basename() + ".curvetex";
  2185. } else if (extension == "fnt") {
  2186. target_path = target_path.basename() + ".font";
  2187. } else if (extension == "gt") {
  2188. target_path = target_path.basename() + ".meshlib";
  2189. } else if (extension == "ltex") {
  2190. target_path = target_path.basename() + ".largetex";
  2191. } else if (extension == "mmsh") {
  2192. target_path = target_path.basename() + ".multimesh";
  2193. } else if (extension == "msh") {
  2194. target_path = target_path.basename() + ".mesh";
  2195. } else if (extension == "mtl") {
  2196. target_path = target_path.basename() + ".material";
  2197. } else if (extension == "sbx") {
  2198. target_path = target_path.basename() + ".stylebox";
  2199. } else if (extension == "sgp") {
  2200. target_path = target_path.basename() + ".vshader";
  2201. } else if (extension == "shd") {
  2202. target_path = target_path.basename() + ".shader";
  2203. } else if (extension == "shp") {
  2204. target_path = target_path.basename() + ".shape";
  2205. } else if (extension == "smp") {
  2206. target_path = target_path.basename() + ".sample";
  2207. } else if (extension == "tex") {
  2208. target_path = target_path.basename() + ".texture";
  2209. } else if (extension == "thm") {
  2210. target_path = target_path.basename() + ".theme";
  2211. } else if (extension == "wrd") {
  2212. target_path = target_path.basename() + ".world";
  2213. } else if (extension == "xl") {
  2214. target_path = target_path.basename() + ".translation";
  2215. }
  2216. progress.step(target_path.get_file(), idx++);
  2217. print_line("-- Exporting file: " + target_path);
  2218. if (directory->make_dir_recursive(target_path.get_base_dir()) != OK) {
  2219. memdelete(directory);
  2220. ERR_FAIL_V(ERR_CANT_CREATE);
  2221. }
  2222. ExportData resource_data;
  2223. Error err;
  2224. bool cont = false;
  2225. if (xml_extensions.has(extension)) {
  2226. err = ResourceLoader::get_export_data(path, resource_data);
  2227. } else if (text_extensions.has(extension)) {
  2228. err = ResourceLoader::get_export_data(path, resource_data);
  2229. } else if (binary_extensions.has(extension)) {
  2230. err = ResourceLoader::get_export_data(path, resource_data);
  2231. } else {
  2232. if (convert_scripts && extension == "gd") {
  2233. err = _convert_script(path, target_path, mark_converted_lines);
  2234. } else {
  2235. //single file, copy it
  2236. err = directory->copy(path, target_path);
  2237. }
  2238. cont = true; //no longer needed to do anything, just copied the file!
  2239. }
  2240. if (err != OK) {
  2241. memdelete(directory);
  2242. ERR_FAIL_V(err);
  2243. }
  2244. if (cont) {
  2245. continue;
  2246. }
  2247. if (resource_data.nodes.size() == 0 && resource_data.resources[resource_data.resources.size() - 1].type == "PackedScene") {
  2248. //must unpack a PackedScene
  2249. _unpack_packed_scene(resource_data);
  2250. repack = true;
  2251. }
  2252. _convert_resources(resource_data);
  2253. if (repack) {
  2254. _pack_packed_scene(resource_data);
  2255. }
  2256. if (xml_extensions.has(extension)) {
  2257. String save_path = resource_replace_map[target_path];
  2258. _save_text(save_path, resource_data);
  2259. } else if (text_extensions.has(extension)) {
  2260. _save_text(target_path, resource_data);
  2261. } else if (binary_extensions.has(extension)) {
  2262. _save_binary(target_path, resource_data);
  2263. }
  2264. }
  2265. memdelete(directory);
  2266. _save_config(p_path);
  2267. return OK;
  2268. }
  2269. EditorExportGodot3::EditorExportGodot3() {
  2270. int idx = 0;
  2271. while (globals_renames[idx][0] != NULL) {
  2272. globals_rename_map[globals_renames[idx][0]] = globals_renames[idx][1];
  2273. idx++;
  2274. }
  2275. idx = 0;
  2276. while (prop_renames[idx][0] != NULL) {
  2277. prop_rename_map[prop_renames[idx][0]] = prop_renames[idx][1];
  2278. idx++;
  2279. }
  2280. idx = 0;
  2281. while (type_renames[idx][0] != NULL) {
  2282. type_rename_map[type_renames[idx][0]] = type_renames[idx][1];
  2283. idx++;
  2284. }
  2285. idx = 0;
  2286. while (signal_renames[idx][0] != NULL) {
  2287. signal_rename_map[signal_renames[idx][0]] = signal_renames[idx][1];
  2288. idx++;
  2289. }
  2290. }