summaryrefslogtreecommitdiff
path: root/client/data/init.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2019-01-27 10:32:09 -0500
committerAlexander Pickering <alex@cogarr.net>2019-01-27 10:32:09 -0500
commit0aae46ecc38005236210f7e243f02cac39ab1dc3 (patch)
treee2fcc9893df4ff03a87e113b3c0ff89357c86ef7 /client/data/init.lua
downloadhome_text_adventure-0aae46ecc38005236210f7e243f02cac39ab1dc3.tar.gz
home_text_adventure-0aae46ecc38005236210f7e243f02cac39ab1dc3.tar.bz2
home_text_adventure-0aae46ecc38005236210f7e243f02cac39ab1dc3.zip
Inital commit
Diffstat (limited to 'client/data/init.lua')
-rw-r--r--client/data/init.lua176
1 files changed, 176 insertions, 0 deletions
diff --git a/client/data/init.lua b/client/data/init.lua
new file mode 100644
index 0000000..d6ec4f0
--- /dev/null
+++ b/client/data/init.lua
@@ -0,0 +1,176 @@
+math.randomseed(os.time())
+function assertf(bool,fmt,...)
+ assert(bool,string.format(fmt,unpack({...})))
+end
+function printf(fmt,...)
+ print(string.format(fmt,unpack({...})))
+end
+-- Override tostring to display more info about the table
+--local old_tostring = tostring
+--local numtabs = 0
+--function tostring(el)
+ --if type(el) == "table" then
+ --numtabs = numtabs + 1
+ --local strbuilder = {"{"}
+ --for k,v in pairs(el) do
+ --strbuilder[#strbuilder + 1] = string.format("%s%s : %s", string.rep("\t",numtabs), tostring(k), tostring(v))
+ --end
+ --strbuilder[#strbuilder + 1] = "}"
+ --numtabs = numtabs - 1
+ --return table.concat(strbuilder,"\n")
+ --end
+ --return old_tostring(el)
+--end
+
+
+local w,h = scrw(),scrh()
+--gui elements
+local textlabel = gui.newlabel({{20,0},{w-20,h - 80}},"")
+local hintbox = gui.newlabel({{20,h-80},{w-20,h-40}},"")
+local cmdbox = gui.neweditbox({{20,h-40},{w-50,h-20}})
+local cmdbut = gui.newbutton({{w-50,h-40},{w-20,h-20}},"->")
+local fail_hint_tex = video.newtexturefromfile("../data/res/fail_hint_box.png")
+local fail_hint_guiimg = gui.newiguiimage({w,h-200},true,fail_hint_tex)
+local faillabel = gui.newlabel({{w + 30,h-180},{w+220,h-100}},"")
+multibox = gui.neweditbox({{20,h/2},{w-20,h-100}},"")
+multibox:set_multiline(true)
+multibox:setvisible(false)
+multibox_donebut = gui.newbutton({{w-100,h-100},{w-20,h-80}},"Done")
+multibox_donebut:setvisible(false)
+--width=200,height=120
+
+function out(text)
+ local prev = textlabel:gettext()
+ textlabel:settext(prev .. "\n" .. text)
+end
+function cls()
+ textlabel:settext("")
+end
+function set_hints(...)
+ local t = table.concat({...},"\t")
+ hintbox:settext(t)
+end
+function enable_multibox(bool)
+ multibox:settext("")
+ multibox_donebut:setvisible(bool)
+ multibox:setvisible(bool)
+end
+function get_multibox()
+ return multibox
+end
+function get_multibox_donebut()
+ return multibox_donebut
+end
+function clear_cmdbox()
+ cmdbox:settext("")
+end
+
+local cmd_hooks = {}
+function add_cmdbox_hook(func)
+ table.insert(cmd_hooks,func)
+end
+local fail_anim = 0
+local fail_queue = {}
+function fail_hint(...)
+ fail_queue[#fail_queue + 1] = table.concat({...})
+end
+function fail_hintf(fmt,...)
+ s = string.format(fmt,unpack({...}))
+ fail_hint(s)
+end
+
+function GAME.drawPostGui()
+ if fail_anim > 0 then
+ if fail_anim < 11 then
+ fail_hint_guiimg:move({30,0})
+ faillabel:move({30,0})
+ end
+ fail_anim = fail_anim - 1
+ if fail_anim == 0 then
+ for i = 1,#fail_queue do
+ fail_queue[i] = fail_queue[i + 1]
+ end
+ end
+ else
+ if #fail_queue > 0 then
+ fail_anim = 100
+ fail_hint_guiimg:move({-300,0})
+ faillabel:settext(fail_queue[1])
+ faillabel:move({-300,0})
+ end
+ end
+end
+
+
+local cmds
+cmdbox.onChange = function()
+ for k,v in pairs(cmd_hooks) do
+ v(cmdbox)
+ end
+end
+
+--function command_over(text)
+--end
+
+local function run_command()
+ print("Got command")
+ local command = cmdbox:gettext()
+ local parts = {}
+ for word in string.gmatch(command,"([^%s]+)") do
+ parts[#parts + 1] = word
+ end
+ print("Command parts:")
+ for k,v in pairs(parts) do
+ print(k,":",v)
+ end
+ local root = parts[1]
+ for i = 1,#parts do --Remove the first part from the command.
+ parts[i] = parts[i + 1]
+ end
+ if command_over then
+ command_over(command)
+ else
+ if cmds[root] then
+ print("found command, calling with:")
+ for k,v in pairs(parts) do
+ print(k,":",v)
+ end
+ cmds[root](unpack(parts))
+ cmdbox:settext("")
+ print("Done calling command")
+ else
+ fail_hintf("Unkown command: %s",root)
+ end
+ end
+end
+
+--multibox_donebut.onClick = function(self)
+ --print("Ran multibutton click command")
+ --print("Over multibut click:", over_multibut_click)
+ --if over_multibut_click then
+ --over_multibut_click(self)
+ --end
+--end
+cmdbox.onEnter = run_command
+cmdbut.onClick = run_command
+
+GAME.setbackgroundcolor({224,248,208})
+local world = require("world")
+local locations = require("locations")
+print("about to load localplayer")
+print("done loading localplayer")
+require("loc_city")
+require("loc_beach")
+require("loc_forest")
+require("loc_mountains")
+require("loc_fields")
+local player = require("localplayer")
+require("interface")
+cmds = require("commands")
+
+
+--local house = require("house")
+--local save = require("save")
+--local nhouse = house.create_new(text)
+--local house_data = save.table_to_string(nhouse)
+--print("Made house:",house_data)