Skip to content

Commit

Permalink
Fix engine message ot displaying correctly on the screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwursteisen committed Mar 18, 2024
1 parent 86c3ddc commit d105f6c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 4 additions & 1 deletion tiny-doc/src/docs/asciidoc/sample/_engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ function popup(logo, text, color, keep)
end

function printDebug(index, text, color)
local prev = gfx.camera()
shape.rectf(0, index * 6, #text * 6 + 6, 6, color)
print(text, 6, index * 6 + 1, "#FFFFFF")
gfx.camera(prev.x, prev.y)
end

function clear()
Expand All @@ -40,8 +42,9 @@ end

function _draw()
if forever or dt > 0 then
local prev = gfx.camera()
shape.rectf(0, 0, width, 6 * msg.lines, msg.color)
-- TODO: display the logo
print(msg.text, 6, 1, "#FFFFFF")
gfx.camera(prev.x, prev.y)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,23 @@ class GfxLib(private val resourceAccess: GameResourceAccess) : TwoArgFunction()

@TinyCall("Reset the game camera to it's default position (0,0).")
override fun call(): LuaValue {
val previous = coordinates()
resourceAccess.frameBuffer.camera.set(0, 0)
return NONE
return previous
}

@TinyCall("Set game camera to the position x, y.")
override fun call(@TinyArg("x") arg1: LuaValue, @TinyArg("y") arg2: LuaValue): LuaValue {
val previous = coordinates()
resourceAccess.frameBuffer.camera.set(arg1.toint(), arg2.toint())
return NONE
return previous
}

private fun coordinates(): LuaTable {
return LuaTable().apply {
set("x", resourceAccess.frameBuffer.camera.x)
set("y", resourceAccess.frameBuffer.camera.y)
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion tiny-engine/src/commonMain/resources/_engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ function popup(logo, text, color, keep)
end

function printDebug(index, text, color)
local prev = gfx.camera()
shape.rectf(0, index * 6, #text * 6 + 6, 6, color)
print(text, 6, index * 6 + 1, "#FFFFFF")
gfx.camera(prev.x, prev.y)
end

function clear()
Expand All @@ -40,8 +42,9 @@ end

function _draw()
if forever or dt > 0 then
local prev = gfx.camera()
shape.rectf(0, 0, width, 6 * msg.lines, msg.color)
-- TODO: display the logo
print(msg.text, 6, 1, "#FFFFFF")
gfx.camera(prev.x, prev.y)
end
end
5 changes: 4 additions & 1 deletion tiny-web-editor/src/jsMain/resources/_engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ function popup(logo, text, color, keep)
end

function printDebug(index, text, color)
local prev = gfx.camera()
shape.rectf(0, index * 6, #text * 6 + 6, 6, color)
print(text, 6, index * 6 + 1, "#FFFFFF")
gfx.camera(prev.x, prev.y)
end

function clear()
Expand All @@ -40,8 +42,9 @@ end

function _draw()
if forever or dt > 0 then
local prev = gfx.camera()
shape.rectf(0, 0, width, 6 * msg.lines, msg.color)
-- TODO: display the logo
print(msg.text, 6, 1, "#FFFFFF")
gfx.camera(prev.x, prev.y)
end
end

0 comments on commit d105f6c

Please sign in to comment.