Skip to content

Commit

Permalink
feat: store keyboard timestamp as datetime object
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtree committed Dec 11, 2024
1 parent 320b80d commit eda019b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion clients/player-client/src/components/Keyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Keyboard: React.FC<KeyboardProps> = () => {

return (
<div>
{inputContext.state.key} {inputContext.state.timestamp}{' '}
{inputContext.state.key} {inputContext.state.timestamp?.toISO()}{' '}
{input && <div>Input: {input?.map(i => i.key).join(', ')}</div>}
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion clients/player-client/src/context/Input/InputAction.type.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { InputActionType } from './InputActionType.type';
import { DateTime } from 'luxon';

export type InputAction =
| { type: InputActionType.SET_TOUCH_GRID; payload: { x: number; y: number } }
| {
type: InputActionType.SET_KEYSTROKE;
payload: { key: string; timestamp: string };
payload: { key: string; timestamp: DateTime };
};
4 changes: 3 additions & 1 deletion clients/player-client/src/context/Input/InputState.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DateTime } from 'luxon';

export type InputState = {
x?: number;
y?: number;
key?: string;
timestamp?: string;
timestamp?: DateTime;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { DateTime } from 'luxon';

export type PlayerInputRecord = {
key: string;
timestamp: string;
timestamp: DateTime;
};
2 changes: 1 addition & 1 deletion clients/player-client/src/core/useHandleInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function useHandleInput(): PlayerInputRecord[] | null {
// Collect key press for the given direction
newInputRecords.push({
key: direction,
timestamp: DateTime.now().toISO(),
timestamp: DateTime.now(),
});
}
});
Expand Down

0 comments on commit eda019b

Please sign in to comment.