diff --git a/Luxe/blocks/adventures.wren b/Luxe/blocks/adventures.wren index 4f5b33b..6da0b1f 100644 --- a/Luxe/blocks/adventures.wren +++ b/Luxe/blocks/adventures.wren @@ -31,11 +31,18 @@ class Adventure{ adventurers{_adventurers} resources{_resources} data{_data} + direction{_direction} + direction=(dir){_direction = dir} + distance{_distance} + distance=(dist){_distance = dist} construct new(){ _adventurers = [] _resources = [] _data = {} + + _direction = 0 + _distance = 0 } add_adventurer(adventurer){ diff --git a/Luxe/blocks/ui/adventure.wren b/Luxe/blocks/ui/adventure.wren index 66e15ab..0885f22 100644 --- a/Luxe/blocks/ui/adventure.wren +++ b/Luxe/blocks/ui/adventure.wren @@ -16,6 +16,7 @@ import "math/observable" for Observable import "blocks/ui/simple_text" for UISimpleText import "blocks/ui/ui" for Ui import "blocks/ui/compass" for UiCompass +import "math/math" for M class UiAdventure{ root{_root} @@ -85,9 +86,37 @@ class UiAdventure{ var compass = UiCompass.create(_ent) Control.child_add(page, compass) Control.set_size(compass, 32, 32) + var steps = 16 //compass steps + var step_names = ["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"] + var full_step_names = step_names.map{|short| + var shorts = "NESW" + var base_directions = ["north","east","south","west"] + if(short.count == 1){ + return base_directions[shorts.indexOf(short)] + } else if(short.count == 2) { + return base_directions[shorts.indexOf(short[0])] + + base_directions[shorts.indexOf(short[1])] + } else { //assume 3 + return base_directions[shorts.indexOf(short[0])] + "-" + + base_directions[shorts.indexOf(short[1])] + + base_directions[shorts.indexOf(short[2])] + } + }.toList + + _game.adventures.planning.on_change(true){|val| + if(val == null) return + var angle = val.direction * 360 / steps + UiCompass.set_angle(compass, angle) + } + Control.set_events(compass){|event| if(event.type == UIEvent.change){ - System.print(event) + var angle = event.change + + var angleIndex = M.repeat((steps * angle / 360).round, steps) + var adventure = _game.adventures.planning + adventure.value.direction = angleIndex + adventure.emit() } } } diff --git a/Luxe/blocks/ui/compass.wren b/Luxe/blocks/ui/compass.wren index f98f066..cf13392 100644 --- a/Luxe/blocks/ui/compass.wren +++ b/Luxe/blocks/ui/compass.wren @@ -48,7 +48,6 @@ class UiCompass{ var center = [x + w/2, y + h/2] var diff = [center.x - event.x, center.y - event.y] var angle = Math.atan2(diff.x, diff.y) - System.print("change %(Math.degrees(angle).round)") UI.events_emit(control, UIEvent.change, Math.degrees(angle)) } } diff --git a/Luxe/math/math.wren b/Luxe/math/math.wren index e2723e9..d14888f 100644 --- a/Luxe/math/math.wren +++ b/Luxe/math/math.wren @@ -48,6 +48,14 @@ class M{ return result } + static repeat(number, min, max){ + return min + repeat(number, max - min) + } + + static repeat(number, max){ + return max.sign * ((number % max + max) % max) + } + static remap(min_in, max_in, min_out, max_out, value){ var inter = inv_lerp(min_in, max_in, value) return lerp(min_out, max_out, inter)