This commit is contained in:
Alexey 2025-10-30 00:09:34 +03:00
commit d5e8a6945e
6 changed files with 77 additions and 28 deletions

View file

@ -6,19 +6,26 @@ require 'port'
---@param size GridPoint
---@return GridPoint
local function nextxcorner( xcorner, size )
local cornerLookup = {
-- We're looking for old size
local cornerLookup1 = {
GridPoint:new( 0, 0 ),
GridPoint:new( size.y - 1, 0 ),
GridPoint:new( size.y - 1, size.x - 1 ),
GridPoint:new( 0, size.x - 1 )
}
local cornerLookup2 = {
GridPoint:new( 0, 0 ),
GridPoint:new( size.x - 1, 0 ),
GridPoint:new( size.x - 1, size.y - 1 ),
GridPoint:new( size.x - 1, size.y - 1 )
GridPoint:new( 0, size.y - 1 )
}
local index = TableFind(cornerLookup, xcorner, function(value) value:equals(xcorner) end)
if index < #cornerLookup then
local index = TableFind(cornerLookup1, xcorner, function(xc, value) return value:equals(xc) end)
if index < #cornerLookup1 then
index = index + 1
else
index = 0
end
return cornerLookup[index]
return cornerLookup2[index]
end
---@class Mechanism
@ -49,6 +56,7 @@ function Mechanism:new( position, size, ports, color )
end
function Mechanism:rotateClockwise()
self.size = GridPoint:new(self.size.y, self.size.x)
self.xcorner = nextxcorner(self.xcorner, self.size)
for _, port in ipairs(self.ports) do
port:rotateClockwise()
@ -58,8 +66,6 @@ end
function Mechanism:draw()
love.graphics.setColor(self.color)
local x, y = self.position:globalCoords()
x = x - Config.cellSize / 2
y = y - Config.cellSize / 2
local w, h = self.size:globalCoords()
love.graphics.rectangle("fill", x, y, w, h)
for _, port in ipairs(self.ports) do