89 lines
1.5 KiB
Lua
89 lines
1.5 KiB
Lua
|
|
PortTypes = {
|
|
output = 0,
|
|
input = 1
|
|
}
|
|
|
|
PortDirections = {
|
|
[0] = {-1, 0, 0},
|
|
[1] = {0, 1, 0},
|
|
[2] = {1, 0, 0},
|
|
[3] = {0, -1, 0},
|
|
[4] = {0, 0, 1},
|
|
[5] = {0, 0, -1}
|
|
}
|
|
|
|
Port = {
|
|
logictype = 1,
|
|
}
|
|
|
|
function Port.new(self, type, direction, position, causeupdate)
|
|
local o = {
|
|
type = type,
|
|
direction = direction,
|
|
position = position,
|
|
causeupdate = causeupdate,
|
|
state = false,
|
|
gate = nil,
|
|
group = nil,
|
|
}
|
|
setmetatable(o, self)
|
|
self.__index = self
|
|
return o
|
|
end
|
|
|
|
function Port.setstate(port, state)
|
|
if state ~= port.state then
|
|
port.state = state
|
|
Simulation.queuegroup(sim, port.group)
|
|
end
|
|
end
|
|
|
|
function Port.setinputstate(port, state)
|
|
if state ~= port.state then
|
|
port.state = state
|
|
if port.causeupdate then
|
|
Simulation.queuegate(sim, port.gate)
|
|
end
|
|
end
|
|
end
|
|
|
|
function Port.getconnectionposition(self)
|
|
local offset = PortDirections[self.direction]
|
|
return {self.position[1]+offset[1], self.position[2]+offset[2], self.position[3]+offset[3]}
|
|
end
|
|
|
|
function Port.isrising(self)
|
|
if self.group == nil then
|
|
return false
|
|
end
|
|
return self.group.state and (self.group.updatetick == sim.currenttick)
|
|
end
|
|
|
|
function Port.isfalling(self)
|
|
if self.group == nil then
|
|
return false
|
|
end
|
|
return self.group.state == false and (self.group.updatetick == sim.currenttick)
|
|
end
|
|
|
|
function Port.setgate(self, gate)
|
|
self.gate = gate
|
|
end
|
|
|
|
function Port.setgroup(self, group)
|
|
self.group = group
|
|
end
|
|
|
|
function Port.getgroup(self)
|
|
return self.group
|
|
end
|
|
|
|
function Port.gettype(self)
|
|
return self.type
|
|
end
|
|
|
|
function Port.getstate(self)
|
|
return self.state
|
|
end
|