76 lines
1.5 KiB
Lua
76 lines
1.5 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)
|
|
if type(self.destination) == 'string' then
|
|
log:log(string.format("You enter %s", self.destination))
|
|
set_room(self.destination)
|
|
elseif type(self.destination) == 'table' then
|
|
set_room_raw(self.destination)
|
|
else
|
|
error("destination is not valid")
|
|
end
|
|
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 = edge:from{
|
|
dir = dir,
|
|
destination = dst,
|
|
}
|
|
|
|
setmetatable(e, mt)
|
|
|
|
table.insert(room.edges, e)
|
|
end
|
|
|
|
return edge
|