From a29bb4505355b1dce09545f1f87306eb87a39b87 Mon Sep 17 00:00:00 2001 From: Ronja Date: Fri, 23 Oct 2020 15:25:53 +0200 Subject: [PATCH] minor stuff that breaks something ?!? --- Luxe/assets/names.lx | 2 +- Luxe/blocks/adventures.wren | 3 ++- Luxe/blocks/resources.wren | 24 ++++++++++++++++++++++-- Luxe/blocks/tooltip.wren | 2 +- Luxe/blocks/ui/scroll_box.wren | 2 +- Luxe/math/util.wren | 23 +++++++++++++++++++++++ 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Luxe/assets/names.lx b/Luxe/assets/names.lx index 35e41d4..3d8d84c 100644 --- a/Luxe/assets/names.lx +++ b/Luxe/assets/names.lx @@ -35,7 +35,7 @@ "Mara" "Mercedes" "Merryl" - "Mii’a" + "Mii'a" "Niels" "Nina" "Rami" diff --git a/Luxe/blocks/adventures.wren b/Luxe/blocks/adventures.wren index 789910b..8a6cf4d 100644 --- a/Luxe/blocks/adventures.wren +++ b/Luxe/blocks/adventures.wren @@ -1,6 +1,7 @@ import "math/observable" for Observable import "luxe: world" for Entity, Values, Tags import "globals" for Globals +import "blocks/resources" for Resources class Adventures{ planning{_planning} @@ -45,7 +46,7 @@ class Adventure{ construct new(){ _adventurers = [] - _resources = [] + _resources = Resources.new() _data = {} _direction = 0 diff --git a/Luxe/blocks/resources.wren b/Luxe/blocks/resources.wren index 5971d32..fe74366 100644 --- a/Luxe/blocks/resources.wren +++ b/Luxe/blocks/resources.wren @@ -3,6 +3,7 @@ import "luxe: world" for Entity import "math/event" for Event import "math/observable" for Observable import "math/stringUtil" for StringUtil +import "math/util" for Actions class Resources is Observable{ @@ -47,7 +48,7 @@ class Resources is Observable{ add(resource, -amount) } - empty(resource){ + clear(resource){ var value = get(resource) if(value > 0){ //this check is to not initialize undefined resource types set(resource, 0) @@ -55,6 +56,25 @@ class Resources is Observable{ return value } + empty(resource){ + return !has(resource, 1) //returns true if resource doesn't exist or is 0 (or negative??) + } + + exists(resource){ + return _resources.containsKey(resource) + } + + removeEmpty(){ + for(key in _resources.keys){ + if(empty(key)){ + Actions.queue{ + _resources.remove(key) + } + } + } + Actions.execute() + } + tryRemove(resource, amount){ if(has(resource, amount)){ remove(resource, amount) @@ -66,6 +86,6 @@ class Resources is Observable{ has(resource, amount){ var value = _resources[resource] - return value && value >= amount //check if not null, and bigger than amount + return value && value >= amount //check if not null, and bigger/equal than amount } } \ No newline at end of file diff --git a/Luxe/blocks/tooltip.wren b/Luxe/blocks/tooltip.wren index 69380d0..bb1e8fe 100644 --- a/Luxe/blocks/tooltip.wren +++ b/Luxe/blocks/tooltip.wren @@ -51,7 +51,7 @@ class Tooltip{ var offsets = shadowOffsets for(i in 0...offsets.count){ - Transform.set_pos(_shadows[i], pos.x+offsets[i].x, pos.y+offsets[i].y, depth-10) + Transform.set_pos(_shadows[i], pos.x+offsets[i].x, pos.y+offsets[i].y, depth-5) } } } diff --git a/Luxe/blocks/ui/scroll_box.wren b/Luxe/blocks/ui/scroll_box.wren index c562029..e9a4ae5 100644 --- a/Luxe/blocks/ui/scroll_box.wren +++ b/Luxe/blocks/ui/scroll_box.wren @@ -32,7 +32,7 @@ class UiScrollBox{ UiSlider.set_value(slider, 0) Control.set_size(slider, 7, -1) UILayout.set_behave(ent, slider, UILayoutBehave.right | UILayoutBehave.vfill) //| - UILayout.set_margin(ent, slider, 1, 0, 1, 0) + UILayout.set_margin(ent, slider, -1, 0, 0, 0) Control.set_events(slider){|event| if(event.type == UIEvent.change){ var position = 0 diff --git a/Luxe/math/util.wren b/Luxe/math/util.wren index 8548f61..2608564 100644 --- a/Luxe/math/util.wren +++ b/Luxe/math/util.wren @@ -104,4 +104,27 @@ class Util{ return col.toList + [1] } +} + +class Actions{ + + static actions{ + System.print(__actions) + if(!__actions) __actions = [] + System.print(__actions) + return __actions + } + + static queue(fn){ + actions.add(fn) + System.print("actions are %(actions)") + } + + static execute(){ + actions.each{|action| + action.call() + } + actions.clear() + } + } \ No newline at end of file