diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2019-11-19 21:24:49 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2019-11-19 21:24:49 +0000 |
| commit | 9e6414f9a10e32759ee1ecfaffbc8d8f7bc9fc13 (patch) | |
| tree | 92e4c221aac288353e76c0f48b5c4a46f898056c /session.moon | |
| parent | add keyboard capturing to input (diff) | |
| download | watch-cad-9e6414f9a10e32759ee1ecfaffbc8d8f7bc9fc13.tar.gz watch-cad-9e6414f9a10e32759ee1ecfaffbc8d8f7bc9fc13.zip | |
add EX mode, script name display
Diffstat (limited to 'session.moon')
| -rw-r--r-- | session.moon | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/session.moon b/session.moon index 7549b91..da22d80 100644 --- a/session.moon +++ b/session.moon @@ -1,6 +1,8 @@ lfs = require 'lfs' +utf8 = require 'utf8' moon = require 'moonscript.base' +{ graphics: lg } = love trace = (msg) -> debug.traceback msg, 2 class Script @@ -65,10 +67,25 @@ class Script import Object from require 'object' class Session - new: (@script) => + FONTSIZE = 20 + new: (scriptfile) => @objects = {} for i=1,4 - table.insert @objects, Object nil, random.size!/8 + print + -- table.insert @objects, Object nil, random.size!/8 + + if scriptfile + @script = Script scriptfile + + @font = lg.newFont 'font/FantasqueSansMono-Regular.ttf', 20 + @ex = false + + exec: (command) => + switch command\match '^(%w+)' + when 'quit' + love.event.quit! + when 'run' + @script = Script command\match '^run%s+(.+)' frame: => for obj in *@objects @@ -77,12 +94,31 @@ class Session if INPUT\key_down 'escape' STATE\reset! - @script\reload_and_run! + w,h = lg.getDimensions! + lg.setFont @font - if INPUT\key_down 'space' - @script\commit! - STATE\reset! + if @script + @script\reload_and_run! + + if INPUT\key_down 'space' + @script\commit! + STATE\reset! + + lg.print "script: #{@script.file}", 10, 10 + + if (INPUT\key_down ':') or (INPUT\key_down ';') and INPUT\key_held 'lshift' + INPUT\text_capture! + @ex = true + + if @ex + lg.print ":#{INPUT.text}", 10, h - 10 - FONTSIZE + + apply = INPUT\key_down 'return' + input = if apply or INPUT\key_down 'escape' + @ex = nil + apply and @exec INPUT\text_release! + @exec input if input { :Script |
