65 lines
1.5 KiB
Plaintext
65 lines
1.5 KiB
Plaintext
import "fpkit: system/player_interaction.modifier.api" for API, Modifier, APIGet, APISet, Wire, Fields, State, Op
|
|
import "luxe: io" for IO
|
|
import "luxe: assets" for Assets, Strings
|
|
import "luxe: input" for Input
|
|
import "luxe: system/camera.modifier" for Camera
|
|
import "luxe: world" for Entity, World
|
|
import "luxe.project/asset" for Asset
|
|
|
|
#block = data
|
|
class Data {
|
|
var event_name: String = "interact"
|
|
var distance: Num = 2
|
|
|
|
#hidden
|
|
var is_active: Bool = true
|
|
|
|
#hidden
|
|
var camera: Link = null
|
|
}
|
|
|
|
#api
|
|
#display = "FPKit: Player Interaction"
|
|
#desc = "**Lets player use interactive entities**. Handles events when the player looks at, looks away from, or presses the Use key on an entity."
|
|
#icon = "luxe: image/modifier/modifier.svg"
|
|
class PlayerInteraction is API {
|
|
//add public facing API here
|
|
}
|
|
|
|
#system
|
|
#phase(on, tick)
|
|
class System is Modifier {
|
|
|
|
//required atm
|
|
construct new(world: World) { super(world) }
|
|
|
|
init(world: World) {
|
|
Log.print("init `%(This)` in world `%(world)`")
|
|
}
|
|
|
|
#hidden
|
|
attach(entity: Entity, data: Data) {
|
|
Log.print("attached to `%(Entity.name(entity))` `%(entity)` - `%(This)`")
|
|
var camera = Entity.get_with(entity, Camera.id)
|
|
Log.print(" Camera Found: %(camera != null)")
|
|
|
|
// data.camera = camera
|
|
}
|
|
|
|
#hidden
|
|
detach(entity: Entity, data: Data) {
|
|
Log.print("detached from `%(Entity.name(entity))` `%(entity)` - `%(This)`")
|
|
}
|
|
|
|
#hidden
|
|
tick(delta: Num) {
|
|
each {|entity: Entity, data: Data|
|
|
if (!data.is_active) return
|
|
|
|
if (Input.event_began(data.event_name)) {
|
|
Log.print("[[ USE ]]")
|
|
}
|
|
}
|
|
}
|
|
|
|
} |