mirror of
https://git.xeondev.com/LR/S.git
synced 2026-02-04 06:55:06 +01:00
refactor(scene): decouple player level/position from notifying systems
This commit is contained in:
@@ -15,10 +15,32 @@ pub const PlayerId = struct {
|
||||
uid: mem.LimitedString(max_length),
|
||||
};
|
||||
|
||||
// TODO: this can be made a persistent Player component.
|
||||
pub const Location = struct {
|
||||
const default_level = "map02_lv001";
|
||||
|
||||
level: i32,
|
||||
position: [3]f32,
|
||||
|
||||
fn createDefault(assets: *const Assets) Location {
|
||||
const level_config = assets.level_config_table.getPtr(default_level).?;
|
||||
|
||||
return .{
|
||||
.level = level_config.idNum,
|
||||
.position = .{
|
||||
level_config.playerInitPos.x,
|
||||
level_config.playerInitPos.y,
|
||||
level_config.playerInitPos.z,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
player_id: PlayerId,
|
||||
session: *Session, // TODO: should it be here this way? Do we need an abstraction?
|
||||
res: logic.Resource,
|
||||
player: logic.Player,
|
||||
location: Location,
|
||||
|
||||
pub fn init(
|
||||
session: *Session,
|
||||
@@ -34,6 +56,7 @@ pub fn init(
|
||||
.session = session,
|
||||
.player = player,
|
||||
.res = .init(assets, io),
|
||||
.location = .createDefault(assets),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -48,6 +71,7 @@ pub const GetComponentError = error{
|
||||
pub fn getComponentByType(world: *World, comptime T: type) GetComponentError!T {
|
||||
switch (T) {
|
||||
PlayerId => return world.player_id,
|
||||
*Location, *const Location => return &world.location,
|
||||
*Session => return world.session,
|
||||
*logic.Resource.PingTimer => return &world.res.ping_timer,
|
||||
*const Assets => return world.res.assets,
|
||||
|
||||
Reference in New Issue
Block a user