From a3e22101956cb9410d12ca8d7f1214f400fa0189 Mon Sep 17 00:00:00 2001 From: Ronja Date: Sat, 31 Oct 2020 15:13:18 +0100 Subject: [PATCH] correctly hide humans --- Luxe/blocks/human/human.wren | 40 +++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/Luxe/blocks/human/human.wren b/Luxe/blocks/human/human.wren index 679499e..28aa0e5 100644 --- a/Luxe/blocks/human/human.wren +++ b/Luxe/blocks/human/human.wren @@ -50,6 +50,18 @@ class Human { data.adventure_count = data.adventure_count + 1 } + static get_active(entity){ + if(entity == 0 || !entity) return null + var data = Modifiers.get(This, entity) + return data.active + } + + static set_active(entity, active){ + if(entity == 0 || !entity) return null + var data = Modifiers.get(This, entity) + data.active = active + } + } //Human //Your modifier system implementation. @@ -114,28 +126,28 @@ class HumanSystem is ModifierSystem { game.focus.value = _hoverEnt } } + + update() //optimisation: consider running this less often } //tick update(){ - if(World.tag_has(_world, "edit")) return - var size = Vector.new(player_size) var pos = Vector.new(player_start) + size / 2 each {|entity, data| if(!data.active){ - Transform.destroy(entity) - Sprite.destroy(entity) - return + if(Transform.has(entity))Transform.destroy(entity) + if(Sprite.has(entity))Sprite.destroy(entity) + } else { + if(!Transform.has(entity)){ + Transform.create(entity) + } + if(!Sprite.has(entity)){ + Sprite.create(entity, _material, 10, 12) + Sprite.set_color(entity, data.color.r, data.color.g, data.color.b, data.color.a) + } + Transform.set_pos(entity, pos.x, pos.y) + pos.x = pos.x + size.x } - if(!Transform.has(entity)){ - Transform.create(entity) - } - if(!Sprite.has(entity)){ - Sprite.create(entity, _material, 10, 12) - Sprite.set_color(entity, data.color.r, data.color.g, data.color.b, data.color.a) - } - Transform.set_pos(entity, pos.x, pos.y) - pos.x = pos.x + size.x } } } //HumanSystem