2020-08-29 19:25:16 +00:00
|
|
|
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
|
2020-09-03 15:31:23 +00:00
|
|
|
import "globals" for Globals
|
|
|
|
|
import "luxe: assets" for Strings
|
2020-09-06 13:05:13 +00:00
|
|
|
import "luxe: input" for Input, MouseButton
|
2020-09-06 13:18:43 +00:00
|
|
|
|
2020-08-29 19:25:16 +00:00
|
|
|
//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)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-04 12:44:45 +00:00
|
|
|
static set_name(entity, name){
|
|
|
|
|
var data = Modifiers.get(This, entity)
|
2020-09-09 14:12:39 +00:00
|
|
|
Strings.add(name)
|
|
|
|
|
data.name = name
|
2020-09-04 12:44:45 +00:00
|
|
|
}
|
2020-08-29 19:25:16 +00:00
|
|
|
|
2020-09-06 13:05:13 +00:00
|
|
|
static get_name(entity){
|
|
|
|
|
if(entity == 0 || !entity) return null
|
|
|
|
|
var data = Modifiers.get(This, entity)
|
2020-09-06 15:45:33 +00:00
|
|
|
return Strings.get(data.name)
|
2020-09-06 13:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static get_color(entity){
|
|
|
|
|
if(entity == 0 || !entity) return null
|
|
|
|
|
var data = Modifiers.get(This, entity)
|
|
|
|
|
return data.color
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 05:21:12 +00:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-31 14:13:18 +00:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-29 19:25:16 +00:00
|
|
|
} //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 {
|
2020-08-30 08:31:57 +00:00
|
|
|
player_start{[26, 89]}
|
2020-08-29 19:25:16 +00:00
|
|
|
player_size{[10, 12]}
|
|
|
|
|
|
2020-12-21 08:40:06 +00:00
|
|
|
dictionaries{_dictionaries}
|
|
|
|
|
|
2020-08-29 19:25:16 +00:00
|
|
|
construct new() {
|
|
|
|
|
//called when your system is first created.
|
2020-12-21 08:40:06 +00:00
|
|
|
_dictionaries = {}
|
2020-08-29 19:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2020-09-09 14:12:39 +00:00
|
|
|
if(World.tag_has(_world, "edit")) return
|
|
|
|
|
|
2020-09-06 15:04:34 +00:00
|
|
|
//called usually once every frame.
|
|
|
|
|
//called when the world that this modifier lives in, is ticked
|
2020-08-29 19:25:16 +00:00
|
|
|
each {|entity, data|
|
2020-09-03 15:31:23 +00:00
|
|
|
if(!data.active) return
|
|
|
|
|
|
|
|
|
|
var mouse = Globals["GameMouse"]
|
|
|
|
|
var over = Sprite.contains(entity,mouse.x, mouse.y)
|
2020-09-06 13:05:13 +00:00
|
|
|
if(over){
|
|
|
|
|
if(_hoverEnt != entity){
|
|
|
|
|
_hoverEnt = entity
|
|
|
|
|
Globals["Tooltip"].set(Strings.get(data.name), entity)
|
|
|
|
|
}
|
2020-09-03 15:31:23 +00:00
|
|
|
}
|
|
|
|
|
if(!over && _hoverEnt == entity){
|
|
|
|
|
_hoverEnt = null
|
|
|
|
|
Globals["Tooltip"].clear(entity)
|
|
|
|
|
}
|
2020-08-29 19:25:16 +00:00
|
|
|
}
|
2020-09-06 15:04:34 +00:00
|
|
|
|
|
|
|
|
if(Input.mouse_state_pressed(MouseButton.left)){
|
|
|
|
|
var game = Globals["Game"]
|
2020-09-18 16:48:07 +00:00
|
|
|
if(_hoverEnt){ //remove if statement to allow clicking away (probably needs extra code to allow ui clicking)
|
2020-10-04 16:35:12 +00:00
|
|
|
game.focus.value = _hoverEnt
|
2020-09-06 15:04:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-31 14:13:18 +00:00
|
|
|
|
|
|
|
|
update() //optimisation: consider running this less often
|
2020-08-29 19:25:16 +00:00
|
|
|
} //tick
|
|
|
|
|
|
|
|
|
|
update(){
|
|
|
|
|
var size = Vector.new(player_size)
|
2020-09-03 15:31:23 +00:00
|
|
|
var pos = Vector.new(player_start) + size / 2
|
2020-08-29 19:25:16 +00:00
|
|
|
each {|entity, data|
|
|
|
|
|
if(!data.active){
|
2020-10-31 14:13:18 +00:00
|
|
|
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
|
2020-08-29 19:25:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //HumanSystem
|
|
|
|
|
|
|
|
|
|
var Modifier = HumanSystem //required
|
2020-09-06 15:04:34 +00:00
|
|
|
|
2021-02-08 17:56:19 +00:00
|
|
|
import "blocks/ui/ui" for Ui //import at the end in case of cyclic dependency
|