Skip to content

Commit 1545781

Browse files
authored
Merge pull request #250 from oskarrough/experimental-api
Experimental API
2 parents 86e806b + 4ce2d7a commit 1545781

File tree

8 files changed

+694
-5
lines changed

8 files changed

+694
-5
lines changed

DOCUMENTATION.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Throughout the project I've attempted to document and leave comments. Go ahead a
44

55
In the root of this project you'll find configuration files as well as three folders:
66

7-
- [src](src/) The web root.
7+
- [src](src/) The web root.
88
- [content](src/content) contains cards, dungeons, encounters and monsters etc.
99
- [game](src/game) contains the core game logic
1010
- [ui](src/ui) is the example web interface to actually play the game
11-
- [public](public/) Copied to the web root as-is
12-
- [tests](tests/) Contains all tests for the game engine. Nothing for the UI. Run `npm test`.
11+
- [public](public/) Copied to the web root as-is, used for static images
12+
- [tests](tests/) Contains tests for the game. There are no tests for the UI.
1313

1414
### Game
1515

EXPERIMENT.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Slay the web API design
2+
3+
## Core architecture (current)
4+
5+
- State-based: Actions are pure functions `(state, props) => newState`
6+
- Queue system: Actions enqueued and processed sequentially
7+
- Turn-based: Perfect for command pattern with clear state transitions
8+
9+
```js
10+
// Core pattern
11+
game.enqueue({type: 'playCard', card})
12+
game.dequeue()
13+
14+
// Queue enables
15+
// - Undo/redo
16+
// - Action history
17+
// - Save states
18+
// - Debugging
19+
```
20+
21+
## API style options
22+
23+
All styles would wrap the same core engine:
24+
25+
1. Current (Raw Actions) - Explicit and debuggable but verbose
26+
```js
27+
game.enqueue({type: 'playCard', card: strike})
28+
game.dequeue()
29+
```
30+
31+
2. Fluent/Chainable - Readable sequences
32+
```js
33+
game.drawCards(5).playCard(strike, 'enemy0').endTurn()
34+
```
35+
36+
3. Command Strings - Console-like for debugging
37+
```js
38+
game.do('/play strike enemy0')
39+
```
40+
41+
4. Domain-Specific - Organized by game concepts
42+
```js
43+
game.combat.play(strike).on('enemy0')
44+
game.deck.draw(5)
45+
```
46+
47+
5. Builder Pattern - Step-by-step construction
48+
```js
49+
game.command.play(strike).target('enemy0').run()
50+
```
51+
52+
## Implementation considerations
53+
54+
1. All wrappers map to core state transforms
55+
2. Actions remain composable
56+
3. Type safety for parameters
57+
58+
## Conclusion
59+
60+
The state-based core architecture is powerful, flexible, and should be preserved. Thin wrapper APIs can provide more ergonomic interfaces for common operations while maintaining the underlying strengths of the system.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ TLDR;
2424
1. Clone the repository
2525
2. Run `npm install` followed by `npm run dev` to open a local development server.
2626

27-
2827
## Documentation
2928

3029
If you're interested in contributing to the game or merely curious how it works:

bun.lockb

8.99 KB
Binary file not shown.

0 commit comments

Comments
 (0)