Create start of PlayerInteraction modifier
This commit is contained in:
@ -80,7 +80,6 @@ class Fields {
|
|||||||
static decelleration : String { "decelleration" }
|
static decelleration : String { "decelleration" }
|
||||||
static speed_run : String { "speed_run" }
|
static speed_run : String { "speed_run" }
|
||||||
static speed_walk : String { "speed_walk" }
|
static speed_walk : String { "speed_walk" }
|
||||||
static ground_check_dist : String { "ground_check_dist" }
|
|
||||||
static jump_impulse : String { "jump_impulse" }
|
static jump_impulse : String { "jump_impulse" }
|
||||||
static jump_grace_time : String { "jump_grace_time" }
|
static jump_grace_time : String { "jump_grace_time" }
|
||||||
static event_forward : String { "event_forward" }
|
static event_forward : String { "event_forward" }
|
||||||
@ -117,7 +116,6 @@ class APIGet {
|
|||||||
decelleration(entity: Entity) : Num { Modifier.get(entity).decelleration }
|
decelleration(entity: Entity) : Num { Modifier.get(entity).decelleration }
|
||||||
speed_run(entity: Entity) : Num { Modifier.get(entity).speed_run }
|
speed_run(entity: Entity) : Num { Modifier.get(entity).speed_run }
|
||||||
speed_walk(entity: Entity) : Num { Modifier.get(entity).speed_walk }
|
speed_walk(entity: Entity) : Num { Modifier.get(entity).speed_walk }
|
||||||
ground_check_dist(entity: Entity) : Num { Modifier.get(entity).ground_check_dist }
|
|
||||||
jump_impulse(entity: Entity) : Num { Modifier.get(entity).jump_impulse }
|
jump_impulse(entity: Entity) : Num { Modifier.get(entity).jump_impulse }
|
||||||
jump_grace_time(entity: Entity) : Num { Modifier.get(entity).jump_grace_time }
|
jump_grace_time(entity: Entity) : Num { Modifier.get(entity).jump_grace_time }
|
||||||
event_forward(entity: Entity) : String { Modifier.get(entity).event_forward }
|
event_forward(entity: Entity) : String { Modifier.get(entity).event_forward }
|
||||||
@ -139,7 +137,6 @@ class APISet {
|
|||||||
decelleration(entity: Entity, value: Num) { Modifier.get(entity).decelleration = value }
|
decelleration(entity: Entity, value: Num) { Modifier.get(entity).decelleration = value }
|
||||||
speed_run(entity: Entity, value: Num) { Modifier.get(entity).speed_run = value }
|
speed_run(entity: Entity, value: Num) { Modifier.get(entity).speed_run = value }
|
||||||
speed_walk(entity: Entity, value: Num) { Modifier.get(entity).speed_walk = value }
|
speed_walk(entity: Entity, value: Num) { Modifier.get(entity).speed_walk = value }
|
||||||
ground_check_dist(entity: Entity, value: Num) { Modifier.get(entity).ground_check_dist = value }
|
|
||||||
jump_impulse(entity: Entity, value: Num) { Modifier.get(entity).jump_impulse = value }
|
jump_impulse(entity: Entity, value: Num) { Modifier.get(entity).jump_impulse = value }
|
||||||
jump_grace_time(entity: Entity, value: Num) { Modifier.get(entity).jump_grace_time = value }
|
jump_grace_time(entity: Entity, value: Num) { Modifier.get(entity).jump_grace_time = value }
|
||||||
event_forward(entity: Entity, value: String) { Modifier.get(entity).event_forward = value }
|
event_forward(entity: Entity, value: String) { Modifier.get(entity).event_forward = value }
|
||||||
|
|||||||
@ -14,7 +14,6 @@ class Data {
|
|||||||
var decelleration: Num = 0.5
|
var decelleration: Num = 0.5
|
||||||
var speed_run: Num = 25.0
|
var speed_run: Num = 25.0
|
||||||
var speed_walk: Num = 15.0
|
var speed_walk: Num = 15.0
|
||||||
var ground_check_dist: Num = 0
|
|
||||||
var jump_impulse: Num = 20
|
var jump_impulse: Num = 20
|
||||||
var jump_grace_time: Num = 0.1
|
var jump_grace_time: Num = 0.1
|
||||||
|
|
||||||
@ -25,7 +24,6 @@ class Data {
|
|||||||
var event_sprint: String = "run"
|
var event_sprint: String = "run"
|
||||||
var event_jump: String = "jump"
|
var event_jump: String = "jump"
|
||||||
|
|
||||||
#hidden
|
|
||||||
var input_target: Float3 = [0, 0, 0]
|
var input_target: Float3 = [0, 0, 0]
|
||||||
|
|
||||||
#hidden
|
#hidden
|
||||||
@ -108,8 +106,6 @@ class System is Modifier {
|
|||||||
data.time_since_grounded = 0
|
data.time_since_grounded = 0
|
||||||
data.input_target = Math.add(data.input_target, [0, data.jump_impulse / Character3D.get.speed(player), 0])
|
data.input_target = Math.add(data.input_target, [0, data.jump_impulse / Character3D.get.speed(player), 0])
|
||||||
data.is_grounded = false
|
data.is_grounded = false
|
||||||
|
|
||||||
Transform.translate(player, 0, data.ground_check_dist + this.EPSILON, 0)
|
|
||||||
} else {
|
} else {
|
||||||
data.input_target = [data.input_target.x, 0, data.input_target.z]
|
data.input_target = [data.input_target.x, 0, data.input_target.z]
|
||||||
}
|
}
|
||||||
@ -120,7 +116,7 @@ class System is Modifier {
|
|||||||
|
|
||||||
check_grounded(player: Entity, data: Data): Bool {
|
check_grounded(player: Entity, data: Data): Bool {
|
||||||
var height = Character3D.get.height(player) * 0.5
|
var height = Character3D.get.height(player) * 0.5
|
||||||
return Physics3D.cast_ray_closest(_world, Transform.get_pos_world(player), [0,-1,0], height + data.ground_check_dist) != null
|
return Physics3D.cast_ray_closest(_world, Transform.get_pos_world(player), [0,-1,0], height) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility Methods
|
// Utility Methods
|
||||||
|
|||||||
128
assets/system/player_interaction.modifier.api.wren
Normal file
128
assets/system/player_interaction.modifier.api.wren
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
|
||||||
|
class Modifier {
|
||||||
|
static id : String { "fpkit: system/player_interaction.modifier" }
|
||||||
|
static system(world: World) : System { World.get_system(world, Modifier.id) }
|
||||||
|
static get(entity: Entity) : Data { Mod.get(entity, Modifier.id) }
|
||||||
|
construct new(world: World) {
|
||||||
|
_world = world
|
||||||
|
_block = World.get_modifier_block(_world, Modifier.id)
|
||||||
|
}
|
||||||
|
world : World { _world }
|
||||||
|
attached_count : Num { Block.count(_block) }
|
||||||
|
|
||||||
|
init(world: World) : None {}
|
||||||
|
pre(entity: Entity, data) : None {}
|
||||||
|
attach(entity: Entity, data) : None {}
|
||||||
|
detach(entity: Entity, data) : None {}
|
||||||
|
change(entity: Entity, change: ModifierChange) : None {}
|
||||||
|
tick(delta: Num) : None {}
|
||||||
|
|
||||||
|
internal_tick(delta: Num) : None {
|
||||||
|
}
|
||||||
|
|
||||||
|
editor_init(world: World) : None {}
|
||||||
|
editor_pre(entity: Entity, data) : None {}
|
||||||
|
editor_attach(entity: Entity, data) : None {}
|
||||||
|
editor_detach(entity: Entity, data) : None {}
|
||||||
|
editor_change(entity: Entity, change: ModifierChange) : None {}
|
||||||
|
|
||||||
|
editor_tick(delta: Num) : None {}
|
||||||
|
|
||||||
|
get(entity: Entity) : Data { Mod.get(entity, Modifier.id) }
|
||||||
|
|
||||||
|
list() : List {
|
||||||
|
var list = []
|
||||||
|
each {|entity: Entity, unused|
|
||||||
|
list.add(entity)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
each(fn: Fn) : None {
|
||||||
|
var count = attached_count
|
||||||
|
for(idx in 0 ... count) {
|
||||||
|
var inst = Block.get_at(_block, idx)
|
||||||
|
var data = Block.instance(_block, inst)
|
||||||
|
var entity = Block.get_handle(_block, inst, HandleTag.entity)
|
||||||
|
fn.call(entity, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
each(start: Num, count: Num, fn: Fn) : None {
|
||||||
|
for(idx in start ... start + count) {
|
||||||
|
var inst = Block.get_at(_block, idx)
|
||||||
|
var data = Block.instance(_block, inst)
|
||||||
|
var entity = Block.get_handle(_block, inst, HandleTag.entity)
|
||||||
|
fn.call(entity, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class API {
|
||||||
|
static id { Modifier.id }
|
||||||
|
static create(entity: Entity) { Mod.create(Modifier.id, entity) }
|
||||||
|
static has(entity: Entity) { Mod.has(Modifier.id, entity) }
|
||||||
|
static destroy(entity: Entity) { Mod.destroy(Modifier.id, entity) }
|
||||||
|
static get(entity: Entity) : Data { Mod.get(entity, Modifier.id) }
|
||||||
|
static system_in(world: World) : System { World.get_system(world, Modifier.id) }
|
||||||
|
static system(entity: Entity) : System { World.get_system(Entity.get_world(entity), Modifier.id) }
|
||||||
|
static count(world: World) : Num { system_in(world).attached_count }
|
||||||
|
static each(world: World, fn: Fn) : System { system_in(world).each(fn) }
|
||||||
|
static with(world: World) : List { system_in(world).list() }
|
||||||
|
static get : APIGet { APIGetter }
|
||||||
|
static set : APISet { APISetter }
|
||||||
|
static connect : APIWireConnect { APIWireConnects }
|
||||||
|
static send : APIWireSend { APIWireSends }
|
||||||
|
}
|
||||||
|
|
||||||
|
class Fields {
|
||||||
|
static event_name : String { "event_name" }
|
||||||
|
static distance : String { "distance" }
|
||||||
|
static is_active : String { "is_active" }
|
||||||
|
static camera : String { "camera" }
|
||||||
|
}
|
||||||
|
|
||||||
|
import "luxe: world/states" for AState, States, Op
|
||||||
|
#doc="The base class for a state, and our API for accessing it"
|
||||||
|
class State is AState {
|
||||||
|
construct create(in_name: String, in_parent: State) { super(in_name, in_parent) }
|
||||||
|
goto_on(entity: Entity, state: State, wire: Num) { this.goto_on(entity, state, This, wire) }
|
||||||
|
}
|
||||||
|
|
||||||
|
class APIWireSend {
|
||||||
|
construct new() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class APIWireConnect {
|
||||||
|
construct new() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class APIGet {
|
||||||
|
construct new() {}
|
||||||
|
event_name(entity: Entity) : String { Modifier.get(entity).event_name }
|
||||||
|
distance(entity: Entity) : Num { Modifier.get(entity).distance }
|
||||||
|
is_active(entity: Entity) : Bool { Modifier.get(entity).is_active }
|
||||||
|
camera(entity: Entity) : Any { Modifier.get(entity).camera }
|
||||||
|
}
|
||||||
|
|
||||||
|
class APISet {
|
||||||
|
construct new() {}
|
||||||
|
event_name(entity: Entity, value: String) { Modifier.get(entity).event_name = value }
|
||||||
|
distance(entity: Entity, value: Num) { Modifier.get(entity).distance = value }
|
||||||
|
is_active(entity: Entity, value: Bool) { Modifier.get(entity).is_active = value }
|
||||||
|
camera(entity: Entity, value: Any) { Modifier.get(entity).camera = value }
|
||||||
|
}
|
||||||
|
|
||||||
|
var APIGetter = APIGet.new()
|
||||||
|
var APISetter = APISet.new()
|
||||||
|
var APIWireSends = APIWireSend.new()
|
||||||
|
var APIWireConnects = APIWireConnect.new()
|
||||||
|
|
||||||
|
import "fpkit: system/player_interaction.modifier" for Data, System
|
||||||
|
import "luxe: world/world" for World, Wire
|
||||||
|
import "luxe: world" for Entity
|
||||||
|
import "luxe: world/modifier" for Modifier as Mod, ModifierChange
|
||||||
|
import "luxe: blocks" for Block
|
||||||
|
import "luxe: io" for HandleTag
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
tags = []
|
||||||
|
uuid = "c293db97-0f62-430e-972c-0f51411770e2"
|
||||||
65
assets/system/player_interaction.modifier.wren
Normal file
65
assets/system/player_interaction.modifier.wren
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
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 ]]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
2
assets/system/player_interaction.modifier.wren.meta.lx
Normal file
2
assets/system/player_interaction.modifier.wren.meta.lx
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tags = []
|
||||||
|
uuid = "fe40c0cf-6bb3-42a6-80b5-5c86ebc89cb5"
|
||||||
Reference in New Issue
Block a user