@antha/engine 0.0.8 → 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.
- package/README.md +30 -3
- package/dist/antha-engine.d.ts +5 -6
- package/dist/antha-engine.js +13 -7
- package/package.json +16 -17
package/README.md
CHANGED
|
@@ -1,11 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @antha/engine
|
|
2
2
|
|
|
3
|
-
The Antha game engine (for the web), where everything is a mod!
|
|
3
|
+
The Antha game engine (for the web), where everything is a mod! This engine core package only includes a lightweight framework for flexibly defining, inserting, and running the engine mods.
|
|
4
4
|
|
|
5
5
|
- Demo: https://electrovir.github.io/antha/demo
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm i antha
|
|
10
|
+
npm i @antha/engine
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
<!-- example-link: src/readme-examples/creating-engine.example.ts -->
|
|
16
|
+
|
|
17
|
+
```TypeScript
|
|
18
|
+
import {AnthaEngine, defineAnthaMod} from '@antha/engine';
|
|
19
|
+
|
|
20
|
+
const engine = new AnthaEngine<{
|
|
21
|
+
count: number;
|
|
22
|
+
}>({
|
|
23
|
+
mods: [
|
|
24
|
+
defineAnthaMod<{
|
|
25
|
+
count: number;
|
|
26
|
+
}>({
|
|
27
|
+
modName: 'counter',
|
|
28
|
+
execute({state}) {
|
|
29
|
+
state.count = (state.count ?? 0) + 1;
|
|
30
|
+
|
|
31
|
+
return `Count: ${state.count}`;
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
engine.startLoop();
|
|
11
38
|
```
|
package/dist/antha-engine.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type AnyObject, type Branded, type MaybePromise, type PartialWithUndefined, type RequiredAndNotNull } from '@augment-vir/common';
|
|
1
|
+
import { type AnyObject, type Branded, type MaybePromise, type PartialWithUndefined, type RequiredAndNotNull, type RequireExactlyOne } from '@augment-vir/common';
|
|
2
2
|
import { type HtmlInterpolation } from 'element-vir';
|
|
3
3
|
import { Observable } from 'observavir';
|
|
4
|
-
import { type RequireExactlyOne } from 'type-fest';
|
|
5
4
|
import { type AnthaLogger } from './logger/antha-logger.js';
|
|
6
5
|
/**
|
|
7
6
|
* A string type used for mod instances. In reality these are just strings, but this branded type
|
|
@@ -37,10 +36,10 @@ export type ModCleanupParams<State extends AnyObject> = {
|
|
|
37
36
|
modInstanceId: ModInstanceId;
|
|
38
37
|
} & ModOptions;
|
|
39
38
|
/**
|
|
40
|
-
* Return this from a mod's
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
39
|
+
* Return this from a mod's `execute` callback to instruct {@link AnthaEngine} that the mod's current
|
|
40
|
+
* execution should not count toward the mod's frequency schedule. This is useful when a mod needs a
|
|
41
|
+
* dependency (such as a canvas or external resource) that isn't ready yet so that the engine will
|
|
42
|
+
* keep retrying on subsequent ticks, even if the mod has a low execution frequency.
|
|
44
43
|
*
|
|
45
44
|
* @category Mod
|
|
46
45
|
*/
|
package/dist/antha-engine.js
CHANGED
|
@@ -6,10 +6,10 @@ import { Observable } from 'observavir';
|
|
|
6
6
|
import { AnthaUi } from './antha-ui.element.js';
|
|
7
7
|
import { browserAnthaLogger } from './logger/browser-antha-logger.js';
|
|
8
8
|
/**
|
|
9
|
-
* Return this from a mod's
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Return this from a mod's `execute` callback to instruct {@link AnthaEngine} that the mod's current
|
|
10
|
+
* execution should not count toward the mod's frequency schedule. This is useful when a mod needs a
|
|
11
|
+
* dependency (such as a canvas or external resource) that isn't ready yet so that the engine will
|
|
12
|
+
* keep retrying on subsequent ticks, even if the mod has a low execution frequency.
|
|
13
13
|
*
|
|
14
14
|
* @category Mod
|
|
15
15
|
*/
|
|
@@ -174,7 +174,9 @@ export class AnthaEngine {
|
|
|
174
174
|
await mod.cleanup?.({
|
|
175
175
|
engine: this,
|
|
176
176
|
hostElement: this.getEnsuredHostElement(),
|
|
177
|
-
modInstanceId: getOrSetFromMap(this.modInstanceIdMap, mod, () =>
|
|
177
|
+
modInstanceId: getOrSetFromMap(this.modInstanceIdMap, mod, () => {
|
|
178
|
+
return applyBrand(createId());
|
|
179
|
+
}),
|
|
178
180
|
state: this.state,
|
|
179
181
|
executeImmediately: mod.executeImmediately || false,
|
|
180
182
|
frequency: mod.frequency || undefined,
|
|
@@ -236,7 +238,9 @@ export class AnthaEngine {
|
|
|
236
238
|
}
|
|
237
239
|
const rawResult = mod.execute({
|
|
238
240
|
engine: this,
|
|
239
|
-
modInstanceId: getOrSetFromMap(this.modInstanceIdMap, mod, () =>
|
|
241
|
+
modInstanceId: getOrSetFromMap(this.modInstanceIdMap, mod, () => {
|
|
242
|
+
return applyBrand(createId());
|
|
243
|
+
}),
|
|
240
244
|
currentTick: this.currentTick,
|
|
241
245
|
state: this.state,
|
|
242
246
|
ticksSinceLastExecute: this.currentTick - (lastExecution?.tick ?? 0),
|
|
@@ -292,6 +296,8 @@ export class AnthaEngine {
|
|
|
292
296
|
const msSinceLastExecution = performance.now() - (lastExecution?.timeMs || 0);
|
|
293
297
|
return msSinceLastExecution >= mod.frequency.durationMs;
|
|
294
298
|
}
|
|
295
|
-
|
|
299
|
+
else {
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
296
302
|
}
|
|
297
303
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The Antha game engine (for the web).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -35,27 +35,26 @@
|
|
|
35
35
|
"test:update": "npm test update"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@augment-vir/assert": "^
|
|
39
|
-
"@augment-vir/common": "^
|
|
38
|
+
"@augment-vir/assert": "^32.2.2",
|
|
39
|
+
"@augment-vir/common": "^32.2.2",
|
|
40
40
|
"@paralleldrive/cuid2": "^3.3.0",
|
|
41
|
-
"date-vir": "^
|
|
42
|
-
"observavir": "^2.3.
|
|
43
|
-
"sentry-vir": "^4.
|
|
44
|
-
"type-fest": "^5.7.0"
|
|
41
|
+
"date-vir": "^9.0.0",
|
|
42
|
+
"observavir": "^2.3.3",
|
|
43
|
+
"sentry-vir": "^4.5.1"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
|
-
"@augment-vir/test": "^
|
|
48
|
-
"@augment-vir/web": "^
|
|
49
|
-
"@web/dev-server-esbuild": "^
|
|
50
|
-
"@web/test-runner": "^0.
|
|
51
|
-
"@web/test-runner-commands": "^0.
|
|
52
|
-
"@web/test-runner-playwright": "^0.
|
|
53
|
-
"@web/test-runner-visual-regression": "^0.
|
|
46
|
+
"@augment-vir/test": "^32.2.2",
|
|
47
|
+
"@augment-vir/web": "^32.2.2",
|
|
48
|
+
"@web/dev-server-esbuild": "^2.0.0",
|
|
49
|
+
"@web/test-runner": "^1.0.0",
|
|
50
|
+
"@web/test-runner-commands": "^1.0.1",
|
|
51
|
+
"@web/test-runner-playwright": "^1.0.0",
|
|
52
|
+
"@web/test-runner-visual-regression": "^1.0.1",
|
|
54
53
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
55
|
-
"markdown-code-example-inserter": "^3.0.
|
|
56
|
-
"typedoc": "^0.28.
|
|
54
|
+
"markdown-code-example-inserter": "^3.0.6",
|
|
55
|
+
"typedoc": "^0.28.20",
|
|
57
56
|
"typescript": "^6.0.3",
|
|
58
|
-
"vite": "^8.
|
|
57
|
+
"vite": "^8.2.1"
|
|
59
58
|
},
|
|
60
59
|
"peerDependencies": {
|
|
61
60
|
"element-vir": ">=26"
|