garden/edge.lua
2025-01-03 20:48:56 +09:00

70 lines
1.3 KiB
Lua

local window = require('window')
local entity = require('entity')
-- 320x240
local edge_data = {
up = {
x = 120,
y = 10,
width = 80,
height = 10,
lines = {{'fill', {0, 10, 80, 10, 40, 0}}},
},
down = {
x = 120,
y = 220,
width = 80,
height = 10,
lines = {{'fill', {0, 0, 80, 0, 40, 10}}},
},
left = {
x = 10,
y = 80,
width = 10,
height = 80,
lines = {{'fill', {10, 0, 10, 80, 0, 40}}},
},
right = {
x = 300,
y = 80,
width = 10,
height = 80,
lines = {{'fill', {0, 0, 0, 80, 10, 40}}},
}
}
local edge = entity:from{
dir = "up",
destination = "nowhere",
mousepressed = window.mousepressed(function (self)
log:log(string.format("You enter %s", self.destination))
set_room(self.destination)
end)
}
local mt = {
__index = function (t, k)
if edge_data[t.dir][k] then
return edge_data[t.dir][k]
else
return edge[k]
end
end
}
function edge:set(room, dir, dst)
local e = self:from{
dir = dir,
destination = dst,
}
setmetatable(e, mt)
table.insert(room.edges, e)
end
return edge