aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2019-10-15 21:10:21 +0000
committers-ol <s-ol@users.noreply.github.com>2019-10-15 21:10:21 +0000
commitd25e3bf63e843c54feb9eb7206471195e44a6c01 (patch)
tree11dfc432e47b538e093de26799ff8a5591d47850
downloadwatch-cad-d25e3bf63e843c54feb9eb7206471195e44a6c01.tar.gz
watch-cad-d25e3bf63e843c54feb9eb7206471195e44a6c01.zip
initial commit
-rw-r--r--conf.lua49
-rw-r--r--init.moon216
-rw-r--r--main.lua2
3 files changed, 267 insertions, 0 deletions
diff --git a/conf.lua b/conf.lua
new file mode 100644
index 0000000..536364f
--- /dev/null
+++ b/conf.lua
@@ -0,0 +1,49 @@
+function love.conf(t)
+ t.identity = nil -- The name of the save directory (string)
+ t.appendidentity = false -- Search files in source directory before save directory (boolean)
+ t.version = "11.0" -- The LÖVE version this game was made for (string)
+ t.console = false -- Attach a console (boolean, Windows only)
+ t.accelerometerjoystick = true -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean)
+ t.externalstorage = false -- True to save files (and read from the save directory) in external storage on Android (boolean)
+ t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean)
+
+ t.audio.mixwithsystem = true -- Keep background music playing when opening LOVE (boolean, iOS and Android only)
+
+ t.window.title = "Untitled" -- The window title (string)
+ t.window.icon = nil -- Filepath to an image to use as the window's icon (string)
+ t.window.width = 800 -- The window width (number)
+ t.window.height = 600 -- The window height (number)
+ t.window.borderless = false -- Remove all border visuals from the window (boolean)
+ t.window.resizable = false -- Let the window be user-resizable (boolean)
+ t.window.minwidth = 1 -- Minimum window width if the window is resizable (number)
+ t.window.minheight = 1 -- Minimum window height if the window is resizable (number)
+ t.window.fullscreen = false -- Enable fullscreen (boolean)
+ t.window.fullscreentype = "desktop" -- Choose between "desktop" fullscreen or "exclusive" fullscreen mode (string)
+ t.window.vsync = 0 -- Vertical sync mode (number)
+ t.window.msaa = 0 -- The number of samples to use with multi-sampled antialiasing (number)
+ t.window.depth = nil -- The number of bits per sample in the depth buffer
+ t.window.stencil = nil -- The number of bits per sample in the stencil buffer
+ t.window.display = 1 -- Index of the monitor to show the window in (number)
+ t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
+ t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
+ t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
+
+ t.modules.audio = true -- Enable the audio module (boolean)
+ t.modules.data = true -- Enable the data module (boolean)
+ t.modules.event = true -- Enable the event module (boolean)
+ t.modules.font = true -- Enable the font module (boolean)
+ t.modules.graphics = true -- Enable the graphics module (boolean)
+ t.modules.image = true -- Enable the image module (boolean)
+ t.modules.joystick = true -- Enable the joystick module (boolean)
+ t.modules.keyboard = true -- Enable the keyboard module (boolean)
+ t.modules.math = true -- Enable the math module (boolean)
+ t.modules.mouse = true -- Enable the mouse module (boolean)
+ t.modules.physics = true -- Enable the physics module (boolean)
+ t.modules.sound = true -- Enable the sound module (boolean)
+ t.modules.system = true -- Enable the system module (boolean)
+ t.modules.thread = true -- Enable the thread module (boolean)
+ t.modules.timer = true -- Enable the timer module (boolean), Disabling it will result 0 delta time in love.update
+ t.modules.touch = true -- Enable the touch module (boolean)
+ t.modules.video = true -- Enable the video module (boolean)
+ t.modules.window = true -- Enable the window module (boolean)
+end
diff --git a/init.moon b/init.moon
new file mode 100644
index 0000000..e61e1fb
--- /dev/null
+++ b/init.moon
@@ -0,0 +1,216 @@
+print "scratch buffer is #{file}"
+lfs = require 'lfs'
+require 'moon.all'
+
+love.timer = nil
+
+{ graphics: lg, mouse: lm } = love
+
+red = { 1, 0, 0 }
+turk = { 0, 1, 1 }
+orng = { .6, .5, 0 }
+gren = { 0, .8, 0 }
+
+rect = (x, y, w, h, opts={mode: 'line'}) ->
+ lg.setColor opts.color if opts.color
+ lg.rectangle opts.mode, x, y, w, h
+
+ mx, my = lm.getPosition!
+ (lm.isDown 1) and x < mx and x + w > mx and y < my and y + h > my
+
+export ^
+COMMIT = false
+
+Move = (obj, x, y) ->
+ if COMMIT
+ obj.x = x
+ obj.y = y
+ return
+
+ lg.setColor orng
+ lg.line x + obj.w/2, y + obj.h/2, obj\center!
+ obj = obj\clone!
+ obj.x = x
+ obj.y = y
+ obj\draw 'line', orng
+
+Add = (obj) ->
+ if COMMIT
+ table.insert OBJS, obj
+ return
+
+ obj\draw 'line', gren
+
+Select_objs = (match) =>
+ if not @selection
+ @selection = {o for o in *OBJS when match and o.name\match match}
+
+ lg.push 'all'
+ lg.setLineWidth 5
+ for obj in *OBJS
+ selected = @selection[obj]
+ if selected
+ obj\draw 'line', orng
+
+ if obj\hit!
+ @selection[obj] = if selected then nil else obj
+
+ lg.pop!
+
+ [o for o in pairs @selection]
+
+Select_rect = =>
+ { :x, :y, :w, :h } = @rect or { x: 222, y: 200, w: 400, h: 200 }
+
+ opts = mode: 'line', color: turk
+ rect x, y, w, h, opts
+
+ if rect x, y, 30, 30, opts
+ dx, dy = lm.getDelta!
+ x += dx
+ y += dy
+ w -= dx
+ h -= dy
+ if rect x + w - 30, y + h - 30, 30, 30, opts
+ dx, dy = lm.getDelta!
+ w += dx
+ h += dy
+
+ @rect = { :x, :y, :w, :h }
+ @rect
+
+
+Select_circle = (cx, cy) =>
+ @circ or= do
+ r = math.random! * 100 + 50
+ a = math.random! * math.pi * 2 * 50 + 50
+ hx, hy = r * math.cos(a), r * math.sin(a)
+ { cx: 150, cy: 150, :hx, :hy, :r }
+
+ { :r, :hx, :hy } = @circ
+ if cx and cy
+ @fix_center = true
+ else
+ { :cx, :cy } = @circ
+
+ lg.setColor turk
+ lg.circle 'line', cx, cy, r
+
+ opts = color: turk, mode: 'line'
+
+ if not @fix_center
+ if rect cx - 15, cy - 15, 30, 30, opts
+ dx, dy = lm.getDelta!
+ cx += dx
+ cy += dy
+
+ if rect cx + hx - 15, cy + hy - 15, 30, 30
+ dx, dy = lm.getDelta!
+ hx += dx
+ hy += dy
+
+
+ @circ = { :cx, :cy, :hx, :hy, r: math.sqrt hx*hx + hy*hy }
+ @circ
+
+update_script = do
+ file = arg[2]
+ last_mod = 0
+ last_script = ->
+
+ wrapper = () ->
+ ok, err = pcall last_script
+
+ if ok and 'function' != type err
+ ok = false
+ err = 'script did not return a function'
+
+ if not ok
+ print "--- ERROR EXECUTING SCRIPT: ---"
+ print err
+ return
+
+ ok, err = pcall err, STATE
+ if not ok
+ print "--- ERROR EXECUTING SCRIPT: ---"
+ print err
+
+ print "watching '#{file}'..."
+ ->
+ mod = lfs.attributes file, 'modification'
+ if last_mod < mod
+ last_mod = mod
+ script, err = loadfile file
+ if script
+ last_script = script
+ else
+ print "--- ERROR PARSING SCRIPT: ---"
+ print err
+
+ wrapper
+
+
+class Object
+ new: (@name, @x, @y, @w=60, @h=30) =>
+
+ center: =>
+ @x + @w/2, @y + @h/2
+
+ draw: (mode, color) =>
+ rect @x, @y, @w, @h, :mode, :color
+
+ clone: =>
+ Object "", @x, @y, @w, @h
+
+ hit: =>
+ mx, my = lm.getPosition!
+ (lm.justDown!) and @x < mx and @x + @w > mx and @y < my and @y + @h > my
+
+OBJS = {
+ Object 'led-1', 50, 50
+ Object 'led-2', 50, 150
+ Object 'led-3', 150, 50
+ Object 'led-3', 250, 150
+ Object 'btn', 150, 150, 40, 40
+}
+
+lm.doesHit = (x, y, w, h) ->
+ mx, my = lm.getPosition!
+
+mkstate = -> setmetatable {}, __index: (t, k) ->
+ with val = {}
+ rawset t, k, val
+STATE = mkstate!
+
+commit = ->
+ COMMIT = true
+ print "COMMITTING"
+ script = update_script!
+ script!
+ STATE = mkstate!
+ COMMIT = false
+
+local last_mx, last_my, last_down
+love.draw = ->
+ script = update_script!
+
+ for obj in *OBJS
+ obj\draw 'fill', red
+
+ script!
+
+ last_mx, last_my = lm.getPosition!
+ last_down = lm.isDown 1
+
+love.keypressed = (key) ->
+ if key == 'return'
+ commit!
+ if key == 'escape'
+ STATE = mkstate!
+
+lm.justDown = ->
+ (lm.isDown 1) and not last_down
+
+lm.getDelta = ->
+ mx, my = lm.getPosition!
+ mx - last_mx, my - last_my
diff --git a/main.lua b/main.lua
new file mode 100644
index 0000000..6cbdaf0
--- /dev/null
+++ b/main.lua
@@ -0,0 +1,2 @@
+require 'moonscript'
+require 'init'