import "luxe: world" for Entity, Transform, Sprite import "luxe: containers" for Lists import "luxe: assets" for Strings import "luxe: input" for Input, MouseButton import "globals" for Globals import "math/observable" for Observable import "math/vector" for Vector import "math/util" for Util class Human{ active{_active} active=(value){ _active = value if(!__activeHumans) __activeHumans = Observable.new([]) if(value){ show() _changeToken = __activeHumans.on_change{|x| update()} __activeHumans.value.add(this) __activeHumans.emit() } else { hide() _changeToken.discard() Lists.remove(__activeHumans.value, this) __activeHumans.emit() } } name{_name} name=(value){ _name = value } adv_count{_adventure_count} entity{_entity} color=(value){ _color = value } color{_color} construct new(){ _active = false _name = "unnamed" _adventure_count = 0 color = [1, 1, 1, 1] _material = Util.material_from_image_path("assets/wip/Human") } show(){ _entity = Entity.create(Globals["Game"].app.world, name) Transform.create(_entity) Sprite.create(_entity, _material, 10, 12) Sprite.set_color(_entity, _color.r, _color.g, _color.b, _color.a) } hide(){ Entity.destroy(_entity) } update(){ var index = __activeHumans.value.indexOf(this) var pos = PlayerStart + PlayerSize.y0() / 2 + PlayerSize.y0() * index Transform.set_pos(_entity, pos.x, pos.y) } dispose(){ active = false } static tick(){ var mouse = Globals["GameMouse"] __activeHumans.value.each(){|human| var entity = human.entity var over = Sprite.contains(entity, mouse.x, mouse.y) if(over && __hoverEnt != entity){ __hoverEnt = entity Globals["Tooltip"].set(human.name, entity) } if(!over && __hoverEnt == entity){ __hoverEnt = null Globals["Tooltip"].clear(entity) } if(Input.mouse_state_pressed(MouseButton.left) && over){ var game = Globals["Game"] game.focus.value = human } } } } var PlayerStart:Vector = Vector.new(26, 89) var PlayerSize:Vector = Vector.new(10, 12)