@evitcastudio/kit 3.3.1 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,27 +1,80 @@
1
- # Kit
1
+ <p align="center">
2
+ <img src="./evitcastudio_round_branding.png" width="128" height="128" alt="Evitca Studio Logo" />
3
+ </p>
2
4
 
3
- **Kit** is a lightweight, extensible 2D framework for game development in the [Vylocity Game Engine](https://www.vylocity.com/). Designed to be simple and modular, Kit empowers developers to build complex projects quickly through a robust plugin-driven architecture.
5
+ <h1 align="center">@evitcastudio/kit</h1>
6
+
7
+ <p align="center">
8
+ A lightweight, extensible framework and developer toolkit for the Vylocity Game Engine.
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@evitcastudio/kit"><img src="https://img.shields.io/npm/v/@evitcastudio/kit.svg?color=10b981" alt="npm version" /></a>
13
+ <a href="https://github.com/EvitcaStudio/Kit/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" /></a>
14
+ <a href="https://github.com/EvitcaStudio/Kit"><img src="https://img.shields.io/badge/TypeScript-Ready-3178c6.svg" alt="TypeScript" /></a>
15
+ </p>
16
+
17
+ ---
18
+
19
+ ## Features
20
+
21
+ - **Modular Plugin Architecture**: Centralized service locator (`Kit.registerPlugin`, `Kit.getPlugin`) with lifecycle hooks and a decoupled typed event bus (`Kit.on`, `Kit.off`).
22
+ - **Official Plugins Included**:
23
+ - **`Camera` (Lens)**: 5 specialized camera types (`Follow`, `Pan`, `Spectate`, `Influence`, `Transition`), 29 shake presets, smooth zoom, zero-pop transitions, and native 2D canvas debug overlays.
24
+ - **`Network`**: Structured client-server packet communication with registered names and automatic indexing for bandwidth optimization.
25
+ - **Developer CLI (`kit`)**:
26
+ - **`kit init`**: Interactive scaffolding for Singleplayer and Multiplayer game templates.
27
+ - **`kit build`**: Zero-config compilation, asset hashing (`.vyr`), metadata manifest generation, and production minification/obfuscation.
28
+ - **`kit host`**: Built-in local HTTP and game server hosting with hot-reloading and LAN network URLs.
29
+ - **`kit create`**: Instant boilerplate generator for typed plugins.
30
+ - **`kit doctor`**: Comprehensive environment and project health diagnostics.
31
+ - **Smart Asset Pipeline**: Fast hashing, automatic passthrough for subdirectories, and automatic metadata manifest generation (`resource.json`, `bounds.json`, `sizes.json`, `icon-points.json`).
32
+ - **Zero-Config TypeScript**: Powered by Bun for blazing fast bundling, incremental watch mode, and complete type safety.
33
+
34
+ ---
4
35
 
5
36
  ## Installation
6
37
 
7
38
  ```bash
39
+ # Global CLI installation (recommended)
8
40
  bun install -g @evitcastudio/kit
41
+
42
+ # Or as a project dependency
43
+ bun add @evitcastudio/kit
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Quickstart
49
+
50
+ ```bash
51
+ # 1. Initialize a new project
52
+ kit init my-game --single --install
53
+
54
+ # 2. Build game and assets
55
+ cd my-game && kit build
56
+
57
+ # 3. Host locally
58
+ kit host
9
59
  ```
10
- > **Note:** The `-g` flag ensures the `kit` CLI tool is globally available in your PATH.
60
+
61
+ Your game will immediately be accessible at `http://localhost:8090` (or `http://localhost:30000` for multiplayer).
62
+
63
+ ---
11
64
 
12
65
  ## CLI Reference & Usage
13
66
 
14
- Kit includes a CLI tool (`kit`) for scaffolding projects, building game assets, generating plugin boilerplate, and diagnosing your environment.
67
+ Kit includes the `kit` CLI for scaffolding, asset compilation, boilerplate generation, and local testing.
15
68
 
16
69
  ### Global Options
17
70
  - `-v, --verbose`: Enables verbose output and detailed debugging logs.
18
- - `-h, --help`: Displays help and usage information for any command.
71
+ - `-h, --help`: Displays help and usage information.
19
72
  - `-V, --version`: Displays the installed Kit CLI version.
20
73
 
21
74
  ---
22
75
 
23
76
  ### `kit init [name]`
24
- Initializes a new game project for the Vylocity Game Engine. If run without arguments or flags, an interactive prompt will guide you through project setup.
77
+ Initializes a new game project. Run without arguments for an interactive setup prompt.
25
78
 
26
79
  ```bash
27
80
  # Interactive setup
@@ -31,195 +84,224 @@ kit init
31
84
  kit init my-game --single --install
32
85
  ```
33
86
 
34
- #### Flags & Options:
35
- | Flag / Option | Type | Default | Description |
36
- | :--- | :--- | :--- | :--- |
37
- | `[name]` | `string` | `kit-project` | The name of the project folder to create. |
38
- | `-s, --single` | `boolean` | `false` | Quick-starts a single-player game template. |
39
- | `-m, --multi` | `boolean` | `false` | Quick-starts a multiplayer game template (pass both `-s` and `-m` for both). |
40
- | `-f, --force` | `boolean` | `false` | Overwrites the destination folder if it already exists without aborting. |
41
- | `-i, --install` | `boolean` | `false` | Automatically runs `bun install` inside the new project directory after creation. |
87
+ | Option | Description | Default |
88
+ | :--- | :--- | :--- |
89
+ | `[name]` | Project folder name. | `kit-project` |
90
+ | `-s, --single` | Scaffolds a single-player game template. | `false` |
91
+ | `-m, --multi` | Scaffolds a multiplayer game template. | `false` |
92
+ | `-f, --force` | Overwrites destination folder if it already exists. | `false` |
93
+ | `-i, --install` | Automatically runs `bun install` after scaffolding. | `false` |
42
94
 
43
95
  ---
44
96
 
45
97
  ### `kit build`
46
- Builds resources and compiles game application code. Automatically detects whether your project is **Singleplayer** or **Multiplayer**, compiles TypeScript entrypoints to `dist/`, copies static web files (`.html`, `.css`, `.ico`, vendor directories), hashes raw assets into unique identifiers (`.vyr`), mirrors custom subdirectories, and exports metadata manifests (`resource.json`, `bounds.json`, `icon-points.json`, and `sizes.json`).
98
+ Compiles TypeScript application code to `dist/`, hashes raw assets into unique identifiers (`.vyr`), mirrors asset subdirectories, and generates metadata manifests.
47
99
 
48
100
  ```bash
49
- # Zero-config build (auto-detects project architecture, builds ./src to ./dist)
101
+ # Zero-config build (auto-detects project architecture)
50
102
  kit build
51
103
 
52
- # Production ready build (minified, obfuscated identifiers, stripped sourcemaps)
53
- kit build -p
54
-
55
- # Watch mode: auto-rebuilds on source or resource changes
104
+ # Watch mode (incremental rebuilds on source or resource changes)
56
105
  kit build --watch
57
106
 
58
- # Build only raw resources with custom directories
59
- kit build -i ./src/resources -o ./dist --no-app
60
-
61
- # Save the resource manifest to a custom location
62
- kit build --manifest ./dist/resource.json
63
- ```
64
-
65
- #### Flags & Options:
66
- | Flag / Option | Type | Required | Default | Description |
67
- | :--- | :--- | :--- | :--- | :--- |
68
- | `-i, --in <path>` | `string` | No | `./src/resources` | Input directory containing raw game assets (`.vyi`, `.vym`, `.vyint`, audio, etc.). |
69
- | `-o, --out <path>` | `string` | No | `./dist` | Destination directory where processed `resources/` and bundled app files will be written. |
70
- | `-m, --manifest <path>` | `string` | No | `./resource.json` | Path where the resource lookup JSON should be saved. If omitted, defaults to `./resource.json` in the current working directory. |
71
- | `-w, --watch` | `boolean` | No | `false` | Watches the source and resource directories for changes and triggers automatic incremental rebuilds. |
72
- | `-is, --ignore-sound` | `boolean` | No | `false` | Skips processing and copying sound and music files (`.mp3`, `.ogg`, `.wav`, etc.). |
73
- | `-p, --prod` | `boolean` | No | `false` | Production mode: enables full minification, identifier obfuscation/mangling, and strips sourcemaps. |
74
- | `--minify` | `boolean` | No | `false` | Minifies bundled JavaScript syntax, whitespace, and variable names. |
75
- | `--obfuscate` | `boolean` | No | `false` | Mangles and obfuscates identifiers across bundled output. |
76
- | `--sourcemap <mode>` | `string` | No | `linked` (`none` in prod) | Sourcemap mode (`none`, `linked`, `inline`, `external`). |
77
- | `--app` / `--no-app` | `boolean` | No | `true` (auto) | Toggles application code bundling. Enabled automatically if `src/index.ts` or `src/client/index.ts` exists. |
78
-
79
- #### What is the Resource Manifest (`resource.json`)?
80
- A manifest is an index or lookup table. `kit build` obfuscates asset names into unique identifiers (`uuid.vyr`) as a security benefit to protect and hide original asset filenames in production. It generates `resource.json` mapping your original human-readable asset names to their engine identifiers:
81
- ```json
82
- {
83
- "icon": [
84
- {
85
- "fileName": "player.vyi",
86
- "resourceIdentifier": "3cf72322-6b92-4ea5-bbca-b96fae1fe440.vyr"
87
- }
88
- ],
89
- "map": [ ... ],
90
- "sound": [ ... ]
91
- }
92
- ```
93
-
94
- #### Custom Asset Subdirectories (Automatic Pass-Through)
95
- Any subdirectories inside your resource folder (e.g. `src/resources/images`, `src/resources/fonts`, `src/resources/emitters`, `src/resources/particles`, etc.) are automatically mirrored to `<out>/resources/<folder>/`. Non-engine files remain in their original form.
96
-
97
- ---
98
-
99
- ### `kit create <type> <name>`
100
- Scaffolds boilerplate files inside an existing Kit project following standard architectural conventions.
101
-
102
- ```bash
103
- # Generate a typed plugin
104
- kit create plugin Inventory
107
+ # Production build (minified, obfuscated identifiers, stripped sourcemaps)
108
+ kit build -p
105
109
  ```
106
110
 
107
- #### Types:
108
- - `plugin`: Creates a new TypeScript file at `src/plugins/<name>.ts` that subclasses `KitPlugin` with typed lifecycle hooks (`onRegistered()`) ready to extend.
111
+ | Option | Description | Default |
112
+ | :--- | :--- | :--- |
113
+ | `-i, --in <path>` | Input resource directory containing raw game assets. | `./src/resources` |
114
+ | `-o, --out <path>` | Output directory for processed assets and bundled code. | `./dist` |
115
+ | `-m, --manifest <path>` | Custom destination path for `resource.json`. | `./resource.json` |
116
+ | `-w, --watch` | Watches source and resource folders for auto-rebuilding. | `false` |
117
+ | `-p, --prod` | Production mode (minification, mangled identifiers, no maps). | `false` |
118
+ | `--minify` / `--obfuscate` | Granular syntax minification or identifier mangling. | `false` |
119
+ | `--sourcemap <mode>` | Sourcemap mode (`none`, `linked`, `inline`, `external`). | `linked` |
120
+ | `--app` / `--no-app` | Toggles application code bundling. | `true` |
121
+
122
+ #### Generated Metadata Manifests
123
+ During build, Kit produces optimized metadata indices in your project:
124
+ - **`resource.json`**: Maps original human-readable asset filenames to obfuscated engine identifiers (`uuid.vyr`).
125
+ - **`bounds.json` & `sizes.json`**: Pre-calculated collision boundaries and dimensions for icons and tiles.
126
+ - **`icon-points.json`**: Defined anchor points and equipment attachment coordinates for sprites.
109
127
 
110
128
  ---
111
129
 
112
130
  ### `kit host`
113
- Hosts the game project locally for development and testing.
131
+ Hosts your compiled game project locally for browser or multiplayer testing.
114
132
 
115
133
  ```bash
116
- # Host the dist folder on port 8090
134
+ # Host dist folder on default port 8090
117
135
  kit host
118
136
 
119
137
  # Build before hosting and specify custom port
120
138
  kit host -b -p 8080
121
139
  ```
122
140
 
123
- #### Options:
124
- - `-p, --port <number>`: Port to bind the server to (default: `8090`).
125
- - `-d, --dir <path>`: Directory containing built files to serve (default: `./dist`).
126
- - `-b, --build`: Trigger a `kit build` before starting the server.
141
+ | Option | Description | Default |
142
+ | :--- | :--- | :--- |
143
+ | `-p, --port <number>` | Port to bind the server to. | `8090` |
144
+ | `-d, --dir <path>` | Directory of built files to serve. | `./dist` |
145
+ | `-b, --build` | Runs `kit build` prior to starting server. | `false` |
127
146
 
128
- #### Behavior:
129
- - **Singleplayer / Client Projects:** Spawns a lightweight local HTTP server powered by Bun that serves `dist/index.html` and static assets with local and network LAN URLs.
130
- - **Multiplayer Projects:** Automatically launches the backend node server (`dist/server.js`) with configured settings (`dist/settings.json`).
147
+ ---
148
+
149
+ ### `kit create <type> <name>`
150
+ Scaffolds typed boilerplate into an existing Kit project.
151
+
152
+ ```bash
153
+ kit create plugin Inventory
154
+ ```
155
+ Generates `src/plugins/inventory.ts` subclassing `KitPlugin` with lifecycle hooks ready to extend.
131
156
 
132
157
  ---
133
158
 
134
159
  ### `kit doctor`
135
- Inspects your local environment and current project health.
160
+ Inspects your local environment and project health (Bun runtime, Git availability, `package.json`, project architecture, and build pipeline).
136
161
 
137
162
  ```bash
138
163
  kit doctor
139
164
  ```
140
165
 
141
- #### What it checks:
142
- - **Bun Runtime:** Verifies that Bun is installed and detects the version.
143
- - **Git Installation:** Verifies that Git is accessible in your `PATH`.
144
- - **Project Structure:** If executed within a game project, checks `package.json`, `@evitcastudio/kit` framework dependencies, and asset folders (`src/resources`).
145
- - **Project Architecture:** Detects whether the project is **Singleplayer** (`src/index.ts`), **Multiplayer** (`src/client` & `src/server`), or **Dedicated Server**.
146
- - **Build Pipeline:** Verifies that a valid build pipeline is configured (either native `kit build` in `package.json` or legacy `bun-build.ts`).
147
-
148
166
  ---
149
167
 
150
168
  ## Runtime Resource Loading
151
169
 
152
- > **Note:** This process is preconfigured for you if you used `kit init`.
153
-
154
- `Kit.setResources()` should be called **before** `VYLO.load()`.
170
+ `Kit.setResources()` loads the generated `resource.json` manifest into the Vylocity engine prior to calling `VYLO.load()`:
155
171
 
156
172
  ```typescript
157
173
  import resourceJSON from 'resource.json';
158
174
 
159
- // Initialize the engine with mapped resources
175
+ // Initialize engine with mapped resource identifiers
160
176
  await Kit.setResources(resourceJSON);
177
+ await VYLO.load();
161
178
  ```
162
179
 
180
+ ---
163
181
 
164
- ## Local Development & Testing
182
+ ## Plugins
165
183
 
166
- Once your project is scaffolded and dependencies are installed and the project has been built, you can run your game locally.
184
+ Kit features a modular plugin architecture. Plugins register via `Kit.registerPlugin()`, are retrievable globally through `Kit.getPlugin(name)`, and communicate across decoupled systems using Kit's typed event bus.
167
185
 
168
- ### Running the Game
186
+ ```typescript
187
+ import { Kit } from '@evitcastudio/kit';
188
+ import { CustomPlugin } from 'custom-plugin';
169
189
 
170
- ```bash
171
- # For Single-Player or Multiplayer games
172
- bun run host
190
+ // Register with Kit
191
+ const plugin = Kit.registerPlugin(CustomPlugin);
192
+
193
+ // Retrieve anywhere by plugin name
194
+ const plugin = Kit.getPlugin<CustomPlugin>('CustomPlugin');
195
+ ```
196
+
197
+ ---
198
+
199
+ ### Official Plugins
200
+
201
+ #### 1. Camera Plugin (`Camera` / `@evitcastudio/lens`)
202
+ High-performance 2D camera system powered by [`@evitcastudio/lens`](https://github.com/EvitcaStudio/Lens). Supports 5 specialized camera types, 29 shake presets, smooth zoom, zero-pop transitions, native canvas debug overlays, and automatic event dispatching.
203
+
204
+ ##### Setup & Quickstart
205
+
206
+ ```typescript
207
+ import { Kit, Camera } from '@evitcastudio/kit';
208
+
209
+ // 1. Register with Kit (indexes under name 'Camera')
210
+ const camera = Kit.registerPlugin(Camera);
211
+
212
+ // 2. Track player entity with smooth lerping & deadzone
213
+ camera.createFollowCamera('main', playerMob, {
214
+ lerp: 0.1,
215
+ deadzone: { width: 64, height: 64 }
216
+ });
173
217
  ```
174
218
 
175
- ### Accessing the Game
219
+ ##### Seamless Transitions
220
+ Blend smoothly between cameras or targets with Hermite spline interpolation and spring-damping (zero visual pop):
176
221
 
177
- The server will be available at the following locations after being hosted:
222
+ ```typescript
223
+ await camera.switchTo(bossCamera, {
224
+ duration: 800,
225
+ smoothing: 'smoothDamp', // or 'cubicSpline'
226
+ springTension: 170,
227
+ springFriction: 26
228
+ });
229
+ ```
178
230
 
179
- > **Singleplayer**
180
- [http://localhost:8090](http://localhost:8090) defined in `./bun-serve.ts`
231
+ ##### Screen Shake & Zoom
232
+ ```typescript
233
+ // Trigger built-in presets or infinite ambient shakes
234
+ camera.shakePreset('explosion-large');
235
+ camera.shakePreset('rumble', undefined, true);
181
236
 
182
- > **Multiplayer or Singleplayer & Multiplayer**
183
- [http://localhost:30000](http://localhost:30000) defined in `./src/server/settings.json`
237
+ // Smooth zoom animations with 30+ easing equations
238
+ camera.zoom(2, 500, 'easeOutCubic');
239
+ camera.zoom(1, 400, 'easeInOutQuad'); // Reset
240
+ ```
184
241
 
242
+ ##### Camera Event Bus
243
+ All camera lifecycle events automatically dispatch to Kit's global event bus (`Kit.on`), allowing audio, gamepad vibration, or UI systems to decouple from camera logic:
185
244
 
186
- ## Plugin Architecture
245
+ ```typescript
246
+ Kit.on('Camera', 'shake-start', (event) => {
247
+ console.log('Camera shaking:', event.data.preset);
248
+ });
187
249
 
188
- ```ts
189
- import { Plugin } from 'custom-plugin';
250
+ Kit.on('Camera', 'transition-start', () => {
251
+ // e.g. animate cinematic bars
252
+ });
253
+ ```
254
+
255
+ ##### Native Debug Overlay & Gizmos
256
+ Built-in 2D canvas overlay for debugging cameras, bounds, target vectors, and crosshairs:
190
257
 
191
- // Register a single plugin
192
- const plugin = Kit.registerPlugin(Plugin);
258
+ ```typescript
259
+ camera.setDebugMode({
260
+ enabled: true,
261
+ showCameraMarkers: true,
262
+ showTargetLines: true,
263
+ showBounds: true,
264
+ showCenterCrosshair: true,
265
+ bounds: { minX: 0, maxX: 2000, minY: 0, maxY: 2000 }
266
+ });
193
267
  ```
194
268
 
195
- ```ts
196
- // Register multiple plugins
197
- import { Plugin1 } from 'custom-plugin1';
198
- import { Plugin2 } from 'custom-plugin2';
269
+ ---
270
+
271
+ #### 2. Network Plugin (`Network`)
272
+ Handles client-server packet communication with registered packet names, automatic indexing, and minimal bandwidth usage.
273
+
274
+ ```typescript
275
+ import { Kit, Network } from '@evitcastudio/kit';
199
276
 
200
- const plugins = Kit.registerPlugins([Plugin1, Plugin2]);
277
+ const network = Kit.registerPlugin(Network);
201
278
 
202
- // After being registered, kit can find the plugin by name.
203
- const plugin1 = Kit.getPlugin('plugin1-name');
204
- const plugin2 = Kit.getPlugin('plugin2-name');
279
+ // Client-side: register server packet definitions & listen
280
+ network.registerPackets(['CHAT_MESSAGE', 'PLAYER_HEAL'] as const);
281
+
282
+ network.on('CHAT_MESSAGE', (client, senderName, message) => {
283
+ console.log(`[${senderName}]: ${message}`);
284
+ });
205
285
  ```
206
286
 
207
- ### Listening for plugin events
287
+ ---
208
288
 
209
- Plugins emit events, this is how they pass relevant data to other plugins or the main thread.
210
- By listening to these events you can act on this data.
289
+ ### Plugin Events
211
290
 
212
- ```js
213
- const listener = (pEvent: EmitterEvent) => {
214
- const { data, timestamp } = pEvent;
215
- // Here you can use the data that the event sent down.
216
- }
291
+ Plugins can emit and listen to events across the entire application:
217
292
 
218
- // Choose to listen to specific event from a plugin
219
- Kit.on('plugin-name', 'event-name', listener);
293
+ ```typescript
294
+ // Listen for an event from any plugin
295
+ Kit.on('plugin-name', 'event-name', (event) => {
296
+ console.log(event.data, event.timestamp);
297
+ });
220
298
 
221
- // You can also stop listening for an event
299
+ // Remove listener
222
300
  Kit.off('plugin-name', 'event-name', listener);
223
301
  ```
224
302
 
225
- For more information check out the [wiki](https://github.com/EvitcaStudio/Kit/wiki)
303
+ ---
304
+
305
+ ## License
306
+
307
+ MIT © [Evitca Studio](https://evitcastudio.com) & [doubleactii](https://github.com/doubleactii)