@sharpee/helpers 1.0.8 → 1.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 +71 -0
- package/builders/object.d.ts +11 -1
- package/builders/object.d.ts.map +1 -1
- package/builders/object.js +15 -1
- package/builders/object.js.map +1 -1
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @sharpee/helpers
|
|
2
|
+
|
|
3
|
+
Fluent entity builder helpers for the Sharpee Interactive Fiction platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sharpee/helpers
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Concise, chainable builders that take the boilerplate out of constructing entities and their traits:
|
|
14
|
+
|
|
15
|
+
- **`world.helpers()`** - Importing the package augments `WorldModel`, exposing `room`, `object`, `container`, `actor`, and `door` builders.
|
|
16
|
+
- **Fluent traits** - Set descriptions, aliases, locations, and common traits without hand-assembling `IdentityTrait`, `SceneryTrait`, etc.
|
|
17
|
+
- **`.plural()`** - Marks an object as grammatically plural so messages agree in number ("the goats **are** fixed in place").
|
|
18
|
+
- **Direct use** - `createHelpers()` and the `EntityHelpers` / builder classes are exported for use outside the augmentation.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import '@sharpee/helpers'; // side-effect import: activates world.helpers()
|
|
24
|
+
import { WorldModel } from '@sharpee/world-model';
|
|
25
|
+
|
|
26
|
+
function initializeWorld(world: WorldModel): void {
|
|
27
|
+
const { room, object, container, actor } = world.helpers();
|
|
28
|
+
|
|
29
|
+
const kitchen = room('Kitchen')
|
|
30
|
+
.description('A warm kitchen.')
|
|
31
|
+
.build();
|
|
32
|
+
|
|
33
|
+
const knife = object('bread knife')
|
|
34
|
+
.description('A sharp bread knife.')
|
|
35
|
+
.aliases('knife', 'blade')
|
|
36
|
+
.in(kitchen)
|
|
37
|
+
.build();
|
|
38
|
+
|
|
39
|
+
// grammatically plural scenery
|
|
40
|
+
object('pygmy goats')
|
|
41
|
+
.description('Three goats chew contentedly.')
|
|
42
|
+
.plural()
|
|
43
|
+
.scenery()
|
|
44
|
+
.in(kitchen)
|
|
45
|
+
.build();
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Object builder methods
|
|
50
|
+
|
|
51
|
+
| Method | Effect |
|
|
52
|
+
|--------|--------|
|
|
53
|
+
| `description(text)` | Sets the object description |
|
|
54
|
+
| `aliases(...names)` | Adds alternative parser names |
|
|
55
|
+
| `in(entity)` | Places the object in a location |
|
|
56
|
+
| `scenery()` | Marks as scenery (non-portable) |
|
|
57
|
+
| `plural()` | Marks as grammatically plural |
|
|
58
|
+
| `lightSource(opts?)` | Adds a `LightSourceTrait` |
|
|
59
|
+
| `addTrait(trait)` | Adds any custom `ITrait` |
|
|
60
|
+
| `skipValidation()` | Bypasses placement validation (uses `AuthorModel`) |
|
|
61
|
+
| `build()` | Creates and returns the `IFEntity` |
|
|
62
|
+
|
|
63
|
+
## Related Packages
|
|
64
|
+
|
|
65
|
+
- [@sharpee/world-model](https://www.npmjs.com/package/@sharpee/world-model) - Entity, trait, and behavior system
|
|
66
|
+
- [@sharpee/queries](https://www.npmjs.com/package/@sharpee/queries) - LINQ-style entity queries
|
|
67
|
+
- [@sharpee/sharpee](https://www.npmjs.com/package/@sharpee/sharpee) - Full platform bundle
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
package/builders/object.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ObjectBuilder — fluent builder for object entities.
|
|
3
3
|
*
|
|
4
|
-
* Public interface: description, aliases, in, scenery, lightSource,
|
|
4
|
+
* Public interface: description, aliases, in, scenery, plural, lightSource,
|
|
5
5
|
* skipValidation, build.
|
|
6
6
|
*
|
|
7
7
|
* Owner context: @sharpee/helpers (ADR-140)
|
|
@@ -27,6 +27,7 @@ export declare class ObjectBuilder {
|
|
|
27
27
|
private _aliases?;
|
|
28
28
|
private _location?;
|
|
29
29
|
private _scenery;
|
|
30
|
+
private _grammaticalNumber?;
|
|
30
31
|
private _lightSource?;
|
|
31
32
|
private _skipValidation;
|
|
32
33
|
private _traits;
|
|
@@ -58,6 +59,15 @@ export declare class ObjectBuilder {
|
|
|
58
59
|
* @returns this (for chaining)
|
|
59
60
|
*/
|
|
60
61
|
scenery(): this;
|
|
62
|
+
/**
|
|
63
|
+
* Mark the object as grammatically plural (e.g. "pygmy goats", "direction
|
|
64
|
+
* signs"). Sets the identity's `grammaticalNumber` to `'plural'` so message
|
|
65
|
+
* templates render agreeing verbs ("the goats are fixed in place") and
|
|
66
|
+
* pronouns ("take them").
|
|
67
|
+
*
|
|
68
|
+
* @returns this (for chaining)
|
|
69
|
+
*/
|
|
70
|
+
plural(): this;
|
|
61
71
|
/**
|
|
62
72
|
* Add light source trait.
|
|
63
73
|
*
|
package/builders/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/helpers/src/builders/object.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,QAAQ,EAKT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/helpers/src/builders/object.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,QAAQ,EAKT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IAWtB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,IAAI;IAXd,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,CAAW;IAC5B,OAAO,CAAC,SAAS,CAAC,CAAW;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,kBAAkB,CAAC,CAAwB;IACnD,OAAO,CAAC,YAAY,CAAC,CAA0C;IAC/D,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,OAAO,CAAgB;gBAGrB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM;IAGtB;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK/B;;;;;OAKG;IACH,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;IAKjC;;;;;OAKG;IACH,EAAE,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAK5B;;;;OAIG;IACH,OAAO,IAAI,IAAI;IAKf;;;;;;;OAOG;IACH,MAAM,IAAI,IAAI;IAKd;;;;;OAKG;IACH,WAAW,CAAC,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;IAKrE;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7B;;;;;OAKG;IACH,cAAc,IAAI,IAAI;IAKtB;;;;OAIG;IACH,KAAK,IAAI,QAAQ;CA8BlB"}
|
package/builders/object.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* ObjectBuilder — fluent builder for object entities.
|
|
4
4
|
*
|
|
5
|
-
* Public interface: description, aliases, in, scenery, lightSource,
|
|
5
|
+
* Public interface: description, aliases, in, scenery, plural, lightSource,
|
|
6
6
|
* skipValidation, build.
|
|
7
7
|
*
|
|
8
8
|
* Owner context: @sharpee/helpers (ADR-140)
|
|
@@ -29,6 +29,7 @@ class ObjectBuilder {
|
|
|
29
29
|
_aliases;
|
|
30
30
|
_location;
|
|
31
31
|
_scenery = false;
|
|
32
|
+
_grammaticalNumber;
|
|
32
33
|
_lightSource;
|
|
33
34
|
_skipValidation = false;
|
|
34
35
|
_traits = [];
|
|
@@ -75,6 +76,18 @@ class ObjectBuilder {
|
|
|
75
76
|
this._scenery = true;
|
|
76
77
|
return this;
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Mark the object as grammatically plural (e.g. "pygmy goats", "direction
|
|
81
|
+
* signs"). Sets the identity's `grammaticalNumber` to `'plural'` so message
|
|
82
|
+
* templates render agreeing verbs ("the goats are fixed in place") and
|
|
83
|
+
* pronouns ("take them").
|
|
84
|
+
*
|
|
85
|
+
* @returns this (for chaining)
|
|
86
|
+
*/
|
|
87
|
+
plural() {
|
|
88
|
+
this._grammaticalNumber = 'plural';
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
78
91
|
/**
|
|
79
92
|
* Add light source trait.
|
|
80
93
|
*
|
|
@@ -116,6 +129,7 @@ class ObjectBuilder {
|
|
|
116
129
|
name: this.name,
|
|
117
130
|
description: this._description,
|
|
118
131
|
aliases: this._aliases,
|
|
132
|
+
grammaticalNumber: this._grammaticalNumber,
|
|
119
133
|
}));
|
|
120
134
|
if (this._scenery) {
|
|
121
135
|
entity.add(new world_model_1.SceneryTrait());
|
package/builders/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/helpers/src/builders/object.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,sDAM8B;AAG9B;;;;;;;;;;;GAWG;AACH,MAAa,aAAa;
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/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ID,sCA2IC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharpee/helpers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Fluent entity builder helpers for Sharpee Interactive Fiction Platform",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@sharpee/world-model": "^1.
|
|
15
|
+
"@sharpee/world-model": "^1.1.1"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|
|
18
18
|
"interactive-fiction",
|