Skip to content

Commit ec46376

Browse files
committed
chore: more clarification in game
1 parent a5744d3 commit ec46376

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

src/game/game.ts

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// The game is the interface that connects all related to a KAPLAY game state.
1+
// The Game is the interface that connects all related to a KAPLAY game state.
22
// It contains the game object tree, game object events, scenes, etc.
33

4+
// All in /game folder is stuff that uses/modify the game state.
5+
46
import type { Asset } from "../assets/asset";
57
import type { SpriteData } from "../assets/sprite";
68
import type { FakeMouseComp } from "../ecs/components/misc/fakeMouse";
@@ -107,22 +109,33 @@ type CamData = {
107109
transform: Mat23;
108110
};
109111

112+
/**
113+
* Creates the Game interface.
114+
*
115+
* This will create:
116+
*
117+
* - The root game object
118+
* - The game object events
119+
* - The camera data
120+
*
121+
* @returns A Game
122+
*/
110123
export const createGame = (): Game => {
111-
const game = {
124+
const game: Game = {
112125
gameObjLastId: 0,
113-
// general events
114-
events: new KEventHandler<GameEventMap & GameObjEventMap>(),
115-
// root game object
116126
root: makeInternal([], 0) as GameObj<TimerComp>,
127+
events: new KEventHandler<GameEventMap & GameObjEventMap>(),
128+
cam: {
129+
pos: null as Vec2 | null,
130+
scale: new Vec2(1),
131+
angle: 0,
132+
shake: 0,
133+
transform: new Mat23(),
134+
},
117135

118-
// misc
119-
gravity: null as Vec2 | null,
120-
scenes: {} as Record<SceneName, SceneDef>,
121-
currentScene: null as SceneName | null,
122-
layers: null as string[] | null,
123-
defaultLayerIndex: 0,
136+
// Systems
124137
systems: [], // all systems added
125-
// we allocate systems
138+
// we allocate systems here
126139
systemsByEvent: [
127140
[], // afterDraw
128141
[], // afterFixedUpdate
@@ -132,29 +145,34 @@ export const createGame = (): Game => {
132145
[], // beforeUpdate
133146
],
134147

135-
// default assets
148+
// Scenes
149+
scenes: {} as Record<SceneName, SceneDef>,
150+
currentScene: null as SceneName | null,
151+
152+
// Layers
153+
layers: null as string[] | null,
154+
defaultLayerIndex: 0,
155+
156+
// Gravity
157+
gravity: null as Vec2 | null,
158+
159+
// Assets
136160
kaSprite: null as unknown as Asset<SpriteData>,
137161
boomSprite: null as unknown as Asset<SpriteData>,
138162

139-
// on screen log
163+
// Logs
140164
logs: [] as { msg: string | { toString(): string }; time: number }[],
141165

142-
// camera
143-
cam: {
144-
pos: null as Vec2 | null,
145-
scale: new Vec2(1),
146-
angle: 0,
147-
shake: 0,
148-
transform: new Mat23(),
149-
},
166+
// Fake mouse API
167+
fakeMouse: null,
150168

151-
defRNG: new RNG(Date.now()),
169+
// Some state
152170
crashed: false,
153171
areaCount: 0,
154-
fakeMouse: null,
155172
allTextInputs: new Set<GameObj>(),
173+
defRNG: new RNG(Date.now()),
156174
warned: new Set<string>(),
157-
} satisfies Game;
175+
};
158176

159177
game.root.use(timer());
160178
game.gameObjLastId++;

0 commit comments

Comments
 (0)