import "luxe: io" for IO import "luxe: world" for World, Entity, Modifiers, ModifierSystem, Transform, Sprite import "math/vector" for Vector import "math/util" for Util import "globals" for Globals import "luxe: assets" for Strings import "luxe: input" for Input, MouseButton //User facing API //This is what the user of your modifier will interact with class Human { static create(entity) { Modifiers.create(This, entity) } static destroy(entity) { Modifiers.destroy(This, entity) } static has(entity) { Modifiers.has(This, entity) } static set_color(entity, color){ var data = Modifiers.get(This, entity) data.color = color if(Sprite.has(entity)){ Sprite.set_color(entity, color.r, color.g, color.b, color.a) } } static set_name(entity, name){ var data = Modifiers.get(This, entity) Strings.add(name) data.name = name } static get_name(entity){ if(entity == 0 || !entity) return null var data = Modifiers.get(This, entity) return Strings.get(data.name) } static get_color(entity){ if(entity == 0 || !entity) return null var data = Modifiers.get(This, entity) return data.color } static get_adventure_count(entity){ if(entity == 0 || !entity) return null var data = Modifiers.get(This, entity) return data.adventure_count } static increase_adventure_count(entity){ var data = Modifiers.get(This, entity) data.adventure_count = data.adventure_count + 1 } } //Human //Your modifier system implementation. //This speaks to the engine and your user facing API //to do the actual work. You'll get notified when things change //in the world and respond to them here. class HumanSystem is ModifierSystem { player_start{[26, 89]} player_size{[10, 12]} construct new() { //called when your system is first created. } init(world) { _world = world //called when your modifier is created in a world _material = Util.material_from_image_path("assets/wip/Human") } destroy() { //called when your modifier is removed from a world } attach(entity, data) { //called when attached to an entity update() } detach(entity, data) { //called when detached from an entity, like on destroy update() } tick(delta) { if(World.tag_has(_world, "edit")) return //called usually once every frame. //called when the world that this modifier lives in, is ticked each {|entity, data| if(!data.active) return var mouse = Globals["GameMouse"] var over = Sprite.contains(entity,mouse.x, mouse.y) if(over){ if(_hoverEnt != entity){ _hoverEnt = entity Globals["Tooltip"].set(Strings.get(data.name), entity) } } if(!over && _hoverEnt == entity){ _hoverEnt = null Globals["Tooltip"].clear(entity) } } if(Input.mouse_state_pressed(MouseButton.left)){ var game = Globals["Game"] if(_hoverEnt){ //remove if statement to allow clicking away (probably needs extra code to allow ui clicking) game.Focus.value = _hoverEnt } } } //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.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 var Modifier = HumanSystem //required import "blocks/ui/ui" for Ui //import at the end in case of cyclic dependency