Skip to content

Commit d22f1f6

Browse files
authored
refactor: convert to monorepo structure with engine package (#4)
1 parent d12fcd3 commit d22f1f6

198 files changed

Lines changed: 1506 additions & 1828 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,17 @@ jobs:
3939
path: playwright-report/
4040
retention-days: 30
4141

42-
- name: Install demo dependencies
43-
run: cd demo && bun i
44-
4542
- name: Run linting and type checking
4643
run: bun run lint
4744

48-
- name: Run demo linting and type checking
49-
run: cd demo && bun run lint
50-
5145
- name: Run tests with coverage
5246
run: bun run coverage
5347

5448
- name: Build demo
55-
run: cd demo && bun run build
49+
run: bun run demo:build
5650

5751
- name: Upload coverage to Coveralls
5852
uses: coverallsapp/github-action@v2
5953
with:
6054
github-token: ${{ secrets.GITHUB_TOKEN }}
61-
file: ./lcov.info
55+
file: ./packages/core/lcov.info

.github/workflows/deploy-demo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: bun run build
3535

3636
- name: Build demo
37-
run: cd demo && bun i && bun run build
37+
run: bun run demo:build
3838

3939
- name: Setup Pages
4040
uses: actions/configure-pages@v4
@@ -46,4 +46,4 @@ jobs:
4646

4747
- name: Deploy to GitHub Pages
4848
id: deployment
49-
uses: actions/deploy-pages@v4
49+
uses: actions/deploy-pages@v4

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111
jobs:
1212
release:
1313
runs-on: ubuntu-latest
14-
14+
1515
steps:
1616
- name: Checkout code
1717
uses: actions/checkout@v4
@@ -36,10 +36,8 @@ jobs:
3636
- name: Get changelog for this release
3737
id: changelog
3838
run: |
39-
# Extract changelog section for this version
4039
VERSION="${{ steps.tag.outputs.tag }}"
4140
if [ -f "CHANGELOG.md" ]; then
42-
# Get content between this version and next version/end of file
4341
awk "/^## \[?${VERSION#v}\]?/ {flag=1; next} /^## / && flag {exit} flag" CHANGELOG.md > release_notes.md
4442
if [ -s release_notes.md ]; then
4543
echo "HAS_CHANGELOG=true" >> $GITHUB_OUTPUT
@@ -62,4 +60,4 @@ jobs:
6260
prerelease: false
6361
generate_release_notes: ${{ steps.changelog.outputs.HAS_CHANGELOG == 'false' }}
6462
env:
65-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dist-ssr
2727
coverage
2828
lcov.info
2929
test-results/
30+
playwright-report/
3031

3132
# Build info
3233
tsconfig.tsbuildinfo
@@ -40,3 +41,6 @@ tsconfig.declarations.tsbuildinfo
4041
# Demo build
4142
demo/dist
4243

44+
# Packages
45+
packages/*/dist
46+
packages/*/node_modules

.versionrc.json

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,20 @@
11
{
2-
"header": "# Changelog\n\nAll notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.\n",
3-
"types": [
4-
{
5-
"type": "feat",
6-
"section": "Features"
7-
},
8-
{
9-
"type": "fix",
10-
"section": "Bug Fixes"
11-
},
12-
{
13-
"type": "docs",
14-
"section": "Documentation"
15-
},
16-
{
17-
"type": "test",
18-
"section": "Tests"
19-
},
20-
{
21-
"type": "build",
22-
"section": "Build System"
23-
},
24-
{
25-
"type": "ci",
26-
"section": "CI/CD"
27-
},
28-
{
29-
"type": "chore",
30-
"hidden": true
31-
},
32-
{
33-
"type": "style",
34-
"hidden": true
35-
},
36-
{
37-
"type": "refactor",
38-
"section": "Code Refactoring"
39-
},
40-
{
41-
"type": "perf",
42-
"section": "Performance Improvements"
43-
},
44-
{
45-
"type": "revert",
46-
"section": "Reverts"
47-
}
2+
"packageFiles": [
3+
"packages/core/package.json"
4+
],
5+
"bumpFiles": [
6+
"packages/core/package.json"
487
],
49-
"commitUrlFormat": "https://github.com/hiddentao/clockwork-engine/commit/{{hash}}",
50-
"compareUrlFormat": "https://github.com/hiddentao/clockwork-engine/compare/{{previousTag}}...{{currentTag}}",
51-
"issueUrlFormat": "https://github.com/hiddentao/clockwork-engine/issues/{{id}}",
52-
"userUrlFormat": "https://github.com/{{user}}",
53-
"releaseCommitMessageFormat": "chore(release): {{currentTag}}",
54-
"issuePrefixes": ["#"],
55-
"tagPrefix": "v",
56-
"scripts": {
57-
"prerelease": "bun run lint && bun test && bun run build"
58-
}
8+
"infile": "CHANGELOG.md",
9+
"header": "# Changelog\n\nAll notable changes to this project will be documented in this file.\n",
10+
"types": [
11+
{ "type": "feat", "section": "Features" },
12+
{ "type": "fix", "section": "Bug Fixes" },
13+
{ "type": "perf", "section": "Performance" },
14+
{ "type": "refactor", "section": "Refactoring" },
15+
{ "type": "docs", "section": "Documentation" },
16+
{ "type": "test", "section": "Tests" },
17+
{ "type": "build", "section": "Build System" },
18+
{ "type": "ci", "section": "CI/CD" }
19+
]
5920
}

LICENSE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# MIT License
1+
MIT License
22

3-
Copyright (c) 2025 [Ramesh Nair](https://hiddentao.com)
3+
Copyright (c) 2025 Ramesh Nair
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,109 @@
44

55
[![Build Status](https://img.shields.io/github/actions/workflow/status/hiddentao/clockwork-engine/ci.yml?branch=main)](https://github.com/hiddentao/clockwork-engine/actions)
66
[![Coverage Status](https://coveralls.io/repos/github/hiddentao/clockwork-engine/badge.svg?branch=main)](https://coveralls.io/github/hiddentao/clockwork-engine?branch=main)
7-
[![NPM Version](https://img.shields.io/npm/v/@hiddentao/clockwork-engine.svg)](https://www.npmjs.com/package/@hiddentao/clockwork-engine)
7+
[![NPM Version](https://img.shields.io/npm/v/@clockwork-engine/core.svg)](https://www.npmjs.com/package/@clockwork-engine/core)
88
[![TypeScript](https://img.shields.io/badge/TypeScript-5.3.3-blue.svg)](https://www.typescriptlang.org/)
99

10-
**A TypeScript game engine for deterministic, replayable games with built-in recording, replay, and rendering capabilities.**
10+
**A TypeScript game engine for deterministic, replayable games with platform-agnostic rendering.**
1111

12-
[Documentation](./docs)
12+
[Documentation](./packages/core/docs)
1313

1414
</div>
1515

1616
---
1717

18-
## 🎮 Live Demo
18+
## Live Demo
1919

2020
**[Try the Interactive Demo →](https://hiddentao.github.io/clockwork-engine)**
2121

22-
## Features
22+
## Features
2323

24-
- 🎯 **Deterministic Gameplay** - Frame-based updates with seeded PRNG for perfect reproducibility
25-
- 📹 **Record & Replay** - Built-in recording system for gameplay sessions with frame-accurate playback
26-
- 🎮 **Game Object System** - Type-safe game entities with automatic grouping and lifecycle management
27-
- 🎨 **Built-in PIXI.js Renderer** - Built-in [pixi.js](https://pixijs.com/) integration with viewport management, event handling, and rendering abstractions
28-
- 🏃‍♂️ **High-Performance Collision Detection** - Spatial partitioning with BSP trees for efficient collision queries
29-
- **Event-Driven Architecture** - Flexible event system with custom event sources and managers
30-
- 🔄 **Universal Serialization** - Automatic serialization for all game data with custom type support
31-
- ⏱️ **Frame-Based Timers** - Deterministic timing system replacing JavaScript's native timers
32-
- 🔧 **TypeScript First** - Full type safety with comprehensive interfaces and generics
24+
- **Deterministic Gameplay** - Frame-based updates with seeded PRNG for perfect reproducibility
25+
- **Record & Replay** - Built-in recording system for gameplay sessions with frame-accurate playback
26+
- **Game Object System** - Type-safe game entities with automatic grouping and lifecycle management
27+
- **Platform-Agnostic Rendering** - Separate rendering implementations (PIXI.js for web, headless for testing)
28+
- **High-Performance Collision Detection** - Spatial partitioning with BSP trees for efficient collision queries
29+
- **Event-Driven Architecture** - Flexible event system with custom event sources and managers
30+
- **Universal Serialization** - Automatic serialization for all game data with custom type support
31+
- **Frame-Based Timers** - Deterministic timing system replacing JavaScript's native timers
32+
- **TypeScript First** - Full type safety with comprehensive interfaces and generics
3333

34-
## 🚀 Quick Start
34+
## Packages
35+
36+
This monorepo contains the following packages:
37+
38+
| Package | Description |
39+
|---------|-------------|
40+
| [`@clockwork-engine/core`](./packages/core) | Core engine with game objects, recording/replay, serialization, and platform abstraction |
41+
| [`@clockwork-engine/platform-web-pixi`](./packages/platform-web-pixi) | Web platform with PIXI.js 2D rendering |
42+
| [`@clockwork-engine/platform-memory`](./packages/platform-memory) | Headless platform for testing and replay validation |
43+
44+
## Quick Start
3545

3646
### Installation
3747

3848
```bash
39-
npm install @hiddentao/clockwork-engine
40-
# or
41-
bun add @hiddentao/clockwork-engine
49+
# Install core engine and web platform
50+
bun add @clockwork-engine/core @clockwork-engine/platform-web-pixi
51+
52+
# For testing/headless use
53+
bun add @clockwork-engine/platform-memory
4254
```
4355

4456
### Basic Usage
4557

4658
```typescript
47-
import { GameEngine, GameObject, Vector2D, GameCanvas } from '@hiddentao/clockwork-engine'
59+
import { GameEngine, GameObject, Vector2D, GameCanvas } from '@clockwork-engine/core'
60+
import { WebPlatformLayer } from '@clockwork-engine/platform-web-pixi'
4861

62+
// 1. Define your game engine
4963
class MyGame extends GameEngine {
5064
setup() {
51-
// Initialize your game world
5265
const player = new Player(new Vector2D(100, 100))
5366
this.registerGameObject(player)
5467
}
5568
}
5669

70+
// 2. Define your game canvas
5771
class MyGameCanvas extends GameCanvas {
58-
protected initializeGameLayers(): void {
72+
protected setupRenderers(): void {
5973
// Set up your game rendering layers
6074
}
6175

6276
protected render(deltaFrames: number): void {
63-
// Custom rendering logic (optional)
77+
// Custom rendering logic
6478
}
6579
}
6680

67-
const game = new MyGame()
68-
game.reset("my-seed")
69-
70-
// Create canvas with built-in PIXI.js integration
71-
const container = document.getElementById('game-container')
72-
const canvas = await MyGameCanvas.create(container, {
73-
width: 800,
74-
height: 600,
81+
// 3. Initialize the platform and canvas
82+
const container = document.getElementById('game-container')!
83+
const platform = new WebPlatformLayer(container, {
84+
screenWidth: 800,
85+
screenHeight: 600,
7586
worldWidth: 800,
76-
worldHeight: 600
87+
worldHeight: 600,
7788
})
89+
await platform.init()
90+
91+
// 4. Create and initialize the canvas
92+
const canvas = new MyGameCanvas(
93+
{ width: 800, height: 600, worldWidth: 800, worldHeight: 600 },
94+
platform
95+
)
96+
await canvas.initialize()
7897

98+
// 5. Create game engine and connect to canvas
99+
const game = new MyGame()
100+
await game.reset({ seed: 'my-seed' })
79101
canvas.setGameEngine(game)
80102
game.start()
81103
```
82104

83-
## 📚 Documentation
105+
## Documentation
84106

85-
Comprehensive documentation is available in the [docs](./docs) directory:
107+
Comprehensive documentation is available in the [docs](./packages/core/docs) directory.
86108

87-
## 🛠️ Development
109+
## Development
88110

89111
### Prerequisites
90112

@@ -101,7 +123,7 @@ cd clockwork-engine
101123
# Install dependencies
102124
bun install
103125

104-
# Build the project
126+
# Build all packages
105127
bun run build
106128

107129
# Run in watch mode
@@ -134,9 +156,9 @@ bun run format
134156
### Demo Application
135157

136158
```bash
137-
# Run the demo (from project root)
159+
# Run the demo
138160
cd demo
139-
bun i
161+
bun i
140162
bun run dev
141163
```
142164

@@ -173,9 +195,8 @@ The release process will:
173195

174196
## Changelog
175197

176-
See [CHANGELOG.md](CHANGELOG.md)
198+
See [CHANGELOG.md](./CHANGELOG.md)
177199

178-
## 📄 License
200+
## License
179201

180202
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
181-

0 commit comments

Comments
 (0)