Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(game): a HUD that reports Lyra, in whatever language you asked for

esengine378fc2d7de75
diff --git a/examples/celestial-heights/assets/i18n/en.eslocale b/examples/celestial-heights/assets/i18n/en.eslocale
new file mode 100644
index 000000000..b09ab9784
--- /dev/null
+++ b/examples/celestial-heights/assets/i18n/en.eslocale
@@ -0,0 +1,9 @@
+{
+ "version": 1,
+ "locale": "en",
+ "entries": {
+ "area.main": "Cherry Blossom Landing",
+ "area.moonlit-gallery": "Moonlit Gallery",
+ "hud.vitality": "Vitality"
+ }
+}
diff --git a/examples/celestial-heights/assets/i18n/en.eslocale.meta b/examples/celestial-heights/assets/i18n/en.eslocale.meta
new file mode 100644
index 000000000..4a3ec365e
--- /dev/null
+++ b/examples/celestial-heights/assets/i18n/en.eslocale.meta
@@ -0,0 +1,6 @@
+{
+ "uuid": "7f1920ee-8df2-4ded-9123-eb51034811cc",
+ "version": "2.0",
+ "type": "locale",
+ "importer": {}
+}
diff --git a/examples/celestial-heights/assets/i18n/zh-CN.eslocale b/examples/celestial-heights/assets/i18n/zh-CN.eslocale
new file mode 100644
index 000000000..a6e60a27a
--- /dev/null
+++ b/examples/celestial-heights/assets/i18n/zh-CN.eslocale
@@ -0,0 +1,9 @@
+{
+ "version": 1,
+ "locale": "zh-CN",
+ "entries": {
+ "area.main": "樱林渡口",
+ "area.moonlit-gallery": "孤月回廊",
+ "hud.vitality": "生命"
+ }
+}
diff --git a/examples/celestial-heights/assets/i18n/zh-CN.eslocale.meta b/examples/celestial-heights/assets/i18n/zh-CN.eslocale.meta
new file mode 100644
index 000000000..8b156550c
--- /dev/null
+++ b/examples/celestial-heights/assets/i18n/zh-CN.eslocale.meta
@@ -0,0 +1,6 @@
+{
+ "uuid": "1e9d0c9d-9def-493a-91ba-89ab679b94f9",
+ "version": "2.0",
+ "type": "locale",
+ "importer": {}
+}
diff --git a/examples/celestial-heights/assets/scenes/main.esscene b/examples/celestial-heights/assets/scenes/main.esscene
index 677df6eb9..9e53ba2b3 100644
--- a/examples/celestial-heights/assets/scenes/main.esscene
+++ b/examples/celestial-heights/assets/scenes/main.esscene
@@ -792,6 +792,224 @@
}
}
]
+ },
+ {
+ "id": 50,
+ "name": "Canvas",
+ "parent": null,
+ "children": [
+ 51
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "Canvas",
+ "data": {
+ "designResolution": {
+ "x": 1920,
+ "y": 1080
+ },
+ "scaleMode": 2
+ }
+ },
+ {
+ "type": "UINode",
+ "data": {}
+ }
+ ]
+ },
+ {
+ "id": 51,
+ "name": "HUD",
+ "parent": 50,
+ "children": [
+ 52,
+ 53
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "insetLeft": {
+ "value": 48,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 40,
+ "unit": 0
+ },
+ "width": {
+ "value": 460,
+ "unit": 0
+ },
+ "height": {
+ "value": 96,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "FlexContainer",
+ "data": {
+ "direction": 1,
+ "justifyContent": 0,
+ "alignItems": 0,
+ "gap": {
+ "x": 0,
+ "y": 12
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 52,
+ "name": "AreaName",
+ "parent": 51,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "height": {
+ "value": 34,
+ "unit": 0
+ },
+ "width": {
+ "value": 100,
+ "unit": 1
+ }
+ }
+ },
+ {
+ "type": "Text",
+ "data": {
+ "content": "",
+ "i18nKey": "area.main",
+ "fontSize": 30,
+ "bold": true,
+ "color": {
+ "r": 0.925,
+ "g": 0.906,
+ "b": 0.98,
+ "a": 1
+ },
+ "align": 0,
+ "verticalAlign": 1
+ }
+ }
+ ]
+ },
+ {
+ "id": 53,
+ "name": "VitalityTrack",
+ "parent": 51,
+ "children": [
+ 54
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "height": {
+ "value": 26,
+ "unit": 0
+ },
+ "width": {
+ "value": 100,
+ "unit": 1
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 1,
+ "color": {
+ "r": 0.078,
+ "g": 0.067,
+ "b": 0.125,
+ "a": 0.85
+ },
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 54,
+ "name": "VitalityFill",
+ "parent": 53,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "insetLeft": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetRight": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetBottom": {
+ "value": 0,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 5,
+ "fillMethod": 0,
+ "fillOrigin": 0,
+ "fillAmount": 1,
+ "color": {
+ "r": 0.906,
+ "g": 0.353,
+ "b": 0.412,
+ "a": 1
+ },
+ "enabled": true
+ }
+ },
+ {
+ "type": "VitalityMeter",
+ "data": {}
+ }
+ ]
}
]
}
diff --git a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
index 2a1e76d5f..1731881ca 100644
--- a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
+++ b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
@@ -604,6 +604,224 @@
}
}
]
+ },
+ {
+ "id": 50,
+ "name": "Canvas",
+ "parent": null,
+ "children": [
+ 51
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "Canvas",
+ "data": {
+ "designResolution": {
+ "x": 1920,
+ "y": 1080
+ },
+ "scaleMode": 2
+ }
+ },
+ {
+ "type": "UINode",
+ "data": {}
+ }
+ ]
+ },
+ {
+ "id": 51,
+ "name": "HUD",
+ "parent": 50,
+ "children": [
+ 52,
+ 53
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "insetLeft": {
+ "value": 48,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 40,
+ "unit": 0
+ },
+ "width": {
+ "value": 460,
+ "unit": 0
+ },
+ "height": {
+ "value": 96,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "FlexContainer",
+ "data": {
+ "direction": 1,
+ "justifyContent": 0,
+ "alignItems": 0,
+ "gap": {
+ "x": 0,
+ "y": 12
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 52,
+ "name": "AreaName",
+ "parent": 51,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "height": {
+ "value": 34,
+ "unit": 0
+ },
+ "width": {
+ "value": 100,
+ "unit": 1
+ }
+ }
+ },
+ {
+ "type": "Text",
+ "data": {
+ "content": "",
+ "i18nKey": "area.moonlit-gallery",
+ "fontSize": 30,
+ "bold": true,
+ "color": {
+ "r": 0.925,
+ "g": 0.906,
+ "b": 0.98,
+ "a": 1
+ },
+ "align": 0,
+ "verticalAlign": 1
+ }
+ }
+ ]
+ },
+ {
+ "id": 53,
+ "name": "VitalityTrack",
+ "parent": 51,
+ "children": [
+ 54
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "height": {
+ "value": 26,
+ "unit": 0
+ },
+ "width": {
+ "value": 100,
+ "unit": 1
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 1,
+ "color": {
+ "r": 0.078,
+ "g": 0.067,
+ "b": 0.125,
+ "a": 0.85
+ },
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 54,
+ "name": "VitalityFill",
+ "parent": 53,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "insetLeft": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetRight": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetBottom": {
+ "value": 0,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 5,
+ "fillMethod": 0,
+ "fillOrigin": 0,
+ "fillAmount": 1,
+ "color": {
+ "r": 0.906,
+ "g": 0.353,
+ "b": 0.412,
+ "a": 1
+ },
+ "enabled": true
+ }
+ },
+ {
+ "type": "VitalityMeter",
+ "data": {}
+ }
+ ]
}
]
}
diff --git a/examples/celestial-heights/src/components.ts b/examples/celestial-heights/src/components.ts
index 8b2f4d4b2..d81f7dc09 100644
--- a/examples/celestial-heights/src/components.ts
+++ b/examples/celestial-heights/src/components.ts
@@ -21,6 +21,9 @@ export const Gate = defineComponent('Gate', {
/** Set once a tilemap's navigation grid has been derived from its tiles. */
export const NavGridBuilt = defineTag('NavGridBuilt');
+/** The HUD bar that reports Lyra's health; its `UIVisual` fill follows her. */
+export const VitalityMeter = defineTag('VitalityMeter');
+
/**
* Where the actor is facing, as a unit vector. Melee arcs and animation both
* read it, so it is written once per actor rather than derived twice from
diff --git a/examples/celestial-heights/src/main.ts b/examples/celestial-heights/src/main.ts
index 368d6cbbe..f69cc4dff 100644
--- a/examples/celestial-heights/src/main.ts
+++ b/examples/celestial-heights/src/main.ts
@@ -5,8 +5,9 @@ import { playerMoveSystem, playerAttackSystem } from './systems/player';
import {
meleeResolveSystem, damageSystem, invulnerabilitySystem, deathSystem,
} from './systems/combat';
-import { healthBarSystem, hitFlashSystem } from './systems/feedback';
+import { healthBarSystem, hitFlashSystem, vitalityMeterSystem } from './systems/feedback';
import { cameraBindSystem, navFromTerrainSystem, gateSystem } from './systems/world';
+import { cycleLanguageSystem } from './systems/settings';
import { perceiverFacingSystem } from './ai/wisp';
// Perception, nav following, the behaviour-tree tick and scene switching are
@@ -22,6 +23,7 @@ addSystemToSchedule(Schedule.Update, playerMoveSystem);
addSystemToSchedule(Schedule.Update, playerAttackSystem);
addSystemToSchedule(Schedule.Update, perceiverFacingSystem);
addSystemToSchedule(Schedule.Update, gateSystem);
+addSystemToSchedule(Schedule.Update, cycleLanguageSystem);
// Damage resolves after everyone has decided to swing, and death after damage,
// so a hit lands in the frame it was thrown rather than the next one.
@@ -30,4 +32,5 @@ addSystemToSchedule(Schedule.PostUpdate, damageSystem);
addSystemToSchedule(Schedule.PostUpdate, deathSystem);
addSystemToSchedule(Schedule.PostUpdate, invulnerabilitySystem);
addSystemToSchedule(Schedule.PostUpdate, healthBarSystem);
+addSystemToSchedule(Schedule.PostUpdate, vitalityMeterSystem);
addSystemToSchedule(Schedule.PostUpdate, hitFlashSystem);
diff --git a/examples/celestial-heights/src/systems/feedback.ts b/examples/celestial-heights/src/systems/feedback.ts
index 1cf8ce329..c91d04fed 100644
--- a/examples/celestial-heights/src/systems/feedback.ts
+++ b/examples/celestial-heights/src/systems/feedback.ts
@@ -1,7 +1,7 @@
import {
- defineSystem, Query, Mut, Transform, Sprite, Parent, GetWorld,
+ defineSystem, Query, Mut, Transform, Sprite, Parent, GetWorld, UIVisual,
} from 'esengine';
-import { Health, HealthBarFill } from '../components';
+import { Health, HealthBarFill, Player, VitalityMeter } from '../components';
/**
* Shrinks a bar towards its left edge. Scaling would take it in from both
@@ -23,6 +23,23 @@ export const healthBarSystem = defineSystem(
{ name: 'HealthBarSystem' },
);
+/**
+ * Drives the HUD meter from Lyra's health. The bar is a `Filled` UI visual, so
+ * the amount is the whole state — no geometry to keep in step with a layout.
+ */
+export const vitalityMeterSystem = defineSystem(
+ [Query(Mut(UIVisual), VitalityMeter), Query(Health, Player)],
+ (meters, players) => {
+ for (const [, visual] of meters) {
+ for (const [, health] of players) {
+ visual.fillAmount = health.max > 0 ? Math.max(0, health.current / health.max) : 0;
+ break;
+ }
+ }
+ },
+ { name: 'VitalityMeterSystem' },
+);
+
/** Blinks whoever is in invulnerability frames, so a hit is visible at all. */
export const hitFlashSystem = defineSystem(
[Query(Mut(Sprite), Health)],
diff --git a/examples/celestial-heights/src/systems/settings.ts b/examples/celestial-heights/src/systems/settings.ts
new file mode 100644
index 000000000..0f3203d6f
--- /dev/null
+++ b/examples/celestial-heights/src/systems/settings.ts
@@ -0,0 +1,18 @@
+import { defineSystem, Res, Input, Localization } from 'esengine';
+
+/**
+ * Cycles the language. Every bound `Text` re-flows on the next frame from its
+ * `i18nKey`, so nothing here touches a label — this is the whole of what the
+ * settings menu will call once it exists.
+ */
+export const cycleLanguageSystem = defineSystem(
+ [Res(Input), Res(Localization)],
+ (input, i18n) => {
+ if (!input.isKeyPressed('KeyL')) return;
+ const locales = i18n.availableLocales();
+ if (locales.length < 2) return;
+ const next = (locales.indexOf(i18n.locale) + 1) % locales.length;
+ i18n.setLocale(locales[next]);
+ },
+ { name: 'CycleLanguageSystem' },
+);
diff --git a/tools/goldenProjects.mjs b/tools/goldenProjects.mjs
index fa66ccde2..db9aa4491 100644
--- a/tools/goldenProjects.mjs
+++ b/tools/goldenProjects.mjs
@@ -71,7 +71,6 @@ export const CAPABILITIES = [
* coverage — the same bargain check-project-settings strikes.
*/
export const KNOWN_GAPS = {
- localization: 'no example swaps locale at runtime; rich-text covers glyphs, not translation — Celestial Heights P3',
touch: 'no example drives synthetic touch; input-actions is keyboard + gamepad — Celestial Heights P5',
'safe-area': 'safe-area insets are exercised by the UI mode viewport, not by a project — Celestial Heights P5',
'pause-resume': 'lifecycle suspend/resume is covered by native hosts, not by a golden project — Celestial Heights P3',
@@ -172,7 +171,10 @@ export const GOLDEN = [
},
{
id: 'celestial-heights',
- certifies: ['tilemap', 'tile-collision', 'navigation', 'behavior-tree', 'scene-transition', 'y-sort'],
+ certifies: [
+ 'tilemap', 'tile-collision', 'navigation', 'behavior-tree',
+ 'scene-transition', 'y-sort', 'localization', 'ui-layout', 'text',
+ ],
targets: ['web', 'desktop'],
// Nightly, not pr: a project earns the release gate by having run, and this
// one has not run anywhere yet. It is also the biggest thing in the corpus.