diff --git a/blender/addons/defender.zip b/blender/addons/defender.zip index d0c6864..1c4d7d1 100644 Binary files a/blender/addons/defender.zip and b/blender/addons/defender.zip differ diff --git a/blender/addons/defender/defoldsync/defoldCmds.py b/blender/addons/defender/defoldsync/defoldCmds.py index 4111197..9e1e891 100644 --- a/blender/addons/defender/defoldsync/defoldCmds.py +++ b/blender/addons/defender/defoldsync/defoldCmds.py @@ -117,13 +117,14 @@ def processDefoldProperties(obj, thisobj): defold_item["material_texture_defold"] = item.material_texture_defold if item.command == "Set Key/Value": - defold_item["keyval"] = { "key": item.store_key, "value": item.store_value } + val = (item.store_value).replace('"', '\\"') + defold_item["keyval"] = { "key": item.store_key, "value": val, "is_table": item.store_is_table } if item.command == "Init Script": - defold_item["scipt_init"] = item.command_init + defold_item["scipt_init"] = item.command_init.replace('"', '\\"') if item.command == "Update Script": - defold_item["scipt_update"] = item.command_update + defold_item["scipt_update"] = item.command_update.replace('"', '\\"') defold_props.append(defold_item) diff --git a/blender/addons/defender/defoldsync/defoldObjectProps.py b/blender/addons/defender/defoldsync/defoldObjectProps.py index 639b7fa..02cdf6c 100644 --- a/blender/addons/defender/defoldsync/defoldObjectProps.py +++ b/blender/addons/defender/defoldsync/defoldObjectProps.py @@ -123,6 +123,13 @@ class ListItem(PropertyGroup): default="value" ) + store_is_table: BoolProperty( + name="Is Table", + description="Is the value a table construction", + default=False + ) + + command_init: StringProperty( name="Script Init", description="A single lua script line to run on init", @@ -466,6 +473,8 @@ def draw(self, context): row.prop(item, "store_key") row = box.row() row.prop(item, "store_value") + row = box.row() + row.prop(item, "store_is_table") if item.command == "Init Script": row = box.row() diff --git a/blender/addons/defender/defoldsync/generator.lua b/blender/addons/defender/defoldsync/generator.lua index d9c127e..2b484a3 100644 --- a/blender/addons/defender/defoldsync/generator.lua +++ b/blender/addons/defender/defoldsync/generator.lua @@ -196,7 +196,6 @@ local gofiledata = [[ components { id: "MESH_GO_NAME" component: "MESH_FILE_PATH" - GO_DATA_FILE_COMPONENTS position { x: 0.0 y: 0.0 @@ -209,6 +208,7 @@ components { w: 1.0 } } +GO_FILE_COMPONENTS GO_COLLIDER_COMPONENT GO_FILE_SCRIPT ]] @@ -220,13 +220,21 @@ local gomodelmaterialtexture = [[ " texture: \"GO_MODEL_TEXTURE\"" ]] -local gomodelcomponentdata = [[ +local gomodelcomponentembedded = [[ "components {\n" " id: \"GO_COMPONENT_ID\"\n" " component: \"GO_COMPONENT_PATH\"\n" -"}\n" + "}\n" ]] +local gomodelcomponentfile = [[ + components { + id: "GO_COMPONENT_ID" + component: "GO_COMPONENT_PATH" + } +]] + + local gomodelfiledata = { -- Initial version. Will provide a way to set this on the exporter if needed. [[ @@ -240,7 +248,7 @@ embedded_components { "animations: \"MODEL_ANIM_FILE\"\n" "default_animation: \"MODEL_ANIM_NAME\"\n" "name: \"unnamed\"\n" - GO_FILE_COMPONENTS + GO_DATA_FILE_COMPONENTS "" position { x: 0.0 @@ -266,7 +274,7 @@ GO_MESH_TEXTURE_FILES MODEL_SKELETON_FILE MODEL_ANIM_FILE MODEL_ANIM_NAME -GO_FILE_COMPONENTS +GO_DATA_FILE_COMPONENTS "}\n" position { @@ -404,6 +412,8 @@ local gopscript = [[ return gop_tables end + M.tables = gop_tables + return M ]] @@ -878,6 +888,8 @@ local function makescriptfile( name, filepath, objs ) local propcount = 0 scriptdata = scriptdata..'\nlocal gop = require("'..locallua..'")\n' + local initscript = "" + local updatescript = "" for k,v in pairs(objs) do if(v.props) then @@ -886,15 +898,39 @@ local function makescriptfile( name, filepath, objs ) scriptdata = scriptdata..'gop.set("'..pkey..'", "'..pvalue..'")\n' end end + if(v.defold_props) then + for k, v in ipairs(v.defold_props) do + if(v.command == "Set Key/Value") then + propcount = propcount + 1 + if(v.keyval.is_table == true) then + scriptdata = scriptdata..'gop.set("'..tostring(v.keyval.key)..'", {} )\n' + else + scriptdata = scriptdata..'gop.set("'..tostring(v.keyval.key)..'", "'..tostring(v.keyval.value)..'")\n' + end + end + if(v.command == "Init Script") then + propcount = propcount + 1 + initscript = initscript.." "..tostring(v.scipt_init)..'\n' + end + if(v.command == "Update Script") then + propcount = propcount + 1 + updatescript = updatescript.." "..tostring(v.scipt_init)..'\n' + end + end + end end scriptdata = scriptdata..'\nfunction init(self)\n' scriptdata = scriptdata..'\tself.props = gop.getall()\n' scriptdata = scriptdata..'\t-- Run initial setup on properties here.\n' scriptdata = scriptdata..'\t-- pprint(self.props) -- Debug props\n' + + scriptdata = scriptdata..initscript + scriptdata = scriptdata..'end\n' scriptdata = scriptdata..'\nfunction update(self)\n' + scriptdata = scriptdata..updatescript scriptdata = scriptdata..'end\n' if(propcount == 0) then return "" end @@ -920,17 +956,19 @@ end ------------------------------------------------------------------------------------------------------------ -- Helper to insert go components from blender into go file -local function getcomponents( go, godata, fileobj, nodata ) +local function getcomponents( go, godata, embedded, nodata ) local compprops = getdefoldprops(go, "Add FileComponent") - local compstr = "\"\"" + local compstr = "" local prestr = "" - if(fileobj) then + if(embedded) then prestr = "data: " + compstr = "\"\"" end if compprops then - local compdata = gomodelcomponentdata + local compdata = gomodelcomponentfile + if(embedded) then compdata = gomodelcomponentembedded end for k,v in ipairs(compprops) do compdata = string.gsub(compdata, "GO_COMPONENT_ID", v.filecomponent_id) compdata = string.gsub(compdata, "GO_COMPONENT_PATH", v.filecomponent_path) @@ -938,7 +976,7 @@ local function getcomponents( go, godata, fileobj, nodata ) compstr = compstr..compdata end - if(fileobj) then + if(embedded) then if(nodata) then if(compstr == "\"\"") then compstr = "" end godata = string.gsub(godata, "GO_DATA_FILE_COMPONENTS", compstr) @@ -1038,7 +1076,7 @@ local function makegofile( name, filepath, go ) end godata = string.gsub(godata, "GO_FILE_SCRIPT", "") - godata = getcomponents( go, godata, true, true ) + godata = getcomponents( go, godata ) -- Apply animation specific changes to model data if(animname and animfile) then