@combos-fun/plugin-renderer-3d-text 0.1.15 → 0.1.16

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/agent-skill.md +19 -89
  2. package/package.json +4 -4
package/agent-skill.md CHANGED
@@ -1,104 +1,34 @@
1
1
  # `@combos-fun/plugin-renderer-3d-text` — Agent notes
2
2
 
3
- In-world text backed by `troika-three-text`, suitable for labels, dialogue, signs, and scoreboards.
4
-
5
- Prerequisite: follow the parent `@combos-fun/plugin-renderer-3d` skill for system order, pose seeding, hierarchy, and rendering lifecycle.
6
-
7
- ## Public API
8
-
9
- ```ts
10
- import { Text3D, Text3DSystem, type Text3DParams } from '@combos-fun/plugin-renderer-3d-text';
11
- ```
12
-
13
- `componentName = 'Text3D'`; `systemName = 'Text3DSystem'`.
14
-
15
- For dynamic, translatable text, keep values in named `replacements`; do not
16
- concatenate them into `text` and do not invent translation IDs:
3
+ In-world text. Parent setup: `plugin-renderer-3d`.
17
4
 
18
5
  ```ts
19
- score.addComponent(new Text3D({
20
- text: '{player} scored {score} points',
21
- replacements: { player: 'Alice', score: 100 },
22
- fontSize: 0.4,
23
- }));
6
+ import { Text3D, Text3DSystem } from '@combos-fun/plugin-renderer-3d-text';
24
7
  ```
25
8
 
26
- **MUST** set `Text3DSystem` `sourceLocale` to the game's written language as a
27
- BCP 47 tag (`en`, `en-US`, `zh-CN`, `ja-JP`, …). Match the `Text3D` literals,
28
- not the player device locale. Omitting it disables host i18n.
9
+ `componentName = 'Text3D'`. `systemName = 'Text3DSystem'`.
29
10
 
30
- ```ts
31
- new Text3DSystem({
32
- sourceLocale: 'zh-CN',
33
- sourceTexts: ['开始游戏', '下一关已解锁'],
34
- });
35
- ```
11
+ | Field | Default |
12
+ | --- | --- |
13
+ | `text` | `''` |
14
+ | `replacements` | `{}` |
15
+ | `fontSize` | `0.5` |
16
+ | `color` | `0xffffff` |
17
+ | `anchorX` / `anchorY` | `'center'` / `'middle'` |
18
+ | `maxWidth` | `0` (applied only when `> 0`) |
19
+ | `font` | `''` — URL/path, not a resource name |
20
+ | `positionX/Y/Z`, `rotationX/Y/Z` | `0` |
36
21
 
37
- Pass **every** later-screen template in `sourceTexts` so the first
38
- `requestI18n` translates the full catalog before `ready`. The system keeps one
39
- growing session catalog of source templates and translations: new labels are
40
- added to it, and going back to earlier copy looks up that catalog instead of
41
- rebuilding from the current screen. You can also call
42
- `textSystem.declareSourceTexts([...])` during `onSystemsBootstrapComplete`.
22
+ No scale fields; size is `fontSize`. Glyph layout is async. `maxWidth: 0` and `font: ''` do not undo a previous value.
43
23
 
44
- The source template itself is the translation lookup key. After labels exist,
45
- the system checks that `window.combos.requestI18n` exists. The first
46
- `requestI18n({ sourceLocale, sourceTexts })` runs in `beforeReady` and holds
47
- game `ready` / `start` until the host replies. Labels stay empty until that
48
- first reply so the source language does not flash on the canvas. Apply the
49
- result only when `needed: true`. If that reply is `needed: true` but a current template is
50
- missing from `translations`, send only the still-untranslated templates and
51
- `requestI18n` once more before `ready`. After ready, a new label whose
52
- translation is still missing stays empty, sends only those missing templates,
53
- waits for one more `requestI18n`, then renders. Already-translated templates
54
- are omitted from later `requestI18n` payloads and do not trigger another call
55
- when the same labels go back to earlier copy.
56
- `needed: false` keeps source text and does not hold later labels. Do not post `i18n-ready` / `set-i18n` from
57
- this plugin. If no source locale or method is present, placeholder replacement
58
- still works and source text stays as-is.
24
+ **MUST** `new Text3DSystem({ sourceLocale, sourceTexts })`. `sourceLocale` is the written language (`en`, `zh-CN`, `ja-JP`), not the device locale. `sourceTexts` lists every template. `declareSourceTexts([...])` during `onSystemsBootstrapComplete` also works. Omitting `sourceLocale` disables host i18n.
59
25
 
