Posted By

zachgoldgmailcom on 01/04/11


Tagged


Versions (?)

Problem with DAME exporter


 / Published in: Lua
 

problem is around line 445. I want to generate: Background= new ImageLayer( 1, 2, .75, .75,'Background');

or in general it's (Layer Name as object) = new ImageLayer( xPos, yPos, scrollx, scrolly, Layer Name);

Currently it generates Background= new ImageLayer( Background);

  1. groups = DAME.GetGroups()
  2. groupCount = as3.tolua(groups.length) -1
  3.  
  4. DAME.SetFloatPrecision(3)
  5.  
  6. tab1 = "\t"
  7. tab2 = "\t\t"
  8. tab3 = "\t\t\t"
  9. tab4 = "\t\t\t\t"
  10. tab5 = "\t\t\t\t\t"
  11.  
  12. -- slow to call as3.tolua many times so do as much as can in one go and store to a lua variable instead.
  13. exportOnlyCSV = as3.tolua(VALUE_ExportOnlyCSV)
  14. flixelPackage = as3.tolua(VALUE_FlixelPackage)
  15. baseClassName = as3.tolua(VALUE_BaseClass)
  16. as3Dir = as3.tolua(VALUE_AS3Dir)
  17. tileMapClass = as3.tolua(VALUE_TileMapClass)
  18. GamePackage = as3.tolua(VALUE_GamePackage)
  19. csvDir = as3.tolua(VALUE_CSVDir)
  20. importsText = as3.tolua(VALUE_Imports)
  21.  
  22. -- This is the file for the map base class
  23. baseFileText = "";
  24. fileText = "";
  25.  
  26. pathLayers = {}
  27.  
  28. containsBoxData = false
  29. containsCircleData = false
  30. containsTextData = false
  31. containsPaths = false
  32.  
  33. ------------------------
  34. -- TILEMAP GENERATION
  35. ------------------------
  36. function exportMapCSV( mapLayer, layerFileName )
  37. -- get the raw mapdata. To change format, modify the strings passed in (rowPrefix,rowSuffix,columnPrefix,columnSeparator,columnSuffix)
  38. mapText = as3.tolua(DAME.ConvertMapToText(mapLayer,"","\n","",",",""))
  39. DAME.WriteFile(csvDir.."/"..layerFileName, mapText );
  40. end
  41.  
  42. ------------------------
  43. -- PATH GENERATION
  44. ------------------------
  45.  
  46. -- This will store the path along with a name so when we call a get it will output the value between the first : and the last %
  47. -- Here it will be paths[i]. When we later call %getparent% on any attached avatar it will output paths[i].
  48. pathText = "%store:paths[%counter:paths%]%"
  49. pathText = pathText.."%counter++:paths%" -- This line will actually incremement the counter.
  50.  
  51. lineNodeText = "new FlxPoint(%nodex%, %nodey%)"
  52. splineNodeText = "{ pos:new FlxPoint(%nodex%, %nodey%), tan1:new FlxPoint(%tan1x%, %tan1y%), tan2:new FlxPoint(-(%tan2x%), -(%tan2y%)) }"
  53.  
  54. propertiesString = "generateProperties( %%proploop%%"
  55. propertiesString = propertiesString.."{ name:\"%propname%\", value:%propvaluestring% }, "
  56. propertiesString = propertiesString.."%%proploopend%%null )"
  57.  
  58. local groupPropTypes = as3.toobject({ String="String", Int="int", Float="Number", Boolean="Boolean" })
  59.  
  60. linkAssignText = "%%if link%%"
  61. linkAssignText = linkAssignText.."linkedObjectDictionary[%linkid%] = "
  62. linkAssignText = linkAssignText.."%%endiflink%%"
  63. needCallbackText = "%%if link%%, true %%endiflink%%"
  64.  
  65.  
  66. function generatePaths( )
  67. for i,v in ipairs(pathLayers) do
  68. containsPaths = true
  69. fileText = fileText..tab2.."public function addPathsForLayer"..pathLayers[i][3].."(onAddCallback:Function = null):void\n"
  70. fileText = fileText..tab2.."{\n"
  71. fileText = fileText..tab3.."var pathobj:PathData;\n\n"
  72.  
  73. linesText = pathText..tab3.."pathobj = new PathData( [ %nodelist% \n"..tab3.."], %isclosed%, false, "..pathLayers[i][3].."Group );\n"
  74. linesText = linesText..tab3.."paths.push(pathobj);\n"
  75.  
  76. linesText = linesText..tab3..linkAssignText.."callbackNewData( pathobj, onAddCallback, "..pathLayers[i][3].."Group, "..propertiesString..needCallbackText.." );\n\n"
  77.  
  78. fileText = fileText..as3.tolua(DAME.CreateTextForPaths(pathLayers[i][2], linesText, lineNodeText, linesText, splineNodeText, ",\n"..tab4))
  79. fileText = fileText..tab2.."}\n\n"
  80. end
  81. end
  82.  
  83. -------------------------------------
  84. -- SHAPE and TEXTBOX GENERATION
  85. -------------------------------------
  86.  
  87. function generateShapes( )
  88. for i,v in ipairs(shapeLayers) do
  89. groupname = shapeLayers[i][3].."Group"
  90.  
  91.  
  92. textboxText = tab3..linkAssignText.."callbackNewData(new TextData(%xpos%, %ypos%, %width%, %height%, %degrees%, \"%text%\",\"%font%\", %size%, 0x%color%, \"%align%\"), onAddCallback, "..groupname..", "..propertiesString..needCallbackText.." ) ;\n"
  93.  
  94. fileText = fileText..tab2.."public function addShapesForLayer"..shapeLayers[i][3].."(onAddCallback:Function = null):void\n"
  95. fileText = fileText..tab2.."{\n"
  96. fileText = fileText..tab3.."var obj:Object;\n\n"
  97.  
  98. boxText = tab3.."obj = new BoxData(%xpos%, %ypos%, %degrees%, %width%, %height%, "..groupname.." );\n"
  99. boxText = boxText..tab3.."shapes.push(obj);\n"
  100. boxText = boxText..tab3..linkAssignText.."callbackNewData( obj, onAddCallback, "..groupname..", "..propertiesString..needCallbackText.." );\n"
  101.  
  102. circleText = tab3.."obj = new CircleData(%xpos%, %ypos%, %radius%, "..groupname.." );\n"
  103. circleText = circleText..tab3.."shapes.push(obj);\n"
  104. circleText = circleText..tab3..linkAssignText.."callbackNewData( obj, onAddCallback, "..groupname..", "..propertiesString..needCallbackText..");\n"
  105.  
  106. shapeText = as3.tolua(DAME.CreateTextForShapes(shapeLayers[i][2], circleText, boxText, textboxText ))
  107. fileText = fileText..shapeText
  108. fileText = fileText..tab2.."}\n\n"
  109.  
  110. if string.find(shapeText, "BoxData") ~= nil then
  111. containsBoxData = true
  112. end
  113. if string.find(shapeText, "CircleData") ~= nil then
  114. containsCircleData = true
  115. end
  116. if containsTextData == false and string.find(shapeText, "TextData") ~= nil then
  117. containsTextData = true
  118. end
  119. end
  120. end
  121.  
  122. ------------------------
  123. -- BASE CLASS
  124. ------------------------
  125. if exportOnlyCSV == false then
  126. baseFileText = "//Code generated with DAME. http://www.dambots.com\n\n"
  127. baseFileText = baseFileText.."package "..GamePackage.."\n"
  128. baseFileText = baseFileText.."{\n"
  129. baseFileText = baseFileText..tab1.."import "..flixelPackage..".*;\n"
  130.  
  131. baseFileText = baseFileText..tab1.."import flash.utils.Dictionary;\n"
  132. baseFileText = baseFileText..tab1.."public class "..baseClassName.."\n"
  133. baseFileText = baseFileText..tab1.."{\n"
  134. baseFileText = baseFileText..tab2.."// The masterLayer contains every single object in this group making it easy to empty the level.\n"
  135. baseFileText = baseFileText..tab2.."public var masterLayer:FlxGroup = new FlxGroup;\n\n"
  136. baseFileText = baseFileText..tab2.."// This group contains all the tilemaps specified to use collisions.\n"
  137. baseFileText = baseFileText..tab2.."public var hitTilemaps:FlxGroup = new FlxGroup;\n\n"
  138. baseFileText = baseFileText..tab2.."public static var boundsMinX:int;\n"
  139. baseFileText = baseFileText..tab2.."public static var boundsMinY:int;\n"
  140. baseFileText = baseFileText..tab2.."public static var boundsMaxX:int;\n"
  141. baseFileText = baseFileText..tab2.."public static var boundsMaxY:int;\n\n"
  142. baseFileText = baseFileText..tab2.."public var bgColor:uint = 0;\n"
  143. baseFileText = baseFileText..tab2.."public var paths:Array = [];\t// Array of PathData\n"
  144. baseFileText = baseFileText..tab2.."public var shapes:Array = [];\t//Array of ShapeData.\n"
  145. baseFileText = baseFileText..tab2.."public static var linkedObjectDictionary:Dictionary = new Dictionary;\n\n"
  146. baseFileText = baseFileText..tab2.."public function "..baseClassName.."() { }\n\n"
  147. baseFileText = baseFileText..tab2.."// Expects callback function to be callback(newobj:Object,layer:FlxGroup,level:BaseLevel,properties:Array)\n"
  148. baseFileText = baseFileText..tab2.."public function createObjects(onAddCallback:Function = null):void { }\n\n"
  149.  
  150. baseFileText = baseFileText..tab2.."public function addTilemap( mapClass:Class, imageClass:Class, x:Number, y:Number, tileWidth:uint, tileHeight:uint, scrollX:Number, scrollY:Number, hits:Boolean, collideIdx:uint, drawIdx:uint, properties:Array, onAddCallback:Function = null ):"..tileMapClass.."\n"
  151. baseFileText = baseFileText..tab2.."{\n"
  152. baseFileText = baseFileText..tab3.."var map:"..tileMapClass.." = new "..tileMapClass..";\n"
  153. baseFileText = baseFileText..tab3.."map.collideIndex = collideIdx;\n"
  154. baseFileText = baseFileText..tab3.."map.drawIndex = drawIdx;\n"
  155. baseFileText = baseFileText..tab3.."map.loadMap( new mapClass, imageClass, tileWidth, tileHeight );\n"
  156. baseFileText = baseFileText..tab3.."map.x = x;\n"
  157. baseFileText = baseFileText..tab3.."map.y = y;\n"
  158. baseFileText = baseFileText..tab3.."map.scrollFactor.x = scrollX;\n"
  159. baseFileText = baseFileText..tab3.."map.scrollFactor.y = scrollY;\n"
  160. baseFileText = baseFileText..tab3.."if ( hits )\n"
  161. baseFileText = baseFileText..tab4.."hitTilemaps.add(map);\n"
  162. baseFileText = baseFileText..tab3.."if(onAddCallback != null)\n"
  163. baseFileText = baseFileText..tab4.."onAddCallback(map, null, this, properties);\n"
  164. baseFileText = baseFileText..tab3.."return map;\n"
  165. baseFileText = baseFileText..tab2.."}\n\n"
  166.  
  167. baseFileText = baseFileText..tab2.."public function addSpriteToLayer(passedObj:FlxObject, type:Class, layer:FlxGroup, x:Number, y:Number, angle:Number, flipped:Boolean = false, scaleX:Number = 1, scaleY:Number = 1, properties:Array = null, onAddCallback:Function = null):FlxObject\n"
  168. baseFileText = baseFileText..tab2.."{\n"
  169. baseFileText = baseFileText..tab3.."if( passedObj == null )\n"
  170. baseFileText = baseFileText..tab4.."passedObj = new type(x, y);\n"
  171. baseFileText = baseFileText..tab3.."if(passedObj is FlxSprite){\n"
  172. baseFileText = baseFileText..tab4.."var obj:FlxSprite = passedObj as FlxSprite;\n"
  173. baseFileText = baseFileText..tab4.."obj.x += obj.offset.x;\n"
  174. baseFileText = baseFileText..tab4.."obj.y += obj.offset.y;\n"
  175. baseFileText = baseFileText..tab4.."obj.angle = angle;\n"
  176. baseFileText = baseFileText..tab4.."// Only override the facing value if the class didn't change it from the default.\n"
  177. baseFileText = baseFileText..tab4.."if( obj.facing == FlxSprite.RIGHT )\n"
  178. baseFileText = baseFileText..tab5.."obj.facing = flipped ? FlxSprite.LEFT : FlxSprite.RIGHT;\n"
  179. baseFileText = baseFileText..tab4.."if ( scaleX != 1 || scaleY != 1 )\n"
  180. baseFileText = baseFileText..tab4.."{\n"
  181. baseFileText = baseFileText..tab5.."obj.scale.x = scaleX;\n"
  182. baseFileText = baseFileText..tab5.."obj.scale.y = scaleY;\n"
  183. baseFileText = baseFileText..tab5.."obj.width *= scaleX;\n"
  184. baseFileText = baseFileText..tab5.."obj.height *= scaleY;\n"
  185. baseFileText = baseFileText..tab5.."// Adjust the offset, in case it was already set.\n"
  186. baseFileText = baseFileText..tab5.."var newFrameWidth:Number = obj.frameWidth * scaleX;\n"
  187. baseFileText = baseFileText..tab5.."var newFrameHeight:Number = obj.frameHeight * scaleY;\n"
  188. baseFileText = baseFileText..tab5.."var hullOffsetX:Number = obj.offset.x * scaleX;\n"
  189. baseFileText = baseFileText..tab5.."var hullOffsetY:Number = obj.offset.y * scaleY;\n"
  190. baseFileText = baseFileText..tab5.."obj.offset.x -= (newFrameWidth- obj.frameWidth) / 2;\n"
  191. baseFileText = baseFileText..tab5.."obj.offset.y -= (newFrameHeight - obj.frameHeight) / 2;\n"
  192. baseFileText = baseFileText..tab5.."// Refresh the collision hulls. If your object moves and you have an offset you should override refreshHulls so that hullOffset is always added.\n"
  193. baseFileText = baseFileText..tab5.."obj.colHullX.x = obj.colHullY.x = obj.x + hullOffsetX;\n"
  194. baseFileText = baseFileText..tab5.."obj.colHullX.y = obj.colHullY.y = obj.y + hullOffsetY;\n"
  195. baseFileText = baseFileText..tab5.."obj.colHullX.width = obj.colHullY.width = obj.width;\n"
  196. baseFileText = baseFileText..tab5.."obj.colHullX.height = obj.colHullY.height = obj.height;\n"
  197. baseFileText = baseFileText..tab4.."}\n"
  198. baseFileText = baseFileText..tab4.."layer.add(obj,true);\n"
  199. baseFileText = baseFileText..tab4.."callbackNewData(obj, onAddCallback, layer, properties, false);\n"
  200. baseFileText = baseFileText..tab4.."return obj;\n"
  201. baseFileText = baseFileText..tab3.."} else if(passedObj is FlxGroup){\n"
  202. baseFileText = baseFileText..tab4.."layer.add(passedObj,true);\n"
  203. baseFileText = baseFileText..tab4.."callbackNewData(passedObj, onAddCallback, layer, properties, false);\n"
  204. baseFileText = baseFileText..tab4.."return passedObj;\n"
  205. baseFileText = baseFileText..tab3.."}\n"
  206. baseFileText = baseFileText..tab3.."return null\n"
  207. baseFileText = baseFileText..tab2.."}\n"
  208.  
  209. baseFileText = baseFileText..tab2.."public function addTextToLayer(textdata:TextData, layer:FlxGroup, embed:Boolean, properties:Array, onAddCallback:Function ):FlxText\n"
  210. baseFileText = baseFileText..tab2.."{\n"
  211. baseFileText = baseFileText..tab3.."var textobj:FlxText = new FlxText(textdata.x, textdata.y, textdata.width, textdata.text, embed);\n"
  212. baseFileText = baseFileText..tab3.."textobj.setFormat(textdata.fontName, textdata.size, textdata.color, textdata.alignment);\n"
  213. baseFileText = baseFileText..tab3.."addSpriteToLayer(textobj, FlxText, layer , 0, 0, textdata.angle, false, 1, 1, properties, onAddCallback );\n"
  214. baseFileText = baseFileText..tab3.."textobj.height = textdata.height;\n"
  215. baseFileText = baseFileText..tab3.."textobj.origin.x = textobj.width * 0.5;\n"
  216. baseFileText = baseFileText..tab3.."textobj.origin.y = textobj.height * 0.5;\n"
  217. baseFileText = baseFileText..tab3.."return textobj;\n"
  218. baseFileText = baseFileText..tab2.."}\n\n"
  219.  
  220. baseFileText = baseFileText..tab2.."protected function callbackNewData(data:Object, onAddCallback:Function, layer:FlxGroup, properties:Array, needsReturnData:Boolean = false):Object\n"
  221. baseFileText = baseFileText..tab2.."{\n"
  222. baseFileText = baseFileText..tab3.."if(onAddCallback != null)\n"
  223. baseFileText = baseFileText..tab3.."{\n"
  224. baseFileText = baseFileText..tab4.."var newData:Object = onAddCallback(data, layer, this, properties);\n"
  225. baseFileText = baseFileText..tab4.."if( newData != null )\n"
  226. baseFileText = baseFileText..tab5.."data = newData;\n"
  227. baseFileText = baseFileText..tab4.."else if ( needsReturnData )\n"
  228. baseFileText = baseFileText..tab5.."trace(\"Error: callback needs to return either the object passed in or a new object to set up links correctly.\");\n"
  229. baseFileText = baseFileText..tab3.."}\n"
  230. baseFileText = baseFileText..tab3.."return data;\n"
  231. baseFileText = baseFileText..tab2.."}\n\n"
  232.  
  233. baseFileText = baseFileText..tab2.."protected function generateProperties( ... arguments ):Array\n"
  234. baseFileText = baseFileText..tab2.."{\n"
  235. baseFileText = baseFileText..tab3.."var properties:Array = [];\n"
  236. baseFileText = baseFileText..tab3.."if ( arguments.length )\n"
  237. baseFileText = baseFileText..tab3.."{\n"
  238. baseFileText = baseFileText..tab4.."var i:uint = arguments.length - 1;\n"
  239. baseFileText = baseFileText..tab4.."while(i--)\n"
  240. baseFileText = baseFileText..tab4.."{\n"
  241. baseFileText = baseFileText..tab5.."properties.push( arguments[i] );\n"
  242. baseFileText = baseFileText..tab4.."}\n"
  243. baseFileText = baseFileText..tab3.."}\n"
  244. baseFileText = baseFileText..tab3.."return properties;\n"
  245. baseFileText = baseFileText..tab2.."}\n\n"
  246.  
  247. baseFileText = baseFileText..tab2.."public function createLink( objectFrom:Object, target:Object, onAddCallback:Function, properties:Array ):void\n"
  248. baseFileText = baseFileText..tab2.."{\n"
  249. baseFileText = baseFileText..tab3.."var link:ObjectLink = new ObjectLink( objectFrom, target );\n"
  250. baseFileText = baseFileText..tab3.."callbackNewData(link, onAddCallback, null, properties);\n"
  251. baseFileText = baseFileText..tab2.."}\n\n"
  252.  
  253. baseFileText = baseFileText..tab1.."}\n" -- end class
  254. baseFileText = baseFileText.."}\n" -- end package
  255. DAME.WriteFile(as3Dir.."/"..baseClassName..".as", baseFileText )
  256. end
  257.  
  258. ------------------------
  259. -- GROUP CLASSES
  260. ------------------------
  261. for groupIndex = 0,groupCount do
  262.  
  263. maps = {}
  264. spriteLayers = {}
  265. shapeLayers = {}
  266. pathLayers = {}
  267. imageLayers = {}
  268. masterLayerAddText = ""
  269. stageAddText = ""
  270.  
  271. group = groups[groupIndex]
  272. groupName = as3.tolua(group.name)
  273. groupName = string.gsub(groupName, " ", "_")
  274.  
  275. DAME.ResetCounters()
  276.  
  277.  
  278. layerCount = as3.tolua(group.children.length) - 1
  279.  
  280. -- This is the file for the map group class.
  281. fileText = "//Code generated with DAME. http://www.dambots.com\n\n"
  282. fileText = fileText.."package "..GamePackage.."\n"
  283. fileText = fileText.."{\n"
  284. fileText = fileText..tab1.."import "..flixelPackage..".*;\n"
  285. fileText = fileText..tab1.."import zachg.*;\n"
  286. fileText = fileText..tab1.."import zachg.components.*;\n"
  287. fileText = fileText..tab1.."import zachg.gameObjects.*;\n"
  288.  
  289. if # importsText > 0 then
  290. fileText = fileText..tab1.."// Custom imports:\n"..importsText.."\n"
  291. end
  292. fileText = fileText..tab1.."public class Level_"..groupName.." extends "..baseClassName.."\n"
  293. fileText = fileText..tab1.."{\n"
  294. fileText = fileText..tab2.."//Embedded media...\n"
  295.  
  296. -- Go through each layer and store some tables for the different layer types.
  297. for layerIndex = 0,layerCount do
  298. layer = group.children[layerIndex]
  299. isMap = as3.tolua(layer.map)~=nil
  300. layerName = as3.tolua(layer.name)
  301. layerName = string.gsub(layerName, " ", "_")
  302. if isMap == true then
  303. mapFileName = "mapCSV_"..groupName.."_"..layerName..".csv"
  304. -- Generate the map file.
  305. exportMapCSV( layer, mapFileName )
  306.  
  307. -- This needs to be done here so it maintains the layer visibility ordering.
  308. if exportOnlyCSV == false then
  309. table.insert(maps,{layer,layerName})
  310. -- For maps just generate the Embeds needed at the top of the class.
  311. fileText = fileText..tab2.."[Embed(source=\""..as3.tolua(DAME.GetRelativePath(as3Dir, csvDir.."/"..mapFileName)).."\", mimeType=\"application/octet-stream\")] public var CSV_"..layerName..":Class;\n"
  312. fileText = fileText..tab2.."[Embed(source=\""..as3.tolua(DAME.GetRelativePath(as3Dir, layer.imageFile)).."\")] public var Img_"..layerName..":Class;\n"
  313. masterLayerAddText = masterLayerAddText..tab3.."masterLayer.add(layer"..layerName..");\n"
  314. end
  315.  
  316. elseif exportOnlyCSV == false then
  317. if as3.tolua(layer.IsSpriteLayer()) == true then
  318. table.insert( spriteLayers,{groupName,layer,layerName})
  319. masterLayerAddText = masterLayerAddText..tab3.."masterLayer.add("..layerName.."Group);\n"
  320. masterLayerAddText = masterLayerAddText..tab3..layerName.."Group.scrollFactor.x = "..string.format("%.6f",as3.tolua(layer.xScroll))..";\n"
  321. masterLayerAddText = masterLayerAddText..tab3..layerName.."Group.scrollFactor.y = "..string.format("%.6f",as3.tolua(layer.yScroll))..";\n"
  322. stageAddText = stageAddText..tab3.."addSpritesForLayer"..layerName.."(onAddCallback);\n"
  323. elseif as3.tolua(layer.IsShapeLayer()) == true then
  324. table.insert(shapeLayers,{groupName,layer,layerName})
  325. masterLayerAddText = masterLayerAddText..tab3.."masterLayer.add("..layerName.."Group);\n"
  326. masterLayerAddText = masterLayerAddText..tab3..layerName.."Group.scrollFactor.x = "..string.format("%.6f",as3.tolua(layer.xScroll))..";\n"
  327. masterLayerAddText = masterLayerAddText..tab3..layerName.."Group.scrollFactor.y = "..string.format("%.6f",as3.tolua(layer.yScroll))..";\n"
  328.  
  329. elseif as3.tolua(layer.IsPathLayer()) == true then
  330. table.insert(pathLayers,{groupName,layer,layerName})
  331. masterLayerAddText = masterLayerAddText..tab3.."masterLayer.add("..layerName.."Group);\n"
  332. masterLayerAddText = masterLayerAddText..tab3..layerName.."Group.scrollFactor.x = "..string.format("%.6f",as3.tolua(layer.xScroll))..";\n"
  333. masterLayerAddText = masterLayerAddText..tab3..layerName.."Group.scrollFactor.y = "..string.format("%.6f",as3.tolua(layer.yScroll))..";\n"
  334. elseif as3.tolua(layer.IsImageLayer()) == true then
  335. table.insert(imageLayers,{groupName,layer,layerName})
  336. masterLayerAddText = masterLayerAddText..tab3.."masterLayer.add("..layerName..");\n"
  337. end
  338. end
  339. end
  340.  
  341. -- Generate the actual text for the derived class file.
  342.  
  343. if exportOnlyCSV == false then
  344.  
  345. ------------------------------------
  346. -- VARIABLE DECLARATIONS
  347. -------------------------------------
  348. fileText = fileText.."\n"
  349.  
  350. if # maps > 0 then
  351. fileText = fileText..tab2.."//Tilemaps\n"
  352. for i,v in ipairs(maps) do
  353. fileText = fileText..tab2.."public var layer"..maps[i][2]..":"..tileMapClass..";\n"
  354. end
  355. fileText = fileText.."\n"
  356. end
  357.  
  358. if # spriteLayers > 0 then
  359. fileText = fileText..tab2.."//Sprites\n"
  360. for i,v in ipairs(spriteLayers) do
  361. fileText = fileText..tab2.."public var "..spriteLayers[i][3].."Group:FlxGroup = new FlxGroup;\n"
  362. end
  363. fileText = fileText.."\n"
  364. end
  365.  
  366. if # shapeLayers > 0 then
  367. fileText = fileText..tab2.."//Shapes\n"
  368. for i,v in ipairs(shapeLayers) do
  369. fileText = fileText..tab2.."public var "..shapeLayers[i][3].."Group:FlxGroup = new FlxGroup;\n"
  370. end
  371. fileText = fileText.."\n"
  372. end
  373.  
  374. if # pathLayers > 0 then
  375. fileText = fileText..tab2.."//Paths\n"
  376. for i,v in ipairs(pathLayers) do
  377. fileText = fileText..tab2.."public var "..pathLayers[i][3].."Group:FlxGroup = new FlxGroup;\n"
  378. end
  379. fileText = fileText.."\n"
  380. end
  381.  
  382. if # imageLayers > 0 then
  383. fileText = fileText..tab2.."//Images\n"
  384. for i,v in ipairs(imageLayers) do
  385. fileText = fileText..tab2.."public var "..imageLayers[i][3]..":ImageLayer;\n"
  386. end
  387. fileText = fileText.."\n"
  388. end
  389.  
  390. groupPropertiesString = "%%proploop%%"..tab2.."public var %propnamefriendly%:%proptype% = %propvaluestring%;\n%%proploopend%%"
  391.  
  392. fileText = fileText..tab2.."//Properties\n"
  393. fileText = fileText..as3.tolua(DAME.GetTextForProperties( groupPropertiesString, group.properties, groupPropTypes )).."\n"
  394.  
  395. fileText = fileText.."\n"
  396. fileText = fileText..tab2.."public function Level_"..groupName.."(addToStage:Boolean = true, onAddCallback:Function = null)\n"
  397. fileText = fileText..tab2.."{\n"
  398. fileText = fileText..tab3.."// Generate maps.\n"
  399.  
  400. fileText = fileText..tab3.."var properties:Array = [];\n\n"
  401.  
  402. minx = 9999999
  403. miny = 9999999
  404. maxx = -9999999
  405. maxy = -9999999
  406. -- Create the tilemaps.
  407. for i,v in ipairs(maps) do
  408. layerName = maps[i][2]
  409. layer = maps[i][1]
  410.  
  411. x = as3.tolua(layer.map.x)
  412. y = as3.tolua(layer.map.y)
  413. width = as3.tolua(layer.map.width)
  414. height = as3.tolua(layer.map.height)
  415. xscroll = as3.tolua(layer.xScroll)
  416. yscroll = as3.tolua(layer.yScroll)
  417. hasHitsString = ""
  418. if as3.tolua(layer.HasHits) == true then
  419. hasHitsString = "true"
  420. else
  421. hasHitsString = "false"
  422. end
  423.  
  424. fileText = fileText..tab3.."properties = "..as3.tolua(DAME.GetTextForProperties( propertiesString, layer.properties ))..";\n"
  425. fileText = fileText..tab3.."layer"..layerName.." = addTilemap( CSV_"..layerName..", Img_"..layerName..", "..string.format("%.3f",x)..", "..string.format("%.3f",y)..", "..as3.tolua(layer.map.tileWidth)..", "..as3.tolua(layer.map.tileHeight)..", "..string.format("%.3f",xscroll)..", "..string.format("%.3f",yscroll)..", "..hasHitsString..", "..as3.tolua(layer.map.collideIndex)..", "..as3.tolua(layer.map.drawIndex)..", properties, onAddCallback );\n"
  426.  
  427. -- Only set the bounds based on maps whose scroll factor is the same as the player's.
  428. if xscroll == 1 and yscroll == 1 then
  429. if x < minx then minx = x end
  430. if y < miny then miny = y end
  431. if x + width > maxx then maxx = x + width end
  432. if y + height > maxy then maxy = y + height end
  433. end
  434.  
  435. end
  436.  
  437. ------------------
  438. -- IMAGES.
  439. ------------------
  440.  
  441. fileText = fileText.."\n"..tab3.."//Create image layer objects\n"
  442. for i,v in ipairs(imageLayers) do
  443. fileText = fileText..tab3..imageLayers[i][3].."= new ImageLayer( "..as3.tolua(DAME.CreateTextForImageLayer(imageLayers[i][1],"%xpos%, %ypos%, %scrollx%, %scrolly%", null))..imageLayers[i][3]..");\n"
  444. end
  445.  
  446. ------------------
  447. -- MASTER GROUP.
  448. ------------------
  449.  
  450. fileText = fileText.."\n"..tab3.."//Add layers to the master group in correct order.\n"
  451. fileText = fileText..masterLayerAddText.."\n";
  452.  
  453. fileText = fileText..tab3.."if ( addToStage )\n"
  454. fileText = fileText..tab4.."createObjects(onAddCallback);\n\n"
  455.  
  456. fileText = fileText..tab3.."boundsMinX = "..minx..";\n"
  457. fileText = fileText..tab3.."boundsMinY = "..miny..";\n"
  458. fileText = fileText..tab3.."boundsMaxX = "..maxx..";\n"
  459. fileText = fileText..tab3.."boundsMaxY = "..maxy..";\n"
  460.  
  461. fileText = fileText..tab3.."bgColor = "..as3.tolua(DAME.GetBackgroundColor())..";\n"
  462.  
  463. fileText = fileText..tab2.."}\n\n" -- end constructor
  464.  
  465. ---------------
  466. -- OBJECTS
  467. ---------------
  468. -- One function for each layer.
  469.  
  470. fileText = fileText..tab2.."override public function createObjects(onAddCallback:Function = null):void\n"
  471. fileText = fileText..tab2.."{\n"
  472. -- Must add the paths before the sprites as the sprites index into the paths array.
  473. for i,v in ipairs(pathLayers) do
  474. fileText = fileText..tab3.."addPathsForLayer"..pathLayers[i][3].."(onAddCallback);\n"
  475. end
  476. for i,v in ipairs(shapeLayers) do
  477. fileText = fileText..tab3.."addShapesForLayer"..shapeLayers[i][3].."(onAddCallback);\n"
  478. end
  479. fileText = fileText..stageAddText
  480. fileText = fileText..tab3.."generateObjectLinks(onAddCallback);\n"
  481. fileText = fileText..tab3.."FlxG.state.add(masterLayer);\n"
  482. fileText = fileText..tab2.."}\n\n"
  483.  
  484. -- Create the paths first so that sprites can reference them if any are attached.
  485.  
  486. generatePaths()
  487. generateShapes()
  488.  
  489. -- create the sprites.
  490.  
  491. for i,v in ipairs(spriteLayers) do
  492.  
  493. creationText = tab3..linkAssignText
  494. creationText = creationText.."%%if parent%%"
  495. creationText = creationText.."%getparent%.childSprite = "
  496. creationText = creationText.."%%endifparent%%"
  497. creationText = creationText.."addSpriteToLayer(%constructor:null%, %class%, "..spriteLayers[i][3].."Group , %xpos%, %ypos%, %degrees%, %flipped%, %scalex%, %scaley%, "..propertiesString..", onAddCallback );//%name%\n"
  498. creationText = creationText.."%%if parent%%"
  499. creationText = creationText..tab3.."%getparent%.childAttachNode = %attachedsegment%;\n"
  500. creationText = creationText..tab3.."%getparent%.childAttachT = %attachedsegment_t%;\n"
  501. creationText = creationText.."%%endifparent%%"
  502.  
  503. fileText = fileText..tab2.."public function addSpritesForLayer"..spriteLayers[i][3].."(onAddCallback:Function = null):void\n"
  504. fileText = fileText..tab2.."{\n"
  505.  
  506. fileText = fileText..as3.tolua(DAME.CreateTextForSprites(spriteLayers[i][2],creationText,"Avatar"))
  507. fileText = fileText..tab2.."}\n\n"
  508. end
  509.  
  510. -- Create the links between objects.
  511.  
  512. fileText = fileText..tab2.."public function generateObjectLinks(onAddCallback:Function = null):void\n"
  513. fileText = fileText..tab2.."{\n"
  514. linkText = tab3.."createLink(linkedObjectDictionary[%linkfromid%], linkedObjectDictionary[%linktoid%], onAddCallback, "..propertiesString.." );\n"
  515. fileText = fileText..as3.tolua(DAME.GetTextForLinks(linkText,group))
  516. fileText = fileText..tab2.."}\n"
  517.  
  518. fileText = fileText.."\n"
  519. fileText = fileText..tab1.."}\n" -- end class
  520. fileText = fileText.."}\n" -- end package
  521.  
  522.  
  523.  
  524. -- Save the file!
  525.  
  526. DAME.WriteFile(as3Dir.."/Level_"..groupName..".as", fileText )
  527.  
  528. end
  529. end
  530.  
  531. -- Create any extra required classes.
  532. -- must be done last after the parser has gone through.
  533.  
  534. if exportOnlyCSV == false then
  535.  
  536. --if containsTextData == true then
  537. textfile = "package "..GamePackage.."\n"
  538. textfile = textfile.."{\n"
  539. textfile = textfile..tab1.."public class TextData\n"
  540. textfile = textfile..tab1.."{\n"
  541. textfile = textfile..tab2.."public var x:Number;\n"
  542. textfile = textfile..tab2.."public var y:Number;\n"
  543. textfile = textfile..tab2.."public var width:uint;\n"
  544. textfile = textfile..tab2.."public var height:uint;\n"
  545. textfile = textfile..tab2.."public var angle:Number;\n"
  546. textfile = textfile..tab2.."public var text:String;\n"
  547. textfile = textfile..tab2.."public var fontName:String;\n"
  548. textfile = textfile..tab2.."public var size:uint;\n"
  549. textfile = textfile..tab2.."public var color:uint;\n"
  550. textfile = textfile..tab2.."public var alignment:String;\n\n"
  551. textfile = textfile..tab2.."public function TextData( X:Number, Y:Number, Width:uint, Height:uint, Angle:Number, Text:String, FontName:String, Size:uint, Color:uint, Alignment:String )\n"
  552. textfile = textfile..tab2.."{\n"
  553. textfile = textfile..tab3.."x = X;\n"
  554. textfile = textfile..tab3.."y = Y;\n"
  555. textfile = textfile..tab3.."width = Width;\n"
  556. textfile = textfile..tab3.."height = Height;\n"
  557. textfile = textfile..tab3.."angle = Angle;\n"
  558. textfile = textfile..tab3.."text = Text;\n"
  559. textfile = textfile..tab3.."fontName = FontName;\n"
  560. textfile = textfile..tab3.."size = Size;\n"
  561. textfile = textfile..tab3.."color = Color;\n"
  562. textfile = textfile..tab3.."alignment = Alignment;\n"
  563. textfile = textfile..tab2.."}\n"
  564. textfile = textfile..tab1.."}\n"
  565. textfile = textfile.."}\n"
  566.  
  567. DAME.WriteFile(as3Dir.."/TextData.as", textfile )
  568. --end
  569.  
  570. if containsPaths == true then
  571. textfile = "package "..GamePackage.."\n"
  572. textfile = textfile.."{\n"
  573. textfile = textfile..tab1.."import "..flixelPackage..".FlxGroup;\n"
  574. textfile = textfile..tab1.."import "..flixelPackage..".FlxSprite;\n\n"
  575. textfile = textfile..tab1.."public class PathData\n"
  576. textfile = textfile..tab1.."{\n"
  577. textfile = textfile..tab2.."public var nodes:Array;\n"
  578. textfile = textfile..tab2.."public var isClosed:Boolean;\n"
  579. textfile = textfile..tab2.."public var isSpline:Boolean;\n"
  580. textfile = textfile..tab2.."public var layer:FlxGroup;\n\n"
  581. textfile = textfile..tab2.."// These values are only set if there is an attachment.\n"
  582. textfile = textfile..tab2.."public var childSprite:FlxSprite = null;\n"
  583. textfile = textfile..tab2.."public var childAttachNode:int = 0;\n"
  584. textfile = textfile..tab2.."public var childAttachT:Number = 0;\t// position of child between attachNode and next node.(0-1)\n\n"
  585. textfile = textfile..tab2.."public function PathData( Nodes:Array, Closed:Boolean, Spline:Boolean, Layer:FlxGroup )\n"
  586. textfile = textfile..tab2.."{\n"
  587. textfile = textfile..tab3.."nodes = Nodes;\n"
  588. textfile = textfile..tab3.."isClosed = Closed;\n"
  589. textfile = textfile..tab3.."isSpline = Spline;\n"
  590. textfile = textfile..tab3.."layer = Layer;\n"
  591. textfile = textfile..tab2.."}\n"
  592. textfile = textfile..tab1.."}\n"
  593. textfile = textfile.."}\n"
  594.  
  595. DAME.WriteFile(as3Dir.."/PathData.as", textfile )
  596.  
  597. end
  598.  
  599. if containsBoxData == true or containsCircleData == true then
  600. textfile = "package "..GamePackage.."\n"
  601. textfile = textfile.."{\n"
  602. textfile = textfile..tab1.."import "..flixelPackage..".FlxGroup;\n\n"
  603. textfile = textfile..tab1.."public class ShapeData\n"
  604. textfile = textfile..tab1.."{\n"
  605. textfile = textfile..tab2.."public var x:Number;\n"
  606. textfile = textfile..tab2.."public var y:Number;\n"
  607. textfile = textfile..tab2.."public var group:FlxGroup;\n\n"
  608. textfile = textfile..tab2.."public function ShapeData(X:Number, Y:Number, Group:FlxGroup )\n"
  609. textfile = textfile..tab2.."{\n"
  610. textfile = textfile..tab3.."x = X;\n"
  611. textfile = textfile..tab3.."y = Y;\n"
  612. textfile = textfile..tab3.."group = Group;\n"
  613. textfile = textfile..tab2.."}\n"
  614. textfile = textfile..tab1.."}\n"
  615. textfile = textfile.."}\n"
  616.  
  617. DAME.WriteFile(as3Dir.."/ShapeData.as", textfile )
  618. end
  619.  
  620. if containsBoxData == true then
  621. textfile = "package "..GamePackage.."\n"
  622. textfile = textfile.."{\n"
  623. textfile = textfile..tab1.."import "..flixelPackage..".FlxGroup;\n\n"
  624. textfile = textfile..tab1.."public class BoxData extends ShapeData\n"
  625. textfile = textfile..tab1.."{\n"
  626. textfile = textfile..tab2.."public var angle:Number;\n"
  627. textfile = textfile..tab2.."public var width:uint;\n"
  628. textfile = textfile..tab2.."public var height:uint;\n\n"
  629. textfile = textfile..tab2.."public function BoxData( X:Number, Y:Number, Angle:Number, Width:uint, Height:uint, Group:FlxGroup ) \n"
  630. textfile = textfile..tab2.."{\n"
  631. textfile = textfile..tab3.."super(X, Y, Group);\n"
  632. textfile = textfile..tab3.."angle = Angle;\n"
  633. textfile = textfile..tab3.."width = Width;\n"
  634. textfile = textfile..tab3.."height = Height;\n"
  635. textfile = textfile..tab2.."}\n"
  636. textfile = textfile..tab1.."}\n"
  637. textfile = textfile.."}\n"
  638.  
  639. DAME.WriteFile(as3Dir.."/BoxData.as", textfile )
  640. end
  641.  
  642. if containsCircleData == true then
  643. textfile = "package "..GamePackage.."\n"
  644. textfile = textfile.."{\n"
  645. textfile = textfile..tab1.."import "..flixelPackage..".FlxGroup;\n\n"
  646. textfile = textfile..tab1.."public class CircleData extends ShapeData\n"
  647. textfile = textfile..tab1.."{\n"
  648. textfile = textfile..tab2.."public var radius:Number;\n\n"
  649. textfile = textfile..tab2.."public function CircleData( X:Number, Y:Number, Radius:Number, Group:FlxGroup )\n"
  650. textfile = textfile..tab2.."{\n"
  651. textfile = textfile..tab3.."super(X, Y, Group);\n"
  652. textfile = textfile..tab3.."radius = Radius;\n"
  653. textfile = textfile..tab2.."}\n"
  654. textfile = textfile..tab1.."}\n"
  655. textfile = textfile.."}\n"
  656.  
  657. DAME.WriteFile(as3Dir.."/CircleData.as", textfile )
  658. end
  659.  
  660. textfile = "package "..GamePackage.."\n"
  661. textfile = textfile.."{\n"
  662. textfile = textfile..tab1.."public class ObjectLink\n"
  663. textfile = textfile..tab1.."{\n"
  664. textfile = textfile..tab2.."public var fromObject:Object;\n"
  665. textfile = textfile..tab2.."public var toObject:Object;\n"
  666. textfile = textfile..tab2.."public function ObjectLink(from:Object, to:Object)\n"
  667. textfile = textfile..tab2.."{\n"
  668. textfile = textfile..tab3.."fromObject = from;\n"
  669. textfile = textfile..tab3.."toObject = to;\n"
  670. textfile = textfile..tab2.."}\n"
  671. textfile = textfile..tab1.."}\n"
  672. textfile = textfile.."}\n"
  673. DAME.WriteFile(as3Dir.."/ObjectLink.as", textfile )
  674. end
  675.  
  676. textfile = "package "..GamePackage.."\n"
  677. textfile = textfile.."{\n"
  678. textfile = textfile..tab1.."import org.flixel.FlxPoint;\n"
  679. textfile = textfile..tab1.."import org.flixel.FlxSprite;\n"
  680.  
  681. textfile = textfile..tab1.."/**\n"
  682. textfile = textfile..tab1.." * NOTE that the name of the image layer within the DAME editor has to correspond to the\n"
  683. textfile = textfile..tab1.." * embed Class name.\n"
  684. textfile = textfile..tab1.." * \n"
  685. textfile = textfile..tab1.." * @author zachgoldstein\n"
  686. textfile = textfile..tab1.." * \n"
  687. textfile = textfile..tab1.." */ \n"
  688.  
  689. textfile = textfile..tab1.."public class ImageLayer extends FlxSprite"
  690. textfile = textfile..tab1.."{\n"
  691. textfile = textfile..tab2.."public function ImageLayer(X:Number,Y:Number,scrollX:Number,scrollY:Number, embedName:String)\n"
  692. textfile = textfile..tab2.."{\n"
  693. textfile = textfile..tab3.."super(X,Y);\n"
  694. textfile = textfile..tab3.."x = X;\n"
  695. textfile = textfile..tab3.."y = Y;\n"
  696. textfile = textfile..tab3.."if(Resources[embedName] != null){;\n"
  697. textfile = textfile..tab4.."loadGraphic(Resources[embedName],false,false);\n"
  698. textfile = textfile..tab3.."}\n"
  699. textfile = textfile..tab3.."scrollFactor = new FlxPoint(scrollX,scrollY);\n"
  700. textfile = textfile..tab2.."}\n"
  701. textfile = textfile..tab1.."}\n"
  702. textfile = textfile.."}\n"
  703. DAME.WriteFile(as3Dir.."/ImageLayer.as", textfile )
  704.  
  705. return 1

Report this snippet  

You need to login to post a comment.