mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
general cleanup, making stuff a bit more uniform; cleaned up term lib a bit; fixed redstone. again -.-; small network fix and renamed signal to 'modem_message'; converting tabs to align to properly instead of just replacing them with two spaces; word wrapping when writing to term with wrap enabled
This commit is contained in:
parent
413a4ede2a
commit
71cfa6104a
@ -14,7 +14,7 @@ local line = nil
|
|||||||
while true do
|
while true do
|
||||||
local w, h = component.primary("gpu").getResolution()
|
local w, h = component.primary("gpu").getResolution()
|
||||||
term.clear()
|
term.clear()
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
local i = 1
|
local i = 1
|
||||||
while i < h do
|
while i < h do
|
||||||
if not line then
|
if not line then
|
||||||
@ -32,14 +32,14 @@ while true do
|
|||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
term.cursor(1, h)
|
term.setCursor(1, h)
|
||||||
term.write(":")
|
term.write(":")
|
||||||
term.cursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
while true do
|
while true do
|
||||||
local event, address, char, code = coroutine.yield("key_down")
|
local event, address, char, code = coroutine.yield("key_down")
|
||||||
if component.isPrimary(address) then
|
if component.isPrimary(address) then
|
||||||
if code == keyboard.keys.q then
|
if code == keyboard.keys.q then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
return
|
return
|
||||||
elseif code == keyboard.keys.space then
|
elseif code == keyboard.keys.space then
|
||||||
|
@ -3,15 +3,14 @@ local gpuAvailable, screenAvailable = false, false
|
|||||||
local cursorX, cursorY = 1, 1
|
local cursorX, cursorY = 1, 1
|
||||||
local cursorBlink = nil
|
local cursorBlink = nil
|
||||||
|
|
||||||
local function gpu() return component.primary("gpu") end
|
|
||||||
|
|
||||||
local function toggleBlink()
|
local function toggleBlink()
|
||||||
if term.isAvailable() then
|
if term.isAvailable() then
|
||||||
local alt = gpu().get(cursorX, cursorY)
|
|
||||||
if alt ~= cursorBlink.alt then
|
|
||||||
gpu().set(cursorX, cursorY, cursorBlink.alt)
|
|
||||||
cursorBlink.alt = alt
|
|
||||||
cursorBlink.state = not cursorBlink.state
|
cursorBlink.state = not cursorBlink.state
|
||||||
|
if cursorBlink.state then
|
||||||
|
cursorBlink.alt = component.gpu.get(cursorX, cursorY)
|
||||||
|
component.gpu.set(cursorX, cursorY, unicode.char(0x2588)) -- solid block
|
||||||
|
else
|
||||||
|
component.gpu.set(cursorX, cursorY, cursorBlink.alt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -20,42 +19,45 @@ end
|
|||||||
|
|
||||||
function term.clear()
|
function term.clear()
|
||||||
if term.isAvailable() then
|
if term.isAvailable() then
|
||||||
local w, h = gpu().getResolution()
|
local w, h = component.gpu.getResolution()
|
||||||
gpu().fill(1, 1, w, h, " ")
|
component.gpu.fill(1, 1, w, h, " ")
|
||||||
end
|
end
|
||||||
cursorX, cursorY = 1, 1
|
cursorX, cursorY = 1, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function term.clearLine()
|
function term.clearLine()
|
||||||
if term.isAvailable() then
|
if term.isAvailable() then
|
||||||
local w = gpu().getResolution()
|
local w = component.gpu.getResolution()
|
||||||
gpu().fill(1, cursorY, w, 1, " ")
|
component.gpu.fill(1, cursorY, w, 1, " ")
|
||||||
end
|
end
|
||||||
cursorX = 1
|
cursorX = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function term.cursor(col, row)
|
function term.getCursor(col, row)
|
||||||
if col and row then
|
|
||||||
local w, h = gpu().getResolution()
|
|
||||||
cursorX = math.min(math.max(col, 1), w)
|
|
||||||
cursorY = math.min(math.max(row, 1), h)
|
|
||||||
end
|
|
||||||
return cursorX, cursorY
|
return cursorX, cursorY
|
||||||
end
|
end
|
||||||
|
|
||||||
function term.cursorBlink(enabled)
|
function term.setCursor(col, row)
|
||||||
checkArg(1, enabled, "boolean", "nil")
|
checkArg(1, col, "number")
|
||||||
local function start(alt)
|
checkArg(2, row, "number")
|
||||||
|
if cursorBlink and cursorBlink.state then
|
||||||
|
toggleBlink()
|
||||||
end
|
end
|
||||||
local function stop()
|
cursorX = col
|
||||||
end
|
cursorY = row
|
||||||
if enabled ~= nil then
|
end
|
||||||
|
|
||||||
|
function term.getCursorBlink()
|
||||||
|
return cursorBlink ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function term.setCursorBlink(enabled)
|
||||||
|
checkArg(1, enabled, "boolean")
|
||||||
if enabled then
|
if enabled then
|
||||||
if not cursorBlink then
|
if not cursorBlink then
|
||||||
cursorBlink = {}
|
cursorBlink = {}
|
||||||
cursorBlink.id = event.timer(0.5, toggleBlink, math.huge)
|
cursorBlink.id = event.timer(0.5, toggleBlink, math.huge)
|
||||||
cursorBlink.state = false
|
cursorBlink.state = false
|
||||||
cursorBlink.alt = unicode.char(0x2588) -- solid block
|
|
||||||
elseif not cursorBlink.state then
|
elseif not cursorBlink.state then
|
||||||
toggleBlink()
|
toggleBlink()
|
||||||
end
|
end
|
||||||
@ -66,8 +68,6 @@ function term.cursorBlink(enabled)
|
|||||||
end
|
end
|
||||||
cursorBlink = nil
|
cursorBlink = nil
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return cursorBlink ~= nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function term.isAvailable()
|
function term.isAvailable()
|
||||||
@ -79,30 +79,30 @@ function term.read(history)
|
|||||||
history = history or {}
|
history = history or {}
|
||||||
table.insert(history, "")
|
table.insert(history, "")
|
||||||
local current = #history
|
local current = #history
|
||||||
local start = term.cursor()
|
local start = term.getCursor()
|
||||||
local cursor, scroll = 1, 0
|
local cursor, scroll = 1, 0
|
||||||
|
|
||||||
local function remove()
|
local function remove()
|
||||||
local x = start - 1 + cursor - scroll
|
local x = start - 1 + cursor - scroll
|
||||||
local w = gpu().getResolution()
|
local w = component.gpu.getResolution()
|
||||||
gpu().copy(x + 1, cursorY, w - x, 1, -1, 0)
|
component.gpu.copy(x + 1, cursorY, w - x, 1, -1, 0)
|
||||||
local cursor = cursor + (w - x)
|
local cursor = cursor + (w - x)
|
||||||
local char = unicode.sub(history[current], cursor, cursor)
|
local char = unicode.sub(history[current], cursor, cursor)
|
||||||
if unicode.len(char) == 0 then
|
if unicode.len(char) == 0 then
|
||||||
char = " "
|
char = " "
|
||||||
end
|
end
|
||||||
gpu().set(w, cursorY, char)
|
component.gpu.set(w, cursorY, char)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function render()
|
local function render()
|
||||||
local w = gpu().getResolution()
|
local w = component.gpu.getResolution()
|
||||||
local str = unicode.sub(history[current], 1 + scroll, 1 + scroll + w - (start - 1))
|
local str = unicode.sub(history[current], 1 + scroll, 1 + scroll + w - (start - 1))
|
||||||
str = str .. string.rep(" ", (w - (start - 1)) - unicode.len(str))
|
str = str .. string.rep(" ", (w - (start - 1)) - unicode.len(str))
|
||||||
gpu().set(start, cursorY, str)
|
component.gpu.set(start, cursorY, str)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function scrollEnd()
|
local function scrollEnd()
|
||||||
local w = gpu().getResolution()
|
local w = component.gpu.getResolution()
|
||||||
cursor = unicode.len(history[current]) + 1
|
cursor = unicode.len(history[current]) + 1
|
||||||
scroll = math.max(0, cursor - (w - (start - 1)))
|
scroll = math.max(0, cursor - (w - (start - 1)))
|
||||||
render()
|
render()
|
||||||
@ -110,36 +110,36 @@ function term.read(history)
|
|||||||
|
|
||||||
local function scrollLeft()
|
local function scrollLeft()
|
||||||
scroll = scroll - 1
|
scroll = scroll - 1
|
||||||
local w = gpu().getResolution()
|
local w = component.gpu.getResolution()
|
||||||
gpu().copy(start, cursorY, w - start - 1, 1, 1, 0)
|
component.gpu.copy(start, cursorY, w - start - 1, 1, 1, 0)
|
||||||
local cursor = w - (start - 1) + scroll
|
local cursor = w - (start - 1) + scroll
|
||||||
local char = unicode.sub(history[current], cursor, cursor)
|
local char = unicode.sub(history[current], cursor, cursor)
|
||||||
if unicode.len(char) == 0 then
|
if unicode.len(char) == 0 then
|
||||||
char = " "
|
char = " "
|
||||||
end
|
end
|
||||||
gpu().set(1, cursorY, char)
|
component.gpu.set(1, cursorY, char)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function scrollRight()
|
local function scrollRight()
|
||||||
scroll = scroll + 1
|
scroll = scroll + 1
|
||||||
local w = gpu().getResolution()
|
local w = component.gpu.getResolution()
|
||||||
gpu().copy(start + 1, cursorY, w - start, 1, -1, 0)
|
component.gpu.copy(start + 1, cursorY, w - start, 1, -1, 0)
|
||||||
local cursor = w - (start - 1) + scroll
|
local cursor = w - (start - 1) + scroll
|
||||||
local char = unicode.sub(history[current], cursor, cursor)
|
local char = unicode.sub(history[current], cursor, cursor)
|
||||||
if unicode.len(char) == 0 then
|
if unicode.len(char) == 0 then
|
||||||
char = " "
|
char = " "
|
||||||
end
|
end
|
||||||
gpu().set(w, cursorY, char)
|
component.gpu.set(w, cursorY, char)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update()
|
local function update()
|
||||||
local w = gpu().getResolution()
|
local w = component.gpu.getResolution()
|
||||||
local cursor = cursor - 1
|
local cursor = cursor - 1
|
||||||
local x = start - 1 + cursor - scroll
|
local x = start - 1 + cursor - scroll
|
||||||
if cursor < unicode.len(history[current]) then
|
if cursor < unicode.len(history[current]) then
|
||||||
gpu().copy(x, cursorY, w - x, 1, 1, 0)
|
component.gpu.copy(x, cursorY, w - x, 1, 1, 0)
|
||||||
end
|
end
|
||||||
gpu().set(x, cursorY, unicode.sub(history[current], cursor, cursor))
|
component.gpu.set(x, cursorY, unicode.sub(history[current], cursor, cursor))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function copyIfNecessary()
|
local function copyIfNecessary()
|
||||||
@ -151,18 +151,17 @@ function term.read(history)
|
|||||||
|
|
||||||
local function updateCursor()
|
local function updateCursor()
|
||||||
cursorX = start - 1 + cursor - scroll
|
cursorX = start - 1 + cursor - scroll
|
||||||
if not term.cursorBlink() then
|
if not term.getCursorBlink() then
|
||||||
term.cursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onKeyDown(char, code)
|
local function onKeyDown(char, code)
|
||||||
if not term.isAvailable() then return end
|
local w = component.gpu.getResolution()
|
||||||
local w = gpu().getResolution()
|
|
||||||
local blink = false
|
local blink = false
|
||||||
if code == keyboard.keys.back then
|
if code == keyboard.keys.back then
|
||||||
if cursor > 1 then
|
if cursor > 1 then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
copyIfNecessary()
|
copyIfNecessary()
|
||||||
history[#history] = unicode.sub(history[#history], 1, cursor - 2) ..
|
history[#history] = unicode.sub(history[#history], 1, cursor - 2) ..
|
||||||
unicode.sub(history[#history], cursor)
|
unicode.sub(history[#history], cursor)
|
||||||
@ -174,7 +173,7 @@ function term.read(history)
|
|||||||
end
|
end
|
||||||
elseif code == keyboard.keys.delete then
|
elseif code == keyboard.keys.delete then
|
||||||
if cursor <= unicode.len(history[current]) then
|
if cursor <= unicode.len(history[current]) then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
copyIfNecessary()
|
copyIfNecessary()
|
||||||
history[#history] = unicode.sub(history[#history], 1, cursor - 1) ..
|
history[#history] = unicode.sub(history[#history], 1, cursor - 1) ..
|
||||||
unicode.sub(history[#history], cursor + 1)
|
unicode.sub(history[#history], cursor + 1)
|
||||||
@ -182,7 +181,7 @@ function term.read(history)
|
|||||||
end
|
end
|
||||||
elseif code == keyboard.keys.left then
|
elseif code == keyboard.keys.left then
|
||||||
if cursor > 1 then
|
if cursor > 1 then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
blink = true
|
blink = true
|
||||||
cursor = cursor - 1
|
cursor = cursor - 1
|
||||||
if cursor - scroll < 1 then
|
if cursor - scroll < 1 then
|
||||||
@ -191,7 +190,7 @@ function term.read(history)
|
|||||||
end
|
end
|
||||||
elseif code == keyboard.keys.right then
|
elseif code == keyboard.keys.right then
|
||||||
if cursor < unicode.len(history[current]) + 1 then
|
if cursor < unicode.len(history[current]) + 1 then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
blink = true
|
blink = true
|
||||||
cursor = cursor + 1
|
cursor = cursor + 1
|
||||||
if cursor - scroll > w - (start - 1) then
|
if cursor - scroll > w - (start - 1) then
|
||||||
@ -200,27 +199,27 @@ function term.read(history)
|
|||||||
end
|
end
|
||||||
elseif code == keyboard.keys.home then
|
elseif code == keyboard.keys.home then
|
||||||
if cursor > 1 then
|
if cursor > 1 then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
blink = true
|
blink = true
|
||||||
cursor, scroll = 1, 0
|
cursor, scroll = 1, 0
|
||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
elseif code == keyboard.keys["end"] then
|
elseif code == keyboard.keys["end"] then
|
||||||
if cursor < unicode.len(history[current]) + 1 then
|
if cursor < unicode.len(history[current]) + 1 then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
blink = true
|
blink = true
|
||||||
scrollEnd()
|
scrollEnd()
|
||||||
end
|
end
|
||||||
elseif code == keyboard.keys.up then
|
elseif code == keyboard.keys.up then
|
||||||
if current > 1 then
|
if current > 1 then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
blink = true
|
blink = true
|
||||||
current = current - 1
|
current = current - 1
|
||||||
scrollEnd()
|
scrollEnd()
|
||||||
end
|
end
|
||||||
elseif code == keyboard.keys.down then
|
elseif code == keyboard.keys.down then
|
||||||
if current < #history then
|
if current < #history then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
blink = true
|
blink = true
|
||||||
current = current + 1
|
current = current + 1
|
||||||
scrollEnd()
|
scrollEnd()
|
||||||
@ -242,7 +241,7 @@ function term.read(history)
|
|||||||
return true, nil
|
return true, nil
|
||||||
end
|
end
|
||||||
elseif not keyboard.isControl(char) then
|
elseif not keyboard.isControl(char) then
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
copyIfNecessary()
|
copyIfNecessary()
|
||||||
history[#history] = unicode.sub(history[#history], 1, cursor - 1) ..
|
history[#history] = unicode.sub(history[#history], 1, cursor - 1) ..
|
||||||
unicode.char(char) ..
|
unicode.char(char) ..
|
||||||
@ -255,13 +254,13 @@ function term.read(history)
|
|||||||
end
|
end
|
||||||
updateCursor()
|
updateCursor()
|
||||||
if blink then -- immediately show cursor
|
if blink then -- immediately show cursor
|
||||||
term.cursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onClipboard(value)
|
local function onClipboard(value)
|
||||||
copyIfNecessary()
|
copyIfNecessary()
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
local l = value:find("\n", 1, true)
|
local l = value:find("\n", 1, true)
|
||||||
if l then
|
if l then
|
||||||
history[#history] = history[#history] .. unicode.sub(value, 1, l - 1)
|
history[#history] = history[#history] .. unicode.sub(value, 1, l - 1)
|
||||||
@ -278,18 +277,21 @@ function term.read(history)
|
|||||||
if history[#history] == "" then
|
if history[#history] == "" then
|
||||||
table.remove(history)
|
table.remove(history)
|
||||||
end
|
end
|
||||||
term.cursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
print()
|
print()
|
||||||
end
|
end
|
||||||
|
|
||||||
term.cursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
while term.isAvailable() do
|
while term.isAvailable() do
|
||||||
local ok, event, address, charOrValue, code = pcall(event.pull)
|
local ok, event, address, charOrValue, code = pcall(event.pull)
|
||||||
if not ok then
|
if not ok then
|
||||||
cleanup()
|
cleanup()
|
||||||
error("interrupted", 0)
|
error("interrupted", 0)
|
||||||
end
|
end
|
||||||
if type(address) == "string" and component.isPrimary(address) then
|
if term.isAvailable() and
|
||||||
|
type(address) == "string" and
|
||||||
|
component.isPrimary(address)
|
||||||
|
then
|
||||||
if event == "key_down" then
|
if event == "key_down" then
|
||||||
local done, result = onKeyDown(charOrValue, code)
|
local done, result = onKeyDown(charOrValue, code)
|
||||||
if done then
|
if done then
|
||||||
@ -310,44 +312,50 @@ function term.read(history)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function term.write(value, wrap)
|
function term.write(value, wrap)
|
||||||
value = tostring(value)
|
if not term.isAvailable() then
|
||||||
if unicode.len(value) == 0 or not term.isAvailable() then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local blink = term.cursorBlink()
|
value = tostring(value)
|
||||||
term.cursorBlink(false)
|
if unicode.len(value) == 0 then
|
||||||
value = value:gsub("\t", " ")
|
return
|
||||||
local w, h = gpu().getResolution()
|
end
|
||||||
|
value = text.detab(value)
|
||||||
|
local w, h = component.gpu.getResolution()
|
||||||
|
local blink = term.getCursorBlink()
|
||||||
|
term.setCursorBlink(false)
|
||||||
local function checkCursor()
|
local function checkCursor()
|
||||||
if cursorX > w then
|
if cursorX > w then
|
||||||
cursorX = 1
|
cursorX = 1
|
||||||
cursorY = cursorY + 1
|
cursorY = cursorY + 1
|
||||||
end
|
end
|
||||||
if cursorY > h then
|
if cursorY > h then
|
||||||
gpu().copy(1, 1, w, h, 0, -1)
|
component.gpu.copy(1, 1, w, h, 0, -1)
|
||||||
gpu().fill(1, h, w, 1, " ")
|
component.gpu.fill(1, h, w, 1, " ")
|
||||||
cursorY = h
|
cursorY = h
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for line, nl in value:gmatch("([^\r\n]*)([\r\n]?)") do
|
for line, nl in value:gmatch("([^\r\n]*)([\r\n]?)") do
|
||||||
while wrap and unicode.len(line) > w - cursorX + 1 do
|
while wrap and unicode.len(line) > w - (cursorX - 1) do
|
||||||
local partial = unicode.sub(line, 1, w - cursorX + 1)
|
local partial = unicode.sub(line, 1, w - (cursorX - 1))
|
||||||
|
local wordWrapped = partial:match("(.*[^a-zA-Z0-9._])")
|
||||||
|
if wordWrapped or unicode.len(partial) > w then
|
||||||
|
partial = wordWrapped or partial
|
||||||
line = unicode.sub(line, unicode.len(partial) + 1)
|
line = unicode.sub(line, unicode.len(partial) + 1)
|
||||||
gpu().set(cursorX, cursorY, partial)
|
component.gpu.set(cursorX, cursorY, partial)
|
||||||
cursorX = cursorX + unicode.len(partial)
|
end
|
||||||
|
cursorX = math.huge
|
||||||
checkCursor()
|
checkCursor()
|
||||||
end
|
end
|
||||||
if unicode.len(line) > 0 then
|
if unicode.len(line) > 0 then
|
||||||
gpu().set(cursorX, cursorY, line)
|
component.gpu.set(cursorX, cursorY, line)
|
||||||
cursorX = cursorX + unicode.len(line)
|
cursorX = cursorX + unicode.len(line)
|
||||||
end
|
end
|
||||||
if unicode.len(nl) == 1 then
|
if unicode.len(nl) == 1 then
|
||||||
cursorX = 1
|
cursorX = math.huge
|
||||||
cursorY = cursorY + 1
|
|
||||||
checkCursor()
|
checkCursor()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
term.cursorBlink(blink)
|
term.setCursorBlink(blink)
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
14
assets/opencomputers/lua/rom/lib/text.lua
Normal file
14
assets/opencomputers/lua/rom/lib/text.lua
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
local text = {}
|
||||||
|
|
||||||
|
function text.detab(value, tabWidth)
|
||||||
|
checkArg(1, value, "string")
|
||||||
|
checkArg(2, tabWidth, "number", "nil")
|
||||||
|
tabWidth = tabWidth or 4
|
||||||
|
local function rep(match)
|
||||||
|
local spaces = tabWidth - match:len() % tabWidth
|
||||||
|
return match .. string.rep(" ", spaces)
|
||||||
|
end
|
||||||
|
return value:gsub("([^\n]-)\t", rep)
|
||||||
|
end
|
||||||
|
|
||||||
|
_G.text = text
|
@ -63,7 +63,7 @@ class PacketHandler extends CommonPacketHandler {
|
|||||||
|
|
||||||
def onComputerStateResponse(p: PacketParser) =
|
def onComputerStateResponse(p: PacketParser) =
|
||||||
p.readTileEntity[Computer]() match {
|
p.readTileEntity[Computer]() match {
|
||||||
case Some(t) => t.isOn = p.readBoolean()
|
case Some(t) => t.isRunning = p.readBoolean()
|
||||||
case _ => // Invalid packet.
|
case _ => // Invalid packet.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ object CaseRenderer extends TileEntitySpecialRenderer {
|
|||||||
|
|
||||||
override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) = {
|
override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) = {
|
||||||
val computer = tileEntity.asInstanceOf[Case]
|
val computer = tileEntity.asInstanceOf[Case]
|
||||||
if (computer.isOn) {
|
if (computer.isRunning) {
|
||||||
GL11.glPushAttrib(0xFFFFFF)
|
GL11.glPushAttrib(0xFFFFFF)
|
||||||
|
|
||||||
RenderState.disableLighting()
|
RenderState.disableLighting()
|
||||||
|
@ -189,13 +189,13 @@ object RobotRenderer extends TileEntitySpecialRenderer {
|
|||||||
|
|
||||||
val timeJitter = robot.hashCode
|
val timeJitter = robot.hashCode
|
||||||
val hover =
|
val hover =
|
||||||
if (robot.isOn) (Math.sin(timeJitter + worldTime / 20.0) * 0.03).toFloat
|
if (robot.isRunning) (Math.sin(timeJitter + worldTime / 20.0) * 0.03).toFloat
|
||||||
else -0.03f
|
else -0.03f
|
||||||
GL11.glTranslatef(0, hover, 0)
|
GL11.glTranslatef(0, hover, 0)
|
||||||
|
|
||||||
if (MinecraftForgeClient.getRenderPass == 0) {
|
if (MinecraftForgeClient.getRenderPass == 0) {
|
||||||
val offset = timeJitter + worldTime / 20.0
|
val offset = timeJitter + worldTime / 20.0
|
||||||
renderChassis(robot.isOn, offset)
|
renderChassis(robot.isRunning, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
robot.equippedItem match {
|
robot.equippedItem match {
|
||||||
|
@ -21,7 +21,7 @@ class Case(val parent: SimpleDelegator) extends Computer with SimpleDelegate {
|
|||||||
|
|
||||||
override def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = {
|
override def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = {
|
||||||
getIcon(localSide, world.getBlockTileEntity(x, y, z) match {
|
getIcon(localSide, world.getBlockTileEntity(x, y, z) match {
|
||||||
case computer: tileentity.Case => computer.isOn
|
case computer: tileentity.Case => computer.isRunning
|
||||||
case _ => false
|
case _ => false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package li.cil.oc.common.block
|
|||||||
|
|
||||||
import cpw.mods.fml.common.{Loader, Optional}
|
import cpw.mods.fml.common.{Loader, Optional}
|
||||||
import java.util
|
import java.util
|
||||||
|
import li.cil.oc.client.renderer.block.BlockRenderer
|
||||||
import li.cil.oc.common.tileentity
|
import li.cil.oc.common.tileentity
|
||||||
import li.cil.oc.{Config, CreativeTab}
|
import li.cil.oc.{Config, CreativeTab}
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
@ -17,7 +18,6 @@ import net.minecraft.world.{IBlockAccess, World}
|
|||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
import powercrystals.minefactoryreloaded.api.rednet.{IRedNetNetworkContainer, RedNetConnectionType, IConnectableRedNet}
|
import powercrystals.minefactoryreloaded.api.rednet.{IRedNetNetworkContainer, RedNetConnectionType, IConnectableRedNet}
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import li.cil.oc.client.renderer.block.BlockRenderer
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block proxy for all real block implementations.
|
* Block proxy for all real block implementations.
|
||||||
@ -134,13 +134,13 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
|
|||||||
override def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
override def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
||||||
subBlock(world, x, y, z) match {
|
subBlock(world, x, y, z) match {
|
||||||
case Some(subBlock) => subBlock.canConnectRedstone(
|
case Some(subBlock) => subBlock.canConnectRedstone(
|
||||||
world, x, y, z, toLocal(world, x, y, z, side match {
|
world, x, y, z, side match {
|
||||||
case -1 => ForgeDirection.UP
|
case -1 => ForgeDirection.UP
|
||||||
case 0 => ForgeDirection.NORTH
|
case 0 => ForgeDirection.NORTH
|
||||||
case 1 => ForgeDirection.EAST
|
case 1 => ForgeDirection.EAST
|
||||||
case 2 => ForgeDirection.SOUTH
|
case 2 => ForgeDirection.SOUTH
|
||||||
case 3 => ForgeDirection.WEST
|
case 3 => ForgeDirection.WEST
|
||||||
}))
|
})
|
||||||
case _ => false
|
case _ => false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,15 +235,13 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
|
|||||||
|
|
||||||
override def isProvidingStrongPower(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
override def isProvidingStrongPower(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
||||||
subBlock(world, x, y, z) match {
|
subBlock(world, x, y, z) match {
|
||||||
case Some(subBlock) => subBlock.isProvidingStrongPower(
|
case Some(subBlock) => subBlock.isProvidingStrongPower(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite)
|
||||||
world, x, y, z, toLocal(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite))
|
|
||||||
case _ => 0
|
case _ => 0
|
||||||
}
|
}
|
||||||
|
|
||||||
override def isProvidingWeakPower(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
override def isProvidingWeakPower(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
||||||
subBlock(world, x, y, z) match {
|
subBlock(world, x, y, z) match {
|
||||||
case Some(subBlock) => subBlock.isProvidingWeakPower(
|
case Some(subBlock) => subBlock.isProvidingWeakPower(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite)
|
||||||
world, x, y, z, toLocal(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite))
|
|
||||||
case _ => 0
|
case _ => 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,21 +9,21 @@ import li.cil.oc.util.{PackedColor, Persistable}
|
|||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
|
||||||
trait Buffer extends Environment with Persistable {
|
trait Buffer extends Environment with Persistable {
|
||||||
protected val buffer_ = new component.Buffer(this)
|
protected val _buffer = new component.Buffer(this)
|
||||||
|
|
||||||
protected var bufferIsDirty_ = false
|
protected var _bufferIsDirty = false
|
||||||
|
|
||||||
protected var currentGui_ = None: Option[gui.Buffer]
|
protected var _currentGui = None: Option[gui.Buffer]
|
||||||
|
|
||||||
def buffer = buffer_
|
def buffer = _buffer
|
||||||
|
|
||||||
def bufferIsDirty = bufferIsDirty_
|
def bufferIsDirty = _bufferIsDirty
|
||||||
|
|
||||||
def bufferIsDirty_=(value: Boolean) = bufferIsDirty_ = value
|
def bufferIsDirty_=(value: Boolean) = _bufferIsDirty = value
|
||||||
|
|
||||||
def currentGui = currentGui_
|
def currentGui = _currentGui
|
||||||
|
|
||||||
def currentGui_=(value: Option[gui.Buffer]) = currentGui_ = value
|
def currentGui_=(value: Option[gui.Buffer]) = _currentGui = value
|
||||||
|
|
||||||
def node: Node = buffer.node
|
def node: Node = buffer.node
|
||||||
|
|
||||||
|
@ -11,24 +11,24 @@ import net.minecraftforge.common.ForgeDirection
|
|||||||
import scala.Some
|
import scala.Some
|
||||||
|
|
||||||
abstract class Computer(isRemote: Boolean) extends Environment with ComponentInventory with Rotatable with Redstone with Analyzable {
|
abstract class Computer(isRemote: Boolean) extends Environment with ComponentInventory with Rotatable with Redstone with Analyzable {
|
||||||
protected val computer_ = if (isRemote) null else new component.Computer(this)
|
protected val _computer = if (isRemote) null else new component.Computer(this)
|
||||||
|
|
||||||
def computer = computer_
|
def computer = _computer
|
||||||
|
|
||||||
def node = if (isClient) null else computer.node
|
def node = if (isClient) null else computer.node
|
||||||
|
|
||||||
override def isClient = computer == null
|
override def isClient = computer == null
|
||||||
|
|
||||||
private var isRunning = false
|
private var _isRunning = false
|
||||||
|
|
||||||
private var hasChanged = false
|
private var hasChanged = false
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
def isOn = isRunning
|
def isRunning = _isRunning
|
||||||
|
|
||||||
def isOn_=(value: Boolean) = {
|
def isRunning_=(value: Boolean) = {
|
||||||
isRunning = value
|
_isRunning = value
|
||||||
world.markBlockForRenderUpdate(x, y, z)
|
world.markBlockForRenderUpdate(x, y, z)
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
@ -57,11 +57,11 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv
|
|||||||
world.markTileEntityChunkModified(x, y, z, this)
|
world.markTileEntityChunkModified(x, y, z, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRunning != computer.isRunning) {
|
if (_isRunning != computer.isRunning) {
|
||||||
isOutputEnabled = hasRedstoneCard && computer.isRunning
|
isOutputEnabled = hasRedstoneCard && computer.isRunning
|
||||||
ServerPacketSender.sendComputerState(this, computer.isRunning)
|
ServerPacketSender.sendComputerState(this, computer.isRunning)
|
||||||
}
|
}
|
||||||
isRunning = computer.isRunning
|
_isRunning = computer.isRunning
|
||||||
|
|
||||||
updateRedstoneInput()
|
updateRedstoneInput()
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
|
|||||||
|
|
||||||
override def node = if (isClient) null else computer.node
|
override def node = if (isClient) null else computer.node
|
||||||
|
|
||||||
override val buffer_ = new common.component.Buffer(this) {
|
override val _buffer = new common.component.Buffer(this) {
|
||||||
override def maxResolution = (48, 14)
|
override def maxResolution = (48, 14)
|
||||||
}
|
}
|
||||||
override val computer_ = if (isRemote) null else new component.Robot(this)
|
override val _computer = if (isRemote) null else new component.Robot(this)
|
||||||
val (battery, distributor, gpu, keyboard) = if (isServer) {
|
val (battery, distributor, gpu, keyboard) = if (isServer) {
|
||||||
val battery = api.Network.newNode(this, Visibility.Network).withConnector(10000).create()
|
val battery = api.Network.newNode(this, Visibility.Network).withConnector(10000).create()
|
||||||
val distributor = new component.PowerDistributor(this)
|
val distributor = new component.PowerDistributor(this)
|
||||||
|
@ -214,9 +214,9 @@ class RobotProxy(val robot: Robot) extends Computer(robot.isClient) with ISidedI
|
|||||||
|
|
||||||
override def computer = robot.computer
|
override def computer = robot.computer
|
||||||
|
|
||||||
override def isOn = robot.isOn
|
override def isRunning = robot.isRunning
|
||||||
|
|
||||||
override def isOn_=(value: Boolean) = robot.isOn_=(value)
|
override def isRunning_=(value: Boolean) = robot.isRunning_=(value)
|
||||||
|
|
||||||
override def markAsChanged() = robot.markAsChanged()
|
override def markAsChanged() = robot.markAsChanged()
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class PacketHandler extends CommonPacketHandler {
|
|||||||
|
|
||||||
def onComputerStateRequest(p: PacketParser) =
|
def onComputerStateRequest(p: PacketParser) =
|
||||||
p.readTileEntity[Computer]() match {
|
p.readTileEntity[Computer]() match {
|
||||||
case Some(t) => PacketSender.sendComputerState(t, t.isOn, Option(p.player))
|
case Some(t) => PacketSender.sendComputerState(t, t.isRunning, Option(p.player))
|
||||||
case _ => // Invalid packet.
|
case _ => // Invalid packet.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,6 +256,7 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con
|
|||||||
else {
|
else {
|
||||||
verifyComponents() // In case we're resuming after loading.
|
verifyComponents() // In case we're resuming after loading.
|
||||||
state.pop()
|
state.pop()
|
||||||
|
// TODO Assertion of "no future" in switchTo can fail when coming from here, why?
|
||||||
switchTo(state.top) // Trigger execution if necessary.
|
switchTo(state.top) // Trigger execution if necessary.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class NetworkCard extends ManagedComponent {
|
|||||||
openPorts.clear()
|
openPorts.clear()
|
||||||
if (message.name == "network.message") message.data match {
|
if (message.name == "network.message") message.data match {
|
||||||
case Array(port: Integer, args@_*) if openPorts.contains(port) =>
|
case Array(port: Integer, args@_*) if openPorts.contains(port) =>
|
||||||
node.sendToReachable("computer.signal", Seq("network_message", message.source.address, Int.box(port), Int.box(-1)) ++ args: _*)
|
node.sendToReachable("computer.signal", Seq("modem_message", message.source.address, Int.box(port)) ++ args: _*)
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ import scala.collection.{immutable, mutable}
|
|||||||
trait Component extends api.network.Component with Persistable {
|
trait Component extends api.network.Component with Persistable {
|
||||||
val name: String
|
val name: String
|
||||||
|
|
||||||
def visibility = visibility_
|
def visibility = _visibility
|
||||||
|
|
||||||
private lazy val callbacks = Component.callbacks(host.getClass)
|
private lazy val callbacks = Component.callbacks(host.getClass)
|
||||||
|
|
||||||
private var visibility_ = Visibility.None
|
private var _visibility = Visibility.None
|
||||||
|
|
||||||
def setVisibility(value: Visibility) = {
|
def setVisibility(value: Visibility) = {
|
||||||
if (value.ordinal() > reachability.ordinal()) {
|
if (value.ordinal() > reachability.ordinal()) {
|
||||||
@ -28,7 +28,7 @@ trait Component extends api.network.Component with Persistable {
|
|||||||
"' node with reachability '" + reachability + "'. It will be limited to the node's reachability.")
|
"' node with reachability '" + reachability + "'. It will be limited to the node's reachability.")
|
||||||
}
|
}
|
||||||
if (FMLCommonHandler.instance.getEffectiveSide == Side.SERVER) {
|
if (FMLCommonHandler.instance.getEffectiveSide == Side.SERVER) {
|
||||||
if (network != null) visibility_ match {
|
if (network != null) _visibility match {
|
||||||
case Visibility.Neighbors => value match {
|
case Visibility.Neighbors => value match {
|
||||||
case Visibility.Network => addTo(reachableNodes)
|
case Visibility.Network => addTo(reachableNodes)
|
||||||
case Visibility.None => removeFrom(neighbors)
|
case Visibility.None => removeFrom(neighbors)
|
||||||
@ -47,7 +47,7 @@ trait Component extends api.network.Component with Persistable {
|
|||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
visibility_ = value
|
_visibility = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,13 +94,13 @@ trait Component extends api.network.Component with Persistable {
|
|||||||
override def load(nbt: NBTTagCompound) {
|
override def load(nbt: NBTTagCompound) {
|
||||||
super.load(nbt)
|
super.load(nbt)
|
||||||
if (nbt.hasKey(Config.namespace + "component.visibility")) {
|
if (nbt.hasKey(Config.namespace + "component.visibility")) {
|
||||||
visibility_ = Visibility.values()(nbt.getInteger(Config.namespace + "component.visibility"))
|
_visibility = Visibility.values()(nbt.getInteger(Config.namespace + "component.visibility"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def save(nbt: NBTTagCompound) {
|
override def save(nbt: NBTTagCompound) {
|
||||||
super.save(nbt)
|
super.save(nbt)
|
||||||
nbt.setInteger(Config.namespace + "component.visibility", visibility_.ordinal())
|
nbt.setInteger(Config.namespace + "component.visibility", _visibility.ordinal())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,29 +13,29 @@ import net.minecraft.nbt._
|
|||||||
class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Depth.Value) extends Persistable {
|
class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Depth.Value) extends Persistable {
|
||||||
def this(size: (Int, Int), depth: PackedColor.Depth.Value) = this(size._1, size._2, depth)
|
def this(size: (Int, Int), depth: PackedColor.Depth.Value) = this(size._1, size._2, depth)
|
||||||
|
|
||||||
private var depth_ = initialDepth
|
private var _depth = initialDepth
|
||||||
|
|
||||||
private var foreground_ = 0xFFFFFF
|
private var _foreground = 0xFFFFFF
|
||||||
|
|
||||||
private var background_ = 0x000000
|
private var _background = 0x000000
|
||||||
|
|
||||||
private var packed = PackedColor.pack(foreground_, background_, depth_)
|
private var packed = PackedColor.pack(_foreground, _background, _depth)
|
||||||
|
|
||||||
def foreground = foreground_
|
def foreground = _foreground
|
||||||
|
|
||||||
def foreground_=(value: Int) = {
|
def foreground_=(value: Int) = {
|
||||||
foreground_ = value
|
_foreground = value
|
||||||
packed = PackedColor.pack(foreground_, background_, depth_)
|
packed = PackedColor.pack(_foreground, _background, _depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
def background = background_
|
def background = _background
|
||||||
|
|
||||||
def background_=(value: Int) = {
|
def background_=(value: Int) = {
|
||||||
background_ = value
|
_background = value
|
||||||
packed = PackedColor.pack(foreground_, background_, depth_)
|
packed = PackedColor.pack(_foreground, _background, _depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
def depth = depth_
|
def depth = _depth
|
||||||
|
|
||||||
def depth_=(value: PackedColor.Depth.Value) = {
|
def depth_=(value: PackedColor.Depth.Value) = {
|
||||||
if (depth != value) {
|
if (depth != value) {
|
||||||
@ -43,13 +43,13 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept
|
|||||||
val rowColor = color(row)
|
val rowColor = color(row)
|
||||||
for (col <- 0 until width) {
|
for (col <- 0 until width) {
|
||||||
val packed = rowColor(col)
|
val packed = rowColor(col)
|
||||||
val fg = PackedColor.unpackForeground(packed, depth_)
|
val fg = PackedColor.unpackForeground(packed, _depth)
|
||||||
val bg = PackedColor.unpackBackground(packed, depth_)
|
val bg = PackedColor.unpackBackground(packed, _depth)
|
||||||
rowColor(col) = PackedColor.pack(fg, bg, value)
|
rowColor(col) = PackedColor.pack(fg, bg, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
depth_ = value
|
_depth = value
|
||||||
packed = PackedColor.pack(foreground_, background_, depth_)
|
packed = PackedColor.pack(_foreground, _background, _depth)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else false
|
else false
|
||||||
@ -176,7 +176,7 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept
|
|||||||
set(0, i, line)
|
set(0, i, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
depth_ = PackedColor.Depth(nbt.getInteger("depth"))
|
_depth = PackedColor.Depth(nbt.getInteger("depth"))
|
||||||
foreground = nbt.getInteger("foreground")
|
foreground = nbt.getInteger("foreground")
|
||||||
background = nbt.getInteger("background")
|
background = nbt.getInteger("background")
|
||||||
|
|
||||||
@ -199,9 +199,9 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept
|
|||||||
}
|
}
|
||||||
nbt.setTag("buffer", b)
|
nbt.setTag("buffer", b)
|
||||||
|
|
||||||
nbt.setInteger("depth", depth_.id)
|
nbt.setInteger("depth", _depth.id)
|
||||||
nbt.setInteger("foreground", foreground_)
|
nbt.setInteger("foreground", _foreground)
|
||||||
nbt.setInteger("background", background_)
|
nbt.setInteger("background", _background)
|
||||||
|
|
||||||
val c = new NBTTagList()
|
val c = new NBTTagList()
|
||||||
for (i <- 0 until height) {
|
for (i <- 0 until height) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user