Compare commits
No commits in common. "3458a6e29ba31b7b18b63076d50f68f50c53c6ce" and "3b327ea260afa870a49e1b70e548174ca15a3a9b" have entirely different histories.
3458a6e29b
...
3b327ea260
6 changed files with 2 additions and 89 deletions
|
@ -51,8 +51,7 @@ export interface Damage {
|
||||||
export interface PlayerCharacter {
|
export interface PlayerCharacter {
|
||||||
character: CharacterRigR6,
|
character: CharacterRigR6,
|
||||||
humanoid: Humanoid,
|
humanoid: Humanoid,
|
||||||
player: Player,
|
player: Player
|
||||||
equippedTool?: Tool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,7 +14,6 @@ export class ClientState {
|
||||||
debugEnabled: boolean,
|
debugEnabled: boolean,
|
||||||
isRunning: boolean,
|
isRunning: boolean,
|
||||||
backpack: Backpack,
|
backpack: Backpack,
|
||||||
// equippedTool: Tool,
|
|
||||||
// lastProcessedCommand: Inputkind,
|
// lastProcessedCommand: Inputkind,
|
||||||
|
|
||||||
logger: Logger
|
logger: Logger
|
||||||
|
@ -24,7 +23,6 @@ export class ClientState {
|
||||||
this.debugEnabled = debugEnabled
|
this.debugEnabled = debugEnabled
|
||||||
this.isRunning = isRunning
|
this.isRunning = isRunning
|
||||||
this.backpack = backpack
|
this.backpack = backpack
|
||||||
// this.equippedTool = equippedTool
|
|
||||||
// this.lastProcessedCommand = lastProcessedCommand
|
// this.lastProcessedCommand = lastProcessedCommand
|
||||||
|
|
||||||
this.logger = logger
|
this.logger = logger
|
||||||
|
@ -35,7 +33,6 @@ export class ClientState {
|
||||||
debugEnabled: boolean
|
debugEnabled: boolean
|
||||||
isRunning: boolean
|
isRunning: boolean
|
||||||
backpack: Backpack
|
backpack: Backpack
|
||||||
|
|
||||||
lastProcessedCommand?: InputKind
|
lastProcessedCommand?: InputKind
|
||||||
|
|
||||||
logger: Logger
|
logger: Logger
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
import { World, useEvent } from "@rbxts/matter"
|
|
||||||
import { PlayerCharacter } from "ReplicatedStorage/ecs/components"
|
|
||||||
import { getEvent } from "ReplicatedStorage/remotes"
|
|
||||||
|
|
||||||
function toolHandler(world: World): void {
|
|
||||||
const activateToolEvent = getEvent("activateToolEvent")
|
|
||||||
const equipToolEvent = getEvent("equipToolEvent")
|
|
||||||
|
|
||||||
for (const [_, character] of world.query(PlayerCharacter)) {
|
|
||||||
if (!character.equippedTool) continue
|
|
||||||
|
|
||||||
for (const [_] of useEvent(character.equippedTool, "Activated")) {
|
|
||||||
activateToolEvent.FireServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [_, mouse] of useEvent(character.equippedTool, "Equipped")) {
|
|
||||||
equipToolEvent.FireServer(mouse)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export = toolHandler
|
|
|
@ -1,37 +0,0 @@
|
||||||
import { None, useEvent, World } from "@rbxts/matter"
|
|
||||||
import { PlayerCharacter } from "ReplicatedStorage/ecs/components"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Equipped tool is replicated into the ECS.
|
|
||||||
*/
|
|
||||||
function playerCharacterToolIsTool(world: World): void {
|
|
||||||
for (const [id, character] of world.query(PlayerCharacter)) {
|
|
||||||
for (const [_, toolInstance] of useEvent(character.character, "ChildAdded")) {
|
|
||||||
if (!classIs(toolInstance, "Tool")) continue
|
|
||||||
|
|
||||||
world.insert(
|
|
||||||
id,
|
|
||||||
character.patch({
|
|
||||||
equippedTool: toolInstance
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [_, toolInstance] of useEvent(character.character, "ChildRemoved")) {
|
|
||||||
// classIs more like classWas
|
|
||||||
if (!classIs(toolInstance, "Tool")) continue
|
|
||||||
|
|
||||||
// could also be swapping tools
|
|
||||||
const swappedTool = character.character.FindFirstChildOfClass("Tool")
|
|
||||||
|
|
||||||
world.insert(
|
|
||||||
id,
|
|
||||||
character.patch({
|
|
||||||
equippedTool: swappedTool ? swappedTool : None
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export = playerCharacterToolIsTool
|
|
|
@ -9,8 +9,7 @@ type ComponentConstructor = (typeof Components)[ComponentName]
|
||||||
|
|
||||||
const REPLICATED_COMPONENT_NAMES: readonly ComponentName[] = [
|
const REPLICATED_COMPONENT_NAMES: readonly ComponentName[] = [
|
||||||
"Model",
|
"Model",
|
||||||
"Transform",
|
"Transform"
|
||||||
"PlayerCharacter"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
const replicatedComponents: ReadonlySet<ComponentConstructor> = REPLICATED_COMPONENT_NAMES.reduce(
|
const replicatedComponents: ReadonlySet<ComponentConstructor> = REPLICATED_COMPONENT_NAMES.reduce(
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
import { World, useEvent } from "@rbxts/matter"
|
|
||||||
import { PlayerCharacter } from "ReplicatedStorage/ecs/components"
|
|
||||||
import { ServerState } from "ReplicatedStorage/ecs/state"
|
|
||||||
import { getEvent } from "ReplicatedStorage/remotes"
|
|
||||||
|
|
||||||
function toolHandler(world: World, state: ServerState): void {
|
|
||||||
const activateToolEvent = getEvent("activateToolEvent")
|
|
||||||
const equipToolEvent = getEvent("equipToolEvent")
|
|
||||||
|
|
||||||
for (const [_, character] of world.query(PlayerCharacter)) {
|
|
||||||
for (const [_, player] of useEvent(activateToolEvent, "OnServerEvent")) {
|
|
||||||
state.logger.Info("{@player} activated the tool {@tool}", player, character.equippedTool)
|
|
||||||
if (character.player !== player) continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [_, player] of useEvent(equipToolEvent, "OnServerEvent")) {
|
|
||||||
state.logger.Info("{@player} equipped the tool {@tool}", player, character.equippedTool)
|
|
||||||
if (character.player !== player) continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export = toolHandler
|
|
Loading…
Add table
Add a link
Reference in a new issue