Skip to content
Snippets Groups Projects
Commit 0e0ebb4d authored by dg's avatar dg
Browse files

small debug console, ctrl+l

git-svn-id: http://svn.net-core.org/repos/t-engine4@44 51575b47-30f0-44d4-a5cc-537603b46e54
parent 4df70631
No related branches found
No related tags found
No related merge requests found
require "engine.class"
require "engine.Dialog"
module(..., package.seeall, class.inherit(engine.Dialog))
function _M:init()
engine.Dialog.init(self, "Lua Console", core.display.size())
self.scroll = 0
self.history = {}
self.line = ""
self:keyCommands{
_RETURN = function()
table.insert(self.history, 1, self.line)
if self.line:match("^=") then self.line = "return "..self.line:sub(2) end
local f, err = loadstring(self.line)
if err then
table.insert(self.history, 1, err)
else
local res = {pcall(f)}
for i, v in ipairs(res) do
if i > 1 then
table.insert(self.history, 1, (i-1).." :=: "..tostring(v))
end
end
end
self.line = ""
self.changed = true
end,
_ESCAPE = function()
game:unregisterDialog(self)
end,
_BACKSPACE = function()
self.line = self.line:sub(1, self.line:len() - 1)
end,
__TEXTINPUT = function(c)
self.line = self.line .. c
self.changed = true
end,
}
end
function _M:drawDialog(s, w, h)
local i, dh = 1, 0
while dh < self.h do
if not self.history[self.scroll + i] then break end
s:drawString(self.font, self.history[self.scroll + i], 0, self.ih - (i + 1) * self.font:lineSkip(), 255, 255, 255)
i = i + 1
dh = dh + self.font:lineSkip()
end
s:drawString(self.font, self.line, 0, self.ih - self.font:lineSkip(), 255, 255, 255)
end
require "engine.class"
require "engine.Mouse"
require "engine.DebugConsole"
--- Represent a game
-- A module should subclass it and initialize anything it needs to play inside
......
......@@ -42,7 +42,7 @@ function _M:display()
-- Erase and the display the map
self.surface:erase(self.bgcolor[1], self.bgcolor[2], self.bgcolor[3])
local i, dh = 1, 0
while i < self.h do
while dh < self.h do
if not self.log[self.scroll + i] then break end
self.surface:drawColorString(self.font, self.log[self.scroll + i], 0, self.h - (i) * self.font_h, self.color[1], self.color[2], self.color[3])
i = i + 1
......
......@@ -2,6 +2,7 @@ require "engine.class"
require "engine.GameTurnBased"
require "engine.KeyCommand"
require "engine.LogDisplay"
local DebugConsole = require "engine.DebugConsole"
local Tooltip = require "engine.Tooltip"
local QuitDialog = require "mod.dialogs.Quit"
local Calendar = require "engine.Calendar"
......@@ -207,6 +208,10 @@ function _M:setupCommands()
[{"_x","ctrl"}] = function()
self:onQuit()
end,
-- Lua console
[{"_l","ctrl"}] = function()
self:registerDialog(DebugConsole.new())
end,
-- Targeting movement
[{"_LEFT","ctrl","shift"}] = function() self.target.target.entity=nil self.target.target.x = self.target.target.x - 1 end,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment