HexCardsClient/modifiers/slot/slot.wren
2021-05-23 19:43:54 +02:00

59 lines
1.5 KiB
Text

import "luxe: io" for IO
import "luxe: world" for World, Entity, Modifiers, ModifierSystem, Transform
import "utils/hex" for Hex
//User facing API
//This is what the user of your modifier will interact with
class Slot {
static create(entity) { Modifiers.create(This, entity) }
static destroy(entity) { Modifiers.destroy(This, entity) }
static has(entity) { Modifiers.has(This, entity) }
} //Slot
//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 SlotSystem is ModifierSystem {
construct new() {
//called when your system is first created.
}
init(world) {
_world = world
//called when your modifier is created in a world
}
destroy() {
//called when your modifier is removed from a world
}
attach(entity, data) {
//called when attached to an entity
}
detach(entity, data) {
//called when detached from an entity, like on destroy
}
tick(delta) {
if(!World.tag_has(_world, "edit")) return //only in editor pls
//called usually once every frame.
//called when the world that this modifier lives in, is ticked
each {|entity, data|
var pos = Transform.get_pos(entity)
var coord = Hex.pos_to_coord(pos, 50) //todo: get scale from field
coord = Hex.round(coord)
pos = Hex.coord_to_pos(coord, 50)
Transform.set_pos(entity, pos.x, pos.y)
data.coord = coord
}
} //tick
} //SlotSystem
var Modifier = SlotSystem //required