Skip to content

Commit 254ae7c

Browse files
committed
feat: Implement GameFeature system for modular game features and management
1 parent d33eec8 commit 254ae7c

File tree

3 files changed

+390
-19
lines changed

3 files changed

+390
-19
lines changed

README.md

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,89 @@ Vigilans Nexum is a tactical, turn- and tile-based RPG with a deep story about t
77
```
88
vigilans-nexum
99
├── src
10-
│ ├── assets
10+
│ ├── assets # Asset Bundles
11+
│ │ ├── startmenu
12+
│ │ │ ├── audio
13+
│ │ │ ├── video
14+
│ │ │ ├── fonts
15+
│ │ │ ├── icons
16+
│ │ │ ├── images
17+
│ │ │ ├── scripts
18+
│ │ │ └── data
19+
│ │ ├── ...
20+
│ │ └── common
21+
│ │ ├── audio
22+
│ │ ├── video
23+
│ │ ├── fonts
24+
│ │ ├── icons
25+
│ │ ├── images
26+
│ │ ├── scripts
27+
│ │ └── data
28+
│ ├── core # Game Framework
29+
│ │ ├── assets
1130
│ │ ├── audio
12-
│ │ ├── fonts
13-
│ │ ├── icons
14-
│ │ ├── images
15-
│ │ ├── javascript
16-
│ │ └── video
17-
│ ├── commands
18-
│ ├── components
19-
│ ├── core
20-
│ ├── states
21-
│ ├── systems
22-
│ ├── utils
23-
│ ├── asset.manifest.ts
24-
│ ├── database.schema.ts
25-
│ ├── game.config.ts
26-
│ ├── game.events.ts
31+
│ │ ├── database
32+
│ │ ├── ecs
33+
│ │ ├── events
34+
│ │ ├── graphics
35+
│ │ ├── input
36+
│ │ ├── math
37+
│ │ ├── model
38+
│ │ ├── service
39+
│ │ ├── utils
40+
│ │ ├── Game.ts
41+
│ │ ├── GameError.ts
42+
│ │ └── ...
43+
│ ├── game # Game Features and Systems
44+
│ │ ├── battle
45+
│ │ │ ├── systems
46+
│ │ │ ├── components
47+
│ │ │ ├── commands
48+
│ │ │ ├── states
49+
│ │ │ ├── model
50+
│ │ │ └── index.ts
51+
│ │ ├── map
52+
│ │ │ ├── systems
53+
│ │ │ ├── components
54+
│ │ │ ├── commands
55+
│ │ │ ├── states
56+
│ │ │ ├── model
57+
│ │ │ └── index.ts
58+
│ │ ├── units
59+
│ │ ├── bonding
60+
│ │ ├── story
61+
│ │ ├── ui
62+
│ │ ├── progression
63+
│ │ ├── ...
64+
│ │ └── common
65+
│ │ ├── systems
66+
│ │ ├── components
67+
│ │ ├── commands
68+
│ │ ├── states
69+
│ │ ├── model
70+
│ │ └── index.ts
71+
│ ├── asset.manifest.ts # Asset Manifest for Loading
72+
│ ├── database.schema.ts # Custom Schemas for IndexDB
73+
│ ├── game.config.ts # Game Configuration
74+
│ ├── game.events.ts # Custom Events for Event System
2775
│ ├── index.css
2876
│ ├── index.html
29-
│ ├── index.ts
77+
│ ├── index.ts # Game Initialization and Feature Registration
3078
│ └── manifest.json
79+
├── test
80+
│ ├── core
81+
│ └── ...
3182
├── .gitignore
83+
├── .editorconfig
84+
├── .eslintrc
85+
├── .prettierrc
3286
├── LICENSE
87+
├── package-lock.json
3388
├── package.json
3489
├── README.md
35-
├── rollup.config.js
36-
└── tsconfig.json
90+
├── sonar-project.properties
91+
├── tsconfig.json
92+
├── vite.config.ts
93+
├── vitest.config.ts
94+
└── vitest.setup.ts
3795
```

src/core/Game.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SystemConstructor } from "@/core/ecs/System";
1414
import { GameStateConstructor } from "@/core/GameState";
1515
import { GameCommandConstructor } from "@/core/input/commands/GameCommand";
1616
import { Savegame } from "@/core/model/Savegame";
17+
import { GameFeature, GameFeatureConstructor } from "./GameFeature";
1718

1819
export interface GameConfiguration {
1920
id: string;
@@ -40,6 +41,8 @@ export class Game {
4041
private isRunning: boolean;
4142
private timer: number;
4243

44+
private features: Map<string, GameFeature>;
45+
4346
private eventSystem: EventSystem;
4447
private localDatabase: LocalDatabase;
4548
private assetStorage: AssetStorage;
@@ -59,6 +62,8 @@ export class Game {
5962
this.isRunning = false;
6063
this.timer = 0;
6164

65+
this.features = new Map<string, GameFeature>();
66+
6267
this.eventSystem = new EventSystem(config.eventSystem);
6368
this.localDatabase = new LocalDatabase(config.id, config.localDatabase);
6469
this.assetStorage = new AssetStorage();
@@ -130,6 +135,23 @@ export class Game {
130135
window.cancelAnimationFrame(this.animationFrame);
131136
}
132137

138+
public install(feature: GameFeature): this {
139+
feature.install();
140+
this.features.set(feature.constructor.name, feature);
141+
return this;
142+
}
143+
144+
public uninstall(feature: GameFeature): this {
145+
feature.uninstall();
146+
this.features.delete(feature.constructor.name);
147+
return this;
148+
}
149+
150+
public getFeature<T extends GameFeature>(featureType: GameFeatureConstructor): T | null {
151+
const feature = this.features.get(featureType.name);
152+
return feature ? (feature as T) : null;
153+
}
154+
133155
public registerComponent<T extends JsonSchema>(compenentType: ComponentConstructor<T>): this {
134156
this.world.registerComponent(compenentType);
135157
return this;

0 commit comments

Comments
 (0)