-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic single square movement on button press
- Loading branch information
Showing
39 changed files
with
862 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
"Aniroth", | ||
"Asmin", | ||
"bson", | ||
"dtos", | ||
"Embeddable", | ||
"esbuild", | ||
"Gaali", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { useInputContext } from '../../context/Input/useInputContext'; | ||
import { InputEventRecordKey } from '../../dtos/Player/InputEventRecordKey.type'; | ||
import { GameState } from '../../dtos/GameState.dto'; | ||
|
||
export type GameEngineProps = { | ||
data: any; | ||
data: GameState; | ||
updateData: (newData: any) => void; | ||
}; | ||
|
||
export const GameEngine: React.FC<GameEngineProps> = () => { | ||
// if input up then try to move up | ||
export const GameEngine: React.FC<GameEngineProps> = props => { | ||
const { data, updateData } = props; | ||
const inputContext = useInputContext(); | ||
|
||
useEffect(() => { | ||
if (inputContext.state.key === InputEventRecordKey.LEFT) { | ||
data.actors[0].movement.targetPosition.x--; | ||
} | ||
if (inputContext.state.key === InputEventRecordKey.RIGHT) { | ||
data.actors[0].movement.targetPosition.x++; | ||
} | ||
if (inputContext.state.key === InputEventRecordKey.UP) { | ||
data.actors[0].movement.targetPosition.y--; | ||
} | ||
if (inputContext.state.key === InputEventRecordKey.DOWN) { | ||
data.actors[0].movement.targetPosition.y++; | ||
} | ||
|
||
updateData(data); | ||
}, [updateData, inputContext.state.key]); | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
// keyboard | ||
import { InputEventRecordKey } from '../../dtos/Player/InputEventRecordKey.type'; | ||
|
||
export const keyboardBindings = { | ||
up: 'w', | ||
down: 's', | ||
left: 'a', | ||
right: 'd', | ||
jump: ' ', | ||
debug: 'p', | ||
select: 'Enter', | ||
back: 'u', | ||
pause: 'Escape', | ||
[InputEventRecordKey.UP]: 'w', | ||
[InputEventRecordKey.DOWN]: 's', | ||
[InputEventRecordKey.LEFT]: 'a', | ||
[InputEventRecordKey.RIGHT]: 'd', | ||
[InputEventRecordKey.JUMP]: ' ', | ||
[InputEventRecordKey.DEBUG]: 'p', | ||
[InputEventRecordKey.SELECT]: 'Enter', | ||
[InputEventRecordKey.BACK]: 'u', | ||
[InputEventRecordKey.PAUSE]: 'Escape', | ||
}; | ||
|
||
// other inputs will be touch and based | ||
// may need to display buttons on screen for touch | ||
// move by clicking a tile.. |
29 changes: 16 additions & 13 deletions
29
clients/player-client/src/core/Keyboard/useHandleInput.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
clients/player-client/src/core/types/player-input-record.type.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
IsUrl, | ||
IsEnum, | ||
IsString, | ||
IsNumber, | ||
Min, | ||
ValidateNested, | ||
IsOptional, | ||
} from 'class-validator'; | ||
import { ActorAnimation } from './ActorAnimation.dto'; | ||
import { Transform, Type } from 'class-transformer'; | ||
import { ActorMovement } from './ActorMovement.dto'; | ||
import { ActorState } from '../../core/IsometricCanvas/types/ActorState.type'; | ||
import { DateTime } from 'luxon'; | ||
|
||
export class Actor { | ||
@IsString() | ||
actorId: string; | ||
|
||
@IsOptional() | ||
@IsNumber() | ||
@Min(0) | ||
height?: number; | ||
|
||
@ValidateNested() | ||
@Type(() => ActorMovement) | ||
movement: ActorMovement; | ||
|
||
@IsEnum(ActorState) | ||
currentState?: ActorState; | ||
|
||
@ValidateNested() | ||
@Type(() => ActorAnimation) | ||
animation: ActorAnimation; | ||
|
||
@Transform(({ value }) => { | ||
return Object.keys(value).reduce( | ||
(acc, key) => { | ||
acc[key] = value[key]; | ||
return acc; | ||
}, | ||
{} as Record<string, string>, | ||
); | ||
}) | ||
@IsString({ each: true }) | ||
@IsUrl({}, { each: true }) | ||
spriteMapRegistry: Record<string, string>; | ||
|
||
lastUpdated?: DateTime; // Timestamp for when the actor's data was last updated | ||
} |
31 changes: 31 additions & 0 deletions
31
clients/player-client/src/dtos/Actor/ActorAnimation.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { IsBoolean, IsDateString, IsString, IsNumber } from 'class-validator'; | ||
import { DateTime, Duration } from 'luxon'; | ||
|
||
export class ActorAnimation { | ||
@IsNumber() | ||
startingFrame?: number; | ||
|
||
@IsNumber() | ||
totalFrames: number; | ||
|
||
@IsNumber() | ||
animationDuration?: number; | ||
|
||
// @IsNumber() | ||
frameDuration: Duration; | ||
|
||
@IsBoolean() | ||
isAnimating?: false; | ||
|
||
@IsDateString() | ||
startTime: DateTime; | ||
|
||
@IsString() | ||
currentAnimation?: string; | ||
|
||
@IsNumber() | ||
currentFrame?: number; | ||
|
||
startTimestamp?: DateTime; // Time when the animation started | ||
endTimestamp?: DateTime; // Time when the animation should end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { IsBoolean, ValidateNested, IsDateString } from 'class-validator'; | ||
import { Type } from 'class-transformer'; | ||
import { Duration, DateTime } from 'luxon'; | ||
import { Coordinate3d } from '../Coordinate3d.dto'; | ||
|
||
export class ActorMovement { | ||
@IsBoolean() | ||
isInMotion: boolean; | ||
|
||
@ValidateNested() | ||
@Type(() => Coordinate3d) | ||
currentPosition: Coordinate3d; | ||
|
||
@ValidateNested() | ||
@Type(() => Coordinate3d) | ||
targetPosition: Coordinate3d; | ||
|
||
// TODO type for duration | ||
|
||
movementDuration?: Duration; // Duration of the movement (in seconds) ??? | ||
|
||
@IsBoolean() | ||
targetPositionReached: boolean; | ||
|
||
@IsDateString() | ||
startTimestamp: DateTime; | ||
|
||
@IsDateString() | ||
endTimestamp?: DateTime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { IsNumber } from 'class-validator'; | ||
|
||
export class Coordinate3d { | ||
@IsNumber() | ||
x: number; | ||
|
||
@IsNumber() | ||
y: number; | ||
|
||
@IsNumber() | ||
z: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IsString, Length } from 'class-validator'; | ||
|
||
export class Dialogue { | ||
@IsString() | ||
actorId: string; | ||
|
||
@IsString() | ||
@Length(1, 1000) | ||
text: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { IsString, IsUrl, IsArray, ValidateNested } from 'class-validator'; | ||
import { Transform, Type } from 'class-transformer'; | ||
import { Properties } from './Properties.dto'; | ||
import { Actor } from './Actor/Actor.dto'; | ||
import { Dialogue } from './Dialogue.dto'; | ||
import { Coordinate3d } from './Coordinate3d.dto'; | ||
|
||
export class GameState { | ||
@ValidateNested() | ||
@Type(() => Properties) | ||
properties: Properties; | ||
|
||
@IsArray() | ||
@ValidateNested({ each: true }) | ||
@Type(() => Actor) | ||
actors: Actor[]; | ||
|
||
@IsArray() | ||
@ValidateNested({ each: true }) | ||
@Type(() => Dialogue) | ||
dialogues: Dialogue[]; | ||
|
||
@Transform(({ value }) => { | ||
return Object.keys(value).reduce( | ||
(acc, key) => { | ||
acc[key] = value[key]; | ||
return acc; | ||
}, | ||
{} as Record<string, string>, | ||
); | ||
}) | ||
@IsString({ each: true }) | ||
@IsUrl({}, { each: true }) | ||
spriteMapRegistry: Record<string, string>; | ||
|
||
// TODO add type for grid | ||
grid: string[][][]; | ||
|
||
@ValidateNested() | ||
@Type(() => Coordinate3d) | ||
cameraPosition: Coordinate3d; | ||
} |
10 changes: 10 additions & 0 deletions
10
clients/player-client/src/dtos/Player/InputEventRecord.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IsEnum } from 'class-validator'; | ||
import { DateTime } from 'luxon'; | ||
import { InputEventRecordKey } from './InputEventRecordKey.type'; | ||
|
||
export class InputEventRecord { | ||
@IsEnum(InputEventRecordKey) | ||
key: InputEventRecordKey; | ||
|
||
timestamp: DateTime; | ||
} |
11 changes: 11 additions & 0 deletions
11
clients/player-client/src/dtos/Player/InputEventRecordKey.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export enum InputEventRecordKey { | ||
'UP' = 'UP', | ||
'DOWN' = 'DOWN', | ||
'LEFT' = 'LEFT', | ||
'RIGHT' = 'RIGHT', | ||
'JUMP' = 'JUMP', | ||
'DEBUG' = 'DEBUG', | ||
'SELECT' = 'SELECT', | ||
'BACK' = 'BACK', | ||
'PAUSE' = 'PAUSE', | ||
} |
Oops, something went wrong.