diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2019-11-03 16:00:33 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2019-11-03 16:01:13 +0000 |
| commit | 16d2531c64fbea1f9ad5f9ca23cac65da47b4aba (patch) | |
| tree | 0ae925f1eeb262be0b1f8421dc707aea60bc29d4 | |
| parent | add input spec (diff) | |
| download | watch-cad-16d2531c64fbea1f9ad5f9ca23cac65da47b4aba.tar.gz watch-cad-16d2531c64fbea1f9ad5f9ca23cac65da47b4aba.zip | |
update/fix API
| -rw-r--r-- | api.moon | 83 | ||||
| -rw-r--r-- | examples/demo.moon | 24 | ||||
| -rw-r--r-- | session.moon | 12 |
3 files changed, 65 insertions, 54 deletions
@@ -5,7 +5,7 @@ import is_once, is_live, are_live, Once from require 'state' random = point: -> - w, h = love.graphics.getDimensions! + w, h = lg.getDimensions! vec2 w*math.random!, h*math.random! size: -> @@ -45,73 +45,64 @@ draw = half_handle = vec2 15, 15 input = point: (fixed={}) => - if vec = is_once fixed - fixed = { - x: Once vec.x - y: Once vec.y - } + last = @init random.point! + pos = last\clone! - init = random.point! - @store 'x', fixed.x, init.x - @store 'y', fixed.y, init.y - pos = vec2 @x, @y + live_x, live_y = (is_live fixed.x), is_live fixed.y + + pos.x = fixed.x if live_x + pos.y = fixed.y if live_y -- both values are 'live', no UI necessary - if are_live fixed.x, fixed.y + if live_x and live_y draw.cross pos - return pos + @set pos + delta = pos - last + return delta\len2! > 0 and delta + -- handle size (square or rect) hh = half_handle\clone! - hh.x /= 2 if is_live fixed.x - hh.y /= 2 if is_live fixed.y + hh.x /= 2 if live_x + hh.y /= 2 if live_y - @init 'drag', false if 'down' == draw.rect pos - hh, pos + hh - @drag = true - - if @drag - @drag = false if INPUT\mouse_up! - - pos += INPUT\mouse_delta! - - @store 'x', pos.x unless is_live fixed.x - @store 'y', pos.y unless is_live fixed.y - - vec2 @x, @y + @drag\set true - point_relative_to: (other, fixed) => - assert (is_live other), "other needs to be live!" + if @drag! + if INPUT\mouse_up! + @drag\set false - @init 'last_other', other - @init 'last', fixed or random.point! - delta = other - @last_other + delta = INPUT\mouse_delta! + delta.x = 0 if live_x + delta.y = 0 if live_y + pos += delta - val = if delta\len2! > 0 and not is_live fixed - input.point @, @last + delta - else - input.point @, fixed or Once @last - - @store 'last_other', other - @store 'last', val - - val + @set pos + delta = last and pos - last + return delta and delta\len2! > 0 and delta rectangle: (fixed={}) => - min = input.point @min, fixed.min or Once random.point! * 0.8 - max = input.point_relative_to @max, min, fixed.max or Once min + random.size! + delta = input.point @min, fixed.min or Once random.point! * 0.8 + input.point @max, fixed.max or Once @min! + random.size! + @max\set @max! + delta if delta + min, max = @min!, @max! draw.rect min, max - { :min, :max } + @set { :min, :max } circle: (fixed={}) => local tangent - center = input.point @center, fixed.center + delta = input.point @center, fixed.center + radius = (is_live fixed.radius) or do radius = (is_once fixed.radius) or math.random! * 100 + 50 init_tangent = vec2.from_cartesian radius, math.random! * 2 * math.pi - tangent = input.point_relative_to @tangent, center, fixed.tangent or Once center + init_tangent - center\dist tangent + input.point @tangent, fixed.tangent or Once @center! + init_tangent + @center!\dist @tangent! + + @tangent\set @tangent! + delta if delta and tangent + center, tangent = @center!, @tangent! draw.circle center, radius { :center, :tangent, :radius } diff --git a/examples/demo.moon b/examples/demo.moon index cb2531f..2a9033c 100644 --- a/examples/demo.moon +++ b/examples/demo.moon @@ -1,7 +1,25 @@ +-- let's load a vector library for doing some +-- more interesting transformations + import vec2 from require 'cpml' => - a = input.point @point, x: 200 - rect = input.rectangle @rect, min: a + (vec2 30, 0), max: { y: 200 } + -- let's try to construct a pill-shape + input.rectangle @rect + rect = @rect! + hsize = (rect.max - rect.min) / 2 + + input.circle @left, { + center: rect.min + vec2 0, hsize.y + radius: hsize.y + } + input.circle @left, { + center: rect.min + vec2 hsize.x*2, hsize.y + radius: hsize.y + } - circle = input.circle @circ, center: rect.min, tangent: rect.max + -- right, so that's that.... + -- kinda forgetting whether there was something + -- else I wanted to show. + -- does this seem interesting to you? + -- let me know :) diff --git a/session.moon b/session.moon index 29d6f24..1edb1de 100644 --- a/session.moon +++ b/session.moon @@ -5,9 +5,8 @@ trace = (msg) -> debug.traceback msg, 2 class Script new: (@file) => - print "loading script '#{@file}'..." @last_modification = 0 - @func = -> print 'idle' + @func = -> commit: => export COMMIT @@ -15,7 +14,7 @@ class Script return unless @func - ok, msg = xpcall @func, trace, STATE.state + ok, msg = xpcall @func, trace, STATE.root if not ok @error = at: 'commit', :msg return @@ -26,7 +25,7 @@ class Script func = @reload! @func = func if func - ok, msg = xpcall @func, trace, STATE.state + ok, msg = xpcall @func, trace, STATE.root if not ok @error = at: 'exec', :msg @@ -43,7 +42,10 @@ class Script print @error.msg reload: => - modification = lfs.attributes @file, 'modification' + { :mode, :modification } = lfs.attributes @file + if mode != 'file' + @error = at: 'parse', msg: "script doesn't exist or is not a file: '#{@file}'" + return if @last_modification < modification @last_modification = modification |
