Compare commits
No commits in common. "7ecaf3e3652c1eea2626c22dc6583347adda0081" and "ded2589e501bfed32021408c04705b4affb85469" have entirely different histories.
7ecaf3e365
...
ded2589e50
3 changed files with 1 additions and 96 deletions
|
|
@ -3,9 +3,3 @@ Config = {
|
||||||
gridOffset = 0,
|
gridOffset = 0,
|
||||||
portWidth = 16
|
portWidth = 16
|
||||||
}
|
}
|
||||||
|
|
||||||
Color = {
|
|
||||||
input = { 0.8, 0.3, 0.3, 1 },
|
|
||||||
output = { 0.3, 0.3, 0.8, 1 },
|
|
||||||
mechanism = { 0.8, 0.8, 0.8, 1 }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
13
selector.lua
13
selector.lua
|
|
@ -11,18 +11,7 @@ local mecha2 = Mechanism:new( GridPoint:new(10, 5), GridPoint:new(2, 2), { port1
|
||||||
|
|
||||||
local mecha3 = Mechanism:new( GridPoint:new(13, 5), GridPoint:new(2, 1), { port1:clone(), port2:clone(), port5:clone() }, {1, 0.5, 0.5, 1} )
|
local mecha3 = Mechanism:new( GridPoint:new(13, 5), GridPoint:new(2, 1), { port1:clone(), port2:clone(), port5:clone() }, {1, 0.5, 0.5, 1} )
|
||||||
|
|
||||||
local conveyorPortI1 = Port:new( GridPoint:new(-1, 0), PortRotation.left, Color.input )
|
local mechs = { mecha1, mecha2, mecha3 }
|
||||||
local conveyorPortI2 = Port:new( GridPoint:new(0, -1), PortRotation.up, Color.input )
|
|
||||||
local conveyorPortI3 = Port:new( GridPoint:new(0, 1), PortRotation.down, Color.input )
|
|
||||||
local conveyorPortO = Port:new( GridPoint:new(1, 0), PortRotation.right, Color.output )
|
|
||||||
local conveyorMecha = Mechanism:new( GridPoint:new(0, 0), GridPoint:new(1, 1), {
|
|
||||||
conveyorPortI1:clone(),
|
|
||||||
conveyorPortI2:clone(),
|
|
||||||
conveyorPortI3:clone(),
|
|
||||||
conveyorPortO:clone()
|
|
||||||
}, Color.mechanism )
|
|
||||||
|
|
||||||
local mechs = { conveyorMecha, mecha2, mecha3 }
|
|
||||||
local actions = { 'none', 'first', 'second', 'third' }
|
local actions = { 'none', 'first', 'second', 'third' }
|
||||||
|
|
||||||
local selected = 0
|
local selected = 0
|
||||||
|
|
|
||||||
78
timer.lua
78
timer.lua
|
|
@ -1,78 +0,0 @@
|
||||||
local function defaultTimeout() end
|
|
||||||
|
|
||||||
---@class Timer
|
|
||||||
---@field duration number
|
|
||||||
---@field time number
|
|
||||||
---@field oneShot boolean
|
|
||||||
---@field timeout function
|
|
||||||
---@field data table
|
|
||||||
---@field paused boolean
|
|
||||||
Timer = {
|
|
||||||
duration = 1,
|
|
||||||
time = 1,
|
|
||||||
oneShot = false,
|
|
||||||
timeout = defaultTimeout,
|
|
||||||
data = {},
|
|
||||||
paused = true
|
|
||||||
}
|
|
||||||
|
|
||||||
---@param duration number|nil
|
|
||||||
---@param oneShot boolean|nil
|
|
||||||
---@param timeout function|nil
|
|
||||||
---@param data table|nil
|
|
||||||
---@return Timer
|
|
||||||
function Timer:new( duration, oneShot, timeout, data )
|
|
||||||
local timer = {
|
|
||||||
duration = duration or self.duration,
|
|
||||||
time = duration or self.duration,
|
|
||||||
oneShot = oneShot or self.oneShot,
|
|
||||||
timeout = timeout or self.timeout,
|
|
||||||
data = data or self.data,
|
|
||||||
paused = self.paused,
|
|
||||||
}
|
|
||||||
setmetatable( timer, { __index = self } )
|
|
||||||
|
|
||||||
return timer
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param dt number
|
|
||||||
function Timer:tick( dt )
|
|
||||||
if self.paused then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
self.time = self.time - dt
|
|
||||||
|
|
||||||
if self.time <= 0 then
|
|
||||||
self.timeout( self.data )
|
|
||||||
|
|
||||||
if self.oneShot then
|
|
||||||
self.paused = true
|
|
||||||
self.time = 0
|
|
||||||
else
|
|
||||||
self.time = self.duration + self.time
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param duration number|nil
|
|
||||||
function Timer:start( duration )
|
|
||||||
self.paused = false
|
|
||||||
if duration ~= nil then
|
|
||||||
self.duration = duration
|
|
||||||
end
|
|
||||||
self.time = self.duration
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param emit boolean
|
|
||||||
function Timer:stop( emit )
|
|
||||||
self.paused = true
|
|
||||||
self.time = 0
|
|
||||||
if emit then
|
|
||||||
self.timeout( self.data )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Timer:elapsed()
|
|
||||||
return self.duration - self.time
|
|
||||||
end
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue