seperated client and server state, input mapper
This commit is contained in:
parent
44f63f8deb
commit
d5b77a9044
10 changed files with 104 additions and 16 deletions
44
src/ReplicatedStorage/ecs/systems/client/inputMapper.ts
Normal file
44
src/ReplicatedStorage/ecs/systems/client/inputMapper.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { useDeltaTime, useEvent, useThrottle, World } from "@rbxts/matter"
|
||||
import { UserInputService } from "@rbxts/services"
|
||||
import { clientState } from "ReplicatedStorage/ecs/state"
|
||||
import { InputKind } from "ReplicatedStorage/inputKind"
|
||||
|
||||
let holdDuration = 0
|
||||
function inputMapper(_: World, client: clientState): void {
|
||||
for (const [, input, gpe] of useEvent(UserInputService, "InputBegan")) {
|
||||
if (gpe) return undefined
|
||||
if (input.KeyCode !== Enum.KeyCode.Unknown) {
|
||||
client.lastProcessedCommand = InputKind.KeyDown(input.KeyCode)
|
||||
} else if (input.UserInputType === Enum.UserInputType.MouseButton1) {
|
||||
if (useThrottle(0.5)) {
|
||||
client.lastProcessedCommand = InputKind.PointerClick
|
||||
return undefined
|
||||
}
|
||||
client.lastProcessedCommand = InputKind.DoubleClick
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
for (const [, input, gpe] of useEvent(UserInputService, "InputEnded")) {
|
||||
if (gpe) return undefined
|
||||
|
||||
if (input.KeyCode !== Enum.KeyCode.Unknown) {
|
||||
client.lastProcessedCommand = InputKind.KeyUp(input.KeyCode)
|
||||
} else if (input.UserInputType === Enum.UserInputType.MouseButton1) {
|
||||
client.lastProcessedCommand = InputKind.HoldRelease
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (UserInputService.IsMouseButtonPressed(Enum.UserInputType.MouseButton1)) {
|
||||
holdDuration += useDeltaTime()
|
||||
client.lastProcessedCommand = InputKind.Hold(holdDuration)
|
||||
return
|
||||
}
|
||||
|
||||
holdDuration = 0
|
||||
client.lastProcessedCommand = undefined
|
||||
return
|
||||
}
|
||||
|
||||
export = inputMapper
|
Loading…
Add table
Add a link
Reference in a new issue