60
- ## Parameters
61
-
62
- | Field | Type | Default |
63
- |-------|------|---------|
64
- | `text` | `string` | `''` |
65
- | `replacements` | `Record<string, string \| number>` | `{}` |
66
- | `fontSize` | `number` | `0.5` |
67
- | `color` | `number` | `0xffffff` |
68
- | `anchorX` | `string` | `'center'` |
69
- | `anchorY` | `string` | `'middle'` |
70
- | `maxWidth` | `number` | `0`; applied only when `> 0` |
71
- | `font` | `string` | `''`; Troika URL/path, not an engine resource name |
72
- | `positionX/Y/Z` | `number` | `0` |
73
- | `rotationX/Y/Z` | `number` | `0` radians |
74
-
75
- There are no scale fields; use `fontSize` for size.
76
-
77
- ## Runtime and lifecycle
78
-
79
- - ADD creates and attaches a `TroikaText`, then calls its asynchronous `sync()`. Property changes copy values and call `sync()` again.
80
- - Font loading and glyph layout complete asynchronously inside Troika. Do not assume final geometry or metrics immediately after ADD.
81
- - Removal detaches and disposes the Troika object; there is no engine named-resource lifecycle for `font`.
82
- - Pose synchronizes per frame.
83
-
84
- ## Package-specific pitfalls
85
-
86
- - `font` must be a browser-reachable URL/path.
87
- - Setting `maxWidth` back to `0` does not clear a previously applied positive width in the current implementation; likewise, setting `font` back to `''` does not restore the prior/default font.
88
- - Empty text or a background-matching color can look like a render failure.
89
-
90
- ## Minimal example
26
+ `text` is the translation key. Values go in `replacements`. `requestI18n` runs in `beforeReady` and holds `ready` when `window.combos.requestI18n` exists. Labels stay empty until that reply. Apply only when `needed: true`. A missing template is requested once more; after `ready` it stays empty until that reply. One session catalog: new labels are added, earlier screens are looked up, and already translated templates are not sent again. `needed: false` keeps source text. Do not post `i18n-ready` / `set-i18n`. With no `sourceLocale` or `requestI18n`, replacements still run and source text stays.
91
27
 
92
28
  ```ts
93
- const sign = new GameObject('sign');
94
29
  sign.addComponent(new Text3D({
95
- text: 'Welcome',
96
- fontSize: 0.6,
97
- color: 0xffffff,
98
- positionY: 1.5,
30
+ text: '{player} 得分 {score}',
31
+ replacements: { player: 'Alice', score: 100 },
32
+ fontSize: 0.4,
99
33
  }));
100
34
  ```
101
-
102
- ## Verification
103
-
104
- `pnpm --filter @combos-fun/plugin-renderer-3d-text run build`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combos-fun/plugin-renderer-3d-text",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "3D text rendering, backed by troika-three-text",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-3d-text.esm.js",
@@ -28,9 +28,9 @@
28
28
  "dependencies": {
29
29
  "three": "^0.172.0",
30
30
  "troika-three-text": "^0.52.3",
31
- "@combos-fun/inspector-decorator": "0.1.15",
32
- "@combos-fun/plugin-renderer-3d": "0.1.15",
33
- "@combos-fun/engine": "0.1.15"
31
+ "@combos-fun/plugin-renderer-3d": "0.1.16",
32
+ "@combos-fun/inspector-decorator": "0.1.16",
33
+ "@combos-fun/engine": "0.1.16"
34
34
  },
35
35
  "devDependencies": {
36
36
  "tsx": "^4.20.3"