Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ellipses, change how ordering is done for tiled objects and fixed some bugs. #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ function Loader.save(map, filename)
local mapx = Loader._compactMap(map)
if not love.filesystem.exists(Loader.saveDirectory) then
love.filesystem.mkdir(Loader.saveDirectory)
if not love.filesystem.exists(Loader.saveDirectory) then
error("Could not create map save directory '" .. Loader.saveDirectory .. "'. \n- Write access to '" .. love.filesystem.getSaveDirectory() .. "' denied or read only?\n- Identity not set in 'conf.lua' or by love.filesystem.setIdentity()?")
end
end
love.filesystem.write( Loader.saveDirectory .. "/" .. filename, xml.table_to_string(mapx) )
end
Expand Down Expand Up @@ -486,6 +489,11 @@ function Loader._expandObjectLayer(t, map)
obj.polygon = {}
string.gsub(v2.xarg.points, "[%-%d]+", polygonFunct)
end

--Process ellipse objects
if v2.label == "ellipse" then
obj.ellipse = {}
end

end
obj:updateDrawInfo()
Expand Down Expand Up @@ -715,9 +723,14 @@ function Loader._compactObject(object)
objectx[#objectx+1] = polygonx
end

-- <ellipse>
if object.ellipse then
objectx[#objectx+1] = {label = "ellipse", xarg = {}}
end

-- <properties>
if next(object.properties) then
objectx[#objectx+1] = Loader.compactProperties(object.properties)
objectx[#objectx+1] = Loader._compactProperties(object.properties)
end

return objectx
Expand Down
2 changes: 1 addition & 1 deletion Map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function Map:_updateTileRange()
-- Limit the drawing range. We must make sure we can draw the tiles that are bigger
-- than the self's tileWidth and tileHeight.
if x1 and y1 and x2 and y2 then
x2 = ceil(x2/self.tileWidth)
x2 = ceil((x2+self._widestTile-self.tileWidth)/self.tileWidth)
y2 = ceil((y2+heightOffset)/self.tileHeight)
x1 = floor((x1-widthOffset)/self.tileWidth)
y1 = floor(y1/self.tileHeight)
Expand Down
40 changes: 33 additions & 7 deletions Object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ function Object:updateDrawInfo()
local tw, th = t.width, t.height
di.x, di.y = map:fromIso(self.x, self.y)
di.x, di.y = di.x - map.offsetX, di.y - map.offsetY
di.order = di.y
di.x = di.x - map.tileWidth/2
di.left, di.right, di.top, di.bottom = di.x, di.x+tw, di.y , di.y +th
di.order = di.bottom + (self.properties.z or t.properties.z or 0)
-- Is not a tile object
else
di[1], di[2] = map:fromIso(self.x, self.y)
Expand All @@ -129,13 +129,27 @@ function Object:updateDrawInfo()
local t = map.tiles[self.gid]
local tw, th = t.width, t.height
di.x, di.y = self.x - map.offsetX, self.y - map.offsetY
di.order = di.y
di.left, di.top, di.right, di.bottom = di.x, di.y, di.x+tw, di.y+th
di.left, di.top, di.right, di.bottom = di.x, di.y - th, di.x+tw, di.y
di.order = di.bottom + (self.properties.z or t.properties.z or 0)
-- Is not a tile object
--Is an ellipse
elseif self.ellipse then
di.x, di.y = self.x - map.offsetX, self.y - map.offsetY
local xr = self.width / 2
local yr = self.height / 2
local segments = math.max(self.properties.segments or 16, 8)
for i=1, segments do
local ang = math.pi * 2 * i / segments
di[i * 2 - 1] = di.x + xr * (1 + math.cos(ang))
di[i * 2 ] = di.y + yr * (1 + math.sin(ang))
end
di.left, di.top, di.right, di.bottom = di.x, di.y , di.x+self.width, di.y +self.height
di.order = 1
--Is a rectangle
else
di.x, di.y = self.x - map.offsetX, self.y - map.offsetY
di[1], di[2] = di.x, di.y
di[3], di[4] = self.width > 20 and self.width or 20, self.height > 20 and self.height or 20
di[3], di[4] = self.width > 5 and self.width or 20, self.height > 5 and self.height or 20
di.left, di.top, di.right, di.bottom = di.x, di.y , di.x+di[3], di.y +di[4]
di.order = 1
end
Expand Down Expand Up @@ -193,17 +207,29 @@ function Object:draw(x, y, r, g, b, a)
-- Map is orthogonal. Draw a rectangle.
else
love.graphics.setColor(r, g, b, a/5)
love.graphics.rectangle("fill", unpack(di))
if self.ellipse then
love.graphics.polygon("fill", unpack(di))
else
love.graphics.rectangle("fill", unpack(di))
end

love.graphics.setColor(0, 0, 0, a)
love.graphics.push()
love.graphics.translate(1,1)
love.graphics.rectangle("line", unpack(di))
if self.ellipse then
love.graphics.polygon("line", unpack(di))
else
love.graphics.rectangle("line", unpack(di))
end
love.graphics.print(self.name, di.x, di.y-20)
love.graphics.pop()

love.graphics.setColor(r,g,b,a)
love.graphics.rectangle("line", unpack(di))
if self.ellipse then
love.graphics.polygon("line", unpack(di))
else
love.graphics.rectangle("line", unpack(di))
end
love.graphics.print(self.name, di.x, di.y-20)
end
end
Expand Down