feat(world): add a batchActor function activated by a bool in tiled
This way, you can add multiple actors with just one tiled object. It also bring better feature parity with Imperium Porcorum. Fixes #10
This commit is contained in:
parent
4c2427bfd6
commit
65b0c74a06
4 changed files with 87 additions and 153 deletions
|
@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- **world/camera:** Add support for Head-Up-Display
|
||||
|
||||
- **world:** Support batching actor loading
|
||||
|
||||
### Changed
|
||||
|
||||
- **world:** automatize world integration in a scene
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
return {
|
||||
version = "1.2",
|
||||
luaversion = "5.1",
|
||||
tiledversion = "1.2.2",
|
||||
tiledversion = "1.2.4",
|
||||
orientation = "orthogonal",
|
||||
renderorder = "right-down",
|
||||
width = 150,
|
||||
|
@ -9,7 +9,7 @@ return {
|
|||
tilewidth = 16,
|
||||
tileheight = 16,
|
||||
nextlayerid = 6,
|
||||
nextobjectid = 24,
|
||||
nextobjectid = 25,
|
||||
backgroundcolor = { 0, 170, 255 },
|
||||
properties = {},
|
||||
tilesets = {
|
||||
|
@ -271,83 +271,20 @@ return {
|
|||
draworder = "topdown",
|
||||
properties = {},
|
||||
objects = {
|
||||
{
|
||||
id = 9,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 512,
|
||||
y = 2160,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 11,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 480,
|
||||
x = 464,
|
||||
y = 2160,
|
||||
width = 16,
|
||||
width = 128,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 12,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 544,
|
||||
y = 2160,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 13,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 576,
|
||||
y = 2160,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 14,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 368,
|
||||
y = 2208,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 15,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 400,
|
||||
y = 2208,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
properties = {
|
||||
["batchActor"] = true
|
||||
}
|
||||
},
|
||||
{
|
||||
id = 16,
|
||||
|
@ -356,76 +293,15 @@ return {
|
|||
shape = "rectangle",
|
||||
x = 336,
|
||||
y = 2208,
|
||||
width = 16,
|
||||
width = 80,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 17,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 112,
|
||||
y = 2224,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 18,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 144,
|
||||
y = 2224,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 19,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 176,
|
||||
y = 2224,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 20,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 256,
|
||||
y = 2272,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 21,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 256,
|
||||
y = 2240,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
properties = {
|
||||
["batchActor"] = true,
|
||||
["gheight"] = 32,
|
||||
["gwidth"] = 32
|
||||
}
|
||||
},
|
||||
{
|
||||
id = 22,
|
||||
|
@ -435,10 +311,31 @@ return {
|
|||
x = 256,
|
||||
y = 2208,
|
||||
width = 16,
|
||||
height = 80,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {
|
||||
["batchActor"] = true,
|
||||
["gheight"] = 32,
|
||||
["gwidth"] = 32
|
||||
}
|
||||
},
|
||||
{
|
||||
id = 24,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 112,
|
||||
y = 2224,
|
||||
width = 80,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
properties = {
|
||||
["batchActor"] = true,
|
||||
["gheight"] = 32,
|
||||
["gwidth"] = 32
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.2" tiledversion="1.2.2" orientation="orthogonal" renderorder="right-down" width="150" height="150" tilewidth="16" tileheight="16" infinite="0" backgroundcolor="#00aaff" nextlayerid="6" nextobjectid="24">
|
||||
<map version="1.2" tiledversion="1.2.4" orientation="orthogonal" renderorder="right-down" width="150" height="150" tilewidth="16" tileheight="16" infinite="0" backgroundcolor="#00aaff" nextlayerid="6" nextobjectid="25">
|
||||
<tileset firstgid="1" source="monkeylad_further.tsx"/>
|
||||
<layer id="1" name="Calque de Tile 1" width="150" height="150">
|
||||
<data encoding="csv">
|
||||
|
@ -161,19 +161,32 @@
|
|||
<object id="8" x="464" y="2192" width="128" height="16"/>
|
||||
</objectgroup>
|
||||
<objectgroup id="4" name="coin">
|
||||
<object id="9" x="512" y="2160" width="16" height="16"/>
|
||||
<object id="11" x="480" y="2160" width="16" height="16"/>
|
||||
<object id="12" x="544" y="2160" width="16" height="16"/>
|
||||
<object id="13" x="576" y="2160" width="16" height="16"/>
|
||||
<object id="14" x="368" y="2208" width="16" height="16"/>
|
||||
<object id="15" x="400" y="2208" width="16" height="16"/>
|
||||
<object id="16" x="336" y="2208" width="16" height="16"/>
|
||||
<object id="17" x="112" y="2224" width="16" height="16"/>
|
||||
<object id="18" x="144" y="2224" width="16" height="16"/>
|
||||
<object id="19" x="176" y="2224" width="16" height="16"/>
|
||||
<object id="20" x="256" y="2272" width="16" height="16"/>
|
||||
<object id="21" x="256" y="2240" width="16" height="16"/>
|
||||
<object id="22" x="256" y="2208" width="16" height="16"/>
|
||||
<object id="11" x="464" y="2160" width="128" height="16">
|
||||
<properties>
|
||||
<property name="batchActor" type="bool" value="true"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="16" x="336" y="2208" width="80" height="16">
|
||||
<properties>
|
||||
<property name="batchActor" type="bool" value="true"/>
|
||||
<property name="gheight" type="int" value="32"/>
|
||||
<property name="gwidth" type="int" value="32"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="22" x="256" y="2208" width="16" height="80">
|
||||
<properties>
|
||||
<property name="batchActor" type="bool" value="true"/>
|
||||
<property name="gheight" type="int" value="32"/>
|
||||
<property name="gwidth" type="int" value="32"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="24" x="112" y="2224" width="80" height="16">
|
||||
<properties>
|
||||
<property name="batchActor" type="bool" value="true"/>
|
||||
<property name="gheight" type="int" value="32"/>
|
||||
<property name="gwidth" type="int" value="32"/>
|
||||
</properties>
|
||||
</object>
|
||||
</objectgroup>
|
||||
<objectgroup id="5" name="player">
|
||||
<object id="23" x="80" y="2272" width="16" height="32"/>
|
||||
|
|
|
@ -231,13 +231,35 @@ function BaseWorld:loadMapActors()
|
|||
if self:isActorIndexed(objectlayer.name) then
|
||||
print("DEBUG: loading actors in " .. objectlayer.name .. " actor layer")
|
||||
for k, object in pairs(objectlayer.objects) do
|
||||
self:newActor(objectlayer.name, object.x, object.y)
|
||||
if (object.properties.batchActor) then
|
||||
self:batchActor(objectlayer.name, object)
|
||||
else
|
||||
self:newActor(objectlayer.name, object.x, object.y)
|
||||
end
|
||||
end
|
||||
self.map:removeLayer(objectlayer.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function BaseWorld:batchActor(name, object)
|
||||
local gwidth = object.properties.gwidth or self.map.tilewidth
|
||||
local gheight = object.properties.gheight or self.map.tileheight
|
||||
local x = object.x
|
||||
local y = object.y
|
||||
local w = object.width
|
||||
local h = object.height
|
||||
|
||||
local cellHor = math.ceil(w / gwidth)
|
||||
local cellVert = math.ceil(h / gheight)
|
||||
|
||||
for i=1, cellHor do
|
||||
for j=1, cellVert do
|
||||
self:newActor(name, x + (i-1)*gwidth, y + (j-1)*gheight)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function BaseWorld:loadMapPlayers()
|
||||
for k, objectlayer in pairs(self.map.layers) do
|
||||
if (objectlayer.name == "player") then
|
||||
|
|
Loading…
Reference in a new issue