Permalink
Browse files

Added NPC support

  • Loading branch information...
1 parent dada03f commit d26d8f341677794d90c270b360a59c1f14d267fa @RachelJMorris RachelJMorris committed Dec 17, 2012
Showing with 32 additions and 2 deletions.
  1. +32 −2 converter.lua
View
@@ -44,11 +44,19 @@ function GetObjectData( layerData, currentLayer, map )
if ( objectItem["name"] == "Warp" or objectItem["name"] == "warp" ) then
obj["type"] = "object"
+ --obj["x"] = math.floor(objectItem["x"] / 20) * 20
+ --obj["y"] = math.floor(objectItem["y"] / 20) * 20
obj["x"] = objectItem["x"]
obj["y"] = objectItem["y"]
obj["z"] = currentLayer
+ --obj["width"] = math.floor(objectItem["width"] / 20) * 20
+ --obj["height"] = math.floor(objectItem["height"] / 20) * 20
obj["width"] = objectItem["width"]
obj["height"] = objectItem["height"]
+
+ if ( obj["width"] == 0 ) then obj["width"] = 20 end
+ if ( obj["height"] == 0 ) then obj["height"] = 20 end
+
obj["warp_to_map"] = objectItem["properties"]["WarpToMap"]
obj["warp_to_x"] = objectItem["properties"]["X"]
obj["warp_to_y"] = objectItem["properties"]["Y"]
@@ -60,12 +68,20 @@ function GetObjectData( layerData, currentLayer, map )
obj["warp_to_y"] = objectItem["properties"]["Y"] * map["tileheight"]
end
table.insert( tileList, obj )
+ elseif ( objectItem["name"] == "npc" or objectItem["name"] == "NPC" ) then
+ obj["x"] = objectItem["x"]
+ obj["y"] = objectItem["y"]
+ obj["layer"] = layerData["name"]
+ obj["type"] = "npc"
+ obj["entity"] = objectItem["properties"]["Type"]
+
+ table.insert( tileList, obj )
end
end
end
function GetTileData( layerData, currentLayer, map )
- tilesetWidth = map["tilesets"][1]["imagewidth"] / map["tilewidth"]
+ tilesetWidth = map["tilesets"][1]["imagewidth"] / map["tilewidth"]
collisionLayer = false -- Specifically to define solid regions
@@ -99,6 +115,12 @@ function GetTileData( layerData, currentLayer, map )
tile["film_y"] = math.floor( tileImg / tilesetWidth )
tile["layer"] = layerData["name"]
+ -- Temporary hax to get LoX working
+ if ( tile["film_x"] < 0 ) then
+ tile["film_x"] = tilesetWidth - 1
+ tile["film_y"] = tile["film_y"] - 1
+ end
+
if ( config["map"]["unit"] == "pixels" ) then
tile["x"] = tile["x"] * map["tilewidth"]
tile["y"] = tile["y"] * map["tileheight"]
@@ -157,7 +179,7 @@ function SaveMap( map )
file:write( "position " .. tile["position"] .. DynamicTab( tile["position"] ) )
end
file:write( "tile_end\n" )
- else
+ elseif ( tile["type"] == "object" ) then
-- Object
file:write(
"object_begin " .. index .. DynamicTab( index .. " " ) ..
@@ -169,7 +191,15 @@ function SaveMap( map )
"warp_to_map " .. tile["warp_to_map"] .. DynamicTab( tile["warp_to_map"] ) ..
"warp_to_x " .. tile["warp_to_x"] .. DynamicTab( tile["warp_to_x"] ) ..
"warp_to_y " .. tile["warp_to_y"] .. DynamicTab( tile["warp_to_y"] ) ..
+ "transition " .. tile["transition"] .. DynamicTab( tile["transition"] ) ..
"object_end\n" )
+ elseif ( tile["type"] == "npc" ) then
+ file:write(
+ "npc_begin " .. index .. DynamicTab( index .. " " ) ..
+ "x " .. tile["x"] .. DynamicTab( tile["x"] ) ..
+ "y " .. tile["y"] .. DynamicTab( tile["y"] ) ..
+ "entity " .. tile["entity"] .. DynamicTab( tile["entity"] ) ..
+ "npc_end\n" )
end
lastTileIndex = index

0 comments on commit d26d8f3

Please sign in to comment.