@antha/graphics-2d 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +38 -3
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,11 +1,46 @@
1
1
  # @antha/graphics-2d
2
2
 
3
- A pre-built [Antha](https://www.npmjs.com/package/antha) mod that sets up rendering a [PixiJS](https://www.npmjs.com/package/pixi.js) instance to a `<canvas>` element.
4
-
5
- Demo: https://electrovir.github.io/antha/demo/graphics-2d
3
+ This package provides a pre-built [Antha game engine](https://www.npmjs.com/package/@antha/engine) mod that creates and manages a PixiJS application and its canvas.
6
4
 
7
5
  ## Install
8
6
 
9
7
  ```sh
10
8
  npm i @antha/graphics-2d
11
9
  ```
10
+
11
+ ## Usage
12
+
13
+ <!-- example-link: src/readme-examples/drawing-graphics.example.ts -->
14
+
15
+ ```TypeScript
16
+ import {AnthaEngine, defineAnthaMod} from '@antha/engine';
17
+ import {type AnthaGraphics2dModState, createAnthaGraphics2dMod, Graphics} from '@antha/graphics-2d';
18
+
19
+ type GameState = AnthaGraphics2dModState & {
20
+ hasAddedCircle: boolean;
21
+ };
22
+
23
+ const engine = new AnthaEngine<GameState>({
24
+ initState: {
25
+ hasAddedCircle: false,
26
+ },
27
+ mods: [
28
+ createAnthaGraphics2dMod(),
29
+ defineAnthaMod<GameState>({
30
+ modName: 'game-logic',
31
+ execute({state}) {
32
+ if (!state.pixi?.pixiApplication || state.hasAddedCircle) {
33
+ return;
34
+ }
35
+
36
+ state.hasAddedCircle = true;
37
+ state.pixi.pixiApplication.stage.addChild(
38
+ new Graphics().circle(0, 0, 20).fill('white'),
39
+ );
40
+ },
41
+ }),
42
+ ],
43
+ });
44
+
45
+ engine.startLoop();
46
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antha/graphics-2d",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "An Antha mod for rendering 2D graphics to a canvas.",
5
5
  "keywords": [
6
6
  "vir",
@@ -40,8 +40,8 @@
40
40
  "@augment-vir/common": "^32.2.2"
41
41
  },
42
42
  "devDependencies": {
43
- "@antha/engine": "^0.1.0",
44
- "@antha/web-test-runner-plugin-pixi": "^0.1.0",
43
+ "@antha/engine": "^0.1.1",
44
+ "@antha/web-test-runner-plugin-pixi": "^0.1.1",
45
45
  "@augment-vir/test": "^32.2.2",
46
46
  "@electrovir/color": "^1.7.11",
47
47
  "@web/dev-server-esbuild": "^2.0.0",