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): one HUD, authored once, that outlives the area under it

esengine8f59c319f267
diff --git a/examples/celestial-heights/assets/scenes/hud.esscene b/examples/celestial-heights/assets/scenes/hud.esscene
new file mode 100644
index 000000000..4b61d0fb6
--- /dev/null
+++ b/examples/celestial-heights/assets/scenes/hud.esscene
@@ -0,0 +1,528 @@
+{
+ "version": "1.0",
+ "name": "hud",
+ "folders": [],
+ "entities": [
+ {
+ "id": 50,
+ "name": "Canvas",
+ "parent": null,
+ "children": [
+ 51,
+ 60,
+ 70
+ ],
+ "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,
+ 55
+ ],
+ "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": "",
+ "fontSize": 30,
+ "bold": true,
+ "color": {
+ "r": 0.925,
+ "g": 0.906,
+ "b": 0.98,
+ "a": 1
+ },
+ "align": 0,
+ "verticalAlign": 1
+ }
+ },
+ {
+ "type": "AreaLabel",
+ "data": {}
+ }
+ ]
+ },
+ {
+ "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": {}
+ }
+ ]
+ },
+ {
+ "id": 55,
+ "name": "AchievementToast",
+ "parent": 51,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "display": 1,
+ "height": {
+ "value": 32,
+ "unit": 0
+ },
+ "width": {
+ "value": 100,
+ "unit": 1
+ }
+ }
+ },
+ {
+ "type": "Text",
+ "data": {
+ "content": "",
+ "fontSize": 26,
+ "bold": true,
+ "color": {
+ "r": 0.976,
+ "g": 0.831,
+ "b": 0.475,
+ "a": 1
+ },
+ "align": 0,
+ "verticalAlign": 1
+ }
+ },
+ {
+ "type": "AchievementToast",
+ "data": {}
+ }
+ ]
+ },
+ {
+ "id": 60,
+ "name": "PauseOverlay",
+ "parent": 50,
+ "children": [
+ 61
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "display": 1,
+ "insetLeft": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetRight": {
+ "value": 0,
+ "unit": 0
+ },
+ "insetBottom": {
+ "value": 0,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "FlexContainer",
+ "data": {
+ "direction": 1,
+ "justifyContent": 1,
+ "alignItems": 1,
+ "gap": {
+ "x": 0,
+ "y": 0
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 1,
+ "color": {
+ "r": 0.02,
+ "g": 0.016,
+ "b": 0.04,
+ "a": 0.62
+ },
+ "enabled": true
+ }
+ },
+ {
+ "type": "PauseOverlay",
+ "data": {}
+ }
+ ]
+ },
+ {
+ "id": 61,
+ "name": "PauseLabel",
+ "parent": 60,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "height": {
+ "value": 64,
+ "unit": 0
+ },
+ "width": {
+ "value": 600,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "Text",
+ "data": {
+ "content": "",
+ "i18nKey": "menu.paused",
+ "fontSize": 56,
+ "bold": true,
+ "color": {
+ "r": 0.925,
+ "g": 0.906,
+ "b": 0.98,
+ "a": 1
+ },
+ "align": 1,
+ "verticalAlign": 1
+ }
+ }
+ ]
+ },
+ {
+ "id": 70,
+ "name": "PackPanel",
+ "parent": 50,
+ "children": [
+ 71,
+ 72
+ ],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "display": 1,
+ "insetLeft": {
+ "value": 560,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 300,
+ "unit": 0
+ },
+ "width": {
+ "value": 800,
+ "unit": 0
+ },
+ "height": {
+ "value": 360,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "FlexContainer",
+ "data": {
+ "direction": 1,
+ "justifyContent": 0,
+ "alignItems": 1,
+ "gap": {
+ "x": 0,
+ "y": 16
+ },
+ "padding": {
+ "left": 24,
+ "top": 20,
+ "right": 24,
+ "bottom": 24
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 1,
+ "color": {
+ "r": 0.055,
+ "g": 0.047,
+ "b": 0.098,
+ "a": 0.92
+ },
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 71,
+ "name": "PackTitle",
+ "parent": 70,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "height": {
+ "value": 38,
+ "unit": 0
+ },
+ "width": {
+ "value": 100,
+ "unit": 1
+ }
+ }
+ },
+ {
+ "type": "Text",
+ "data": {
+ "content": "",
+ "i18nKey": "menu.pack",
+ "fontSize": 32,
+ "bold": true,
+ "color": {
+ "r": 0.925,
+ "g": 0.906,
+ "b": 0.98,
+ "a": 1
+ },
+ "align": 1,
+ "verticalAlign": 1
+ }
+ }
+ ]
+ },
+ {
+ "id": 72,
+ "name": "PackGrid",
+ "parent": 70,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "width": {
+ "value": 408,
+ "unit": 0
+ },
+ "height": {
+ "value": 200,
+ "unit": 0
+ }
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/examples/celestial-heights/assets/scenes/hud.esscene.meta b/examples/celestial-heights/assets/scenes/hud.esscene.meta
new file mode 100644
index 000000000..222356ad7
--- /dev/null
+++ b/examples/celestial-heights/assets/scenes/hud.esscene.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "41076064-fa9c-4694-a10a-5fdd7fa7b8e1",
+ "version": "2.0",
+ "type": "scene",
+ "importer": {
+ "autoMigrate": true
+ }
+}
diff --git a/examples/celestial-heights/assets/scenes/main.esscene b/examples/celestial-heights/assets/scenes/main.esscene
index 1c0e8d4ed..3245a1b8e 100644
--- a/examples/celestial-heights/assets/scenes/main.esscene
+++ b/examples/celestial-heights/assets/scenes/main.esscene
@@ -1025,518 +1025,16 @@
]
},
{
- "id": 50,
- "name": "Canvas",
+ "id": 90,
+ "name": "Area",
"parent": null,
- "children": [
- 51,
- 60,
- 70
- ],
- "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,
- 55
- ],
- "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": {}
- }
- ]
- },
- {
- "id": 55,
- "name": "AchievementToast",
- "parent": 51,
- "children": [],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "display": 1,
- "height": {
- "value": 32,
- "unit": 0
- },
- "width": {
- "value": 100,
- "unit": 1
- }
- }
- },
- {
- "type": "Text",
- "data": {
- "content": "",
- "fontSize": 26,
- "bold": true,
- "color": {
- "r": 0.976,
- "g": 0.831,
- "b": 0.475,
- "a": 1
- },
- "align": 0,
- "verticalAlign": 1
- }
- },
- {
- "type": "AchievementToast",
- "data": {}
- }
- ]
- },
- {
- "id": 60,
- "name": "PauseOverlay",
- "parent": 50,
- "children": [
- 61
- ],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "position": 1,
- "display": 1,
- "insetLeft": {
- "value": 0,
- "unit": 0
- },
- "insetTop": {
- "value": 0,
- "unit": 0
- },
- "insetRight": {
- "value": 0,
- "unit": 0
- },
- "insetBottom": {
- "value": 0,
- "unit": 0
- }
- }
- },
- {
- "type": "FlexContainer",
- "data": {
- "direction": 1,
- "justifyContent": 1,
- "alignItems": 1,
- "gap": {
- "x": 0,
- "y": 0
- }
- }
- },
- {
- "type": "UIVisual",
- "data": {
- "visualType": 1,
- "color": {
- "r": 0.02,
- "g": 0.016,
- "b": 0.04,
- "a": 0.62
- },
- "enabled": true
- }
- },
- {
- "type": "PauseOverlay",
- "data": {}
- }
- ]
- },
- {
- "id": 70,
- "name": "PackPanel",
- "parent": 50,
- "children": [
- 71,
- 72
- ],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "position": 1,
- "display": 1,
- "insetLeft": {
- "value": 560,
- "unit": 0
- },
- "insetTop": {
- "value": 300,
- "unit": 0
- },
- "width": {
- "value": 800,
- "unit": 0
- },
- "height": {
- "value": 360,
- "unit": 0
- }
- }
- },
- {
- "type": "FlexContainer",
- "data": {
- "direction": 1,
- "justifyContent": 0,
- "alignItems": 1,
- "gap": {
- "x": 0,
- "y": 16
- },
- "padding": {
- "left": 24,
- "top": 20,
- "right": 24,
- "bottom": 24
- }
- }
- },
- {
- "type": "UIVisual",
- "data": {
- "visualType": 1,
- "color": {
- "r": 0.055,
- "g": 0.047,
- "b": 0.098,
- "a": 0.92
- },
- "enabled": true
- }
- }
- ]
- },
- {
- "id": 71,
- "name": "PackTitle",
- "parent": 70,
- "children": [],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "height": {
- "value": 38,
- "unit": 0
- },
- "width": {
- "value": 100,
- "unit": 1
- }
- }
- },
- {
- "type": "Text",
- "data": {
- "content": "",
- "i18nKey": "menu.pack",
- "fontSize": 32,
- "bold": true,
- "color": {
- "r": 0.925,
- "g": 0.906,
- "b": 0.98,
- "a": 1
- },
- "align": 1,
- "verticalAlign": 1
- }
- }
- ]
- },
- {
- "id": 72,
- "name": "PackGrid",
- "parent": 70,
- "children": [],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "width": {
- "value": 408,
- "unit": 0
- },
- "height": {
- "value": 200,
- "unit": 0
- }
- }
- }
- ]
- },
- {
- "id": 61,
- "name": "PauseLabel",
- "parent": 60,
"children": [],
"visible": true,
"components": [
{
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
+ "type": "Area",
"data": {
- "height": {
- "value": 64,
- "unit": 0
- },
- "width": {
- "value": 600,
- "unit": 0
- }
- }
- },
- {
- "type": "Text",
- "data": {
- "content": "",
- "i18nKey": "menu.paused",
- "fontSize": 56,
- "bold": true,
- "color": {
- "r": 0.925,
- "g": 0.906,
- "b": 0.98,
- "a": 1
- },
- "align": 1,
- "verticalAlign": 1
+ "nameKey": "area.main"
}
}
]
diff --git a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
index 14c6a3656..f82e2d9a4 100644
--- a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
+++ b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
@@ -753,518 +753,16 @@
]
},
{
- "id": 50,
- "name": "Canvas",
+ "id": 90,
+ "name": "Area",
"parent": null,
- "children": [
- 51,
- 60,
- 70
- ],
- "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,
- 55
- ],
- "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": {}
- }
- ]
- },
- {
- "id": 55,
- "name": "AchievementToast",
- "parent": 51,
- "children": [],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "display": 1,
- "height": {
- "value": 32,
- "unit": 0
- },
- "width": {
- "value": 100,
- "unit": 1
- }
- }
- },
- {
- "type": "Text",
- "data": {
- "content": "",
- "fontSize": 26,
- "bold": true,
- "color": {
- "r": 0.976,
- "g": 0.831,
- "b": 0.475,
- "a": 1
- },
- "align": 0,
- "verticalAlign": 1
- }
- },
- {
- "type": "AchievementToast",
- "data": {}
- }
- ]
- },
- {
- "id": 60,
- "name": "PauseOverlay",
- "parent": 50,
- "children": [
- 61
- ],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "position": 1,
- "display": 1,
- "insetLeft": {
- "value": 0,
- "unit": 0
- },
- "insetTop": {
- "value": 0,
- "unit": 0
- },
- "insetRight": {
- "value": 0,
- "unit": 0
- },
- "insetBottom": {
- "value": 0,
- "unit": 0
- }
- }
- },
- {
- "type": "FlexContainer",
- "data": {
- "direction": 1,
- "justifyContent": 1,
- "alignItems": 1,
- "gap": {
- "x": 0,
- "y": 0
- }
- }
- },
- {
- "type": "UIVisual",
- "data": {
- "visualType": 1,
- "color": {
- "r": 0.02,
- "g": 0.016,
- "b": 0.04,
- "a": 0.62
- },
- "enabled": true
- }
- },
- {
- "type": "PauseOverlay",
- "data": {}
- }
- ]
- },
- {
- "id": 70,
- "name": "PackPanel",
- "parent": 50,
- "children": [
- 71,
- 72
- ],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "position": 1,
- "display": 1,
- "insetLeft": {
- "value": 560,
- "unit": 0
- },
- "insetTop": {
- "value": 300,
- "unit": 0
- },
- "width": {
- "value": 800,
- "unit": 0
- },
- "height": {
- "value": 360,
- "unit": 0
- }
- }
- },
- {
- "type": "FlexContainer",
- "data": {
- "direction": 1,
- "justifyContent": 0,
- "alignItems": 1,
- "gap": {
- "x": 0,
- "y": 16
- },
- "padding": {
- "left": 24,
- "top": 20,
- "right": 24,
- "bottom": 24
- }
- }
- },
- {
- "type": "UIVisual",
- "data": {
- "visualType": 1,
- "color": {
- "r": 0.055,
- "g": 0.047,
- "b": 0.098,
- "a": 0.92
- },
- "enabled": true
- }
- }
- ]
- },
- {
- "id": 71,
- "name": "PackTitle",
- "parent": 70,
- "children": [],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "height": {
- "value": 38,
- "unit": 0
- },
- "width": {
- "value": 100,
- "unit": 1
- }
- }
- },
- {
- "type": "Text",
- "data": {
- "content": "",
- "i18nKey": "menu.pack",
- "fontSize": 32,
- "bold": true,
- "color": {
- "r": 0.925,
- "g": 0.906,
- "b": 0.98,
- "a": 1
- },
- "align": 1,
- "verticalAlign": 1
- }
- }
- ]
- },
- {
- "id": 72,
- "name": "PackGrid",
- "parent": 70,
- "children": [],
- "visible": true,
- "components": [
- {
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
- "data": {
- "width": {
- "value": 408,
- "unit": 0
- },
- "height": {
- "value": 200,
- "unit": 0
- }
- }
- }
- ]
- },
- {
- "id": 61,
- "name": "PauseLabel",
- "parent": 60,
"children": [],
"visible": true,
"components": [
{
- "type": "Transform",
- "data": {}
- },
- {
- "type": "UINode",
+ "type": "Area",
"data": {
- "height": {
- "value": 64,
- "unit": 0
- },
- "width": {
- "value": 600,
- "unit": 0
- }
- }
- },
- {
- "type": "Text",
- "data": {
- "content": "",
- "i18nKey": "menu.paused",
- "fontSize": 56,
- "bold": true,
- "color": {
- "r": 0.925,
- "g": 0.906,
- "b": 0.98,
- "a": 1
- },
- "align": 1,
- "verticalAlign": 1
+ "nameKey": "area.moonlit-gallery"
}
}
]
diff --git a/examples/celestial-heights/src/components.ts b/examples/celestial-heights/src/components.ts
index 5672e102f..680cebd32 100644
--- a/examples/celestial-heights/src/components.ts
+++ b/examples/celestial-heights/src/components.ts
@@ -12,6 +12,18 @@ export const Player = defineComponent('Player', {
/** Anything the player fights. */
export const Enemy = defineTag('Enemy');
+/**
+ * What an area says about itself. Every area scene carries exactly one, which is
+ * how the shared HUD — a scene of its own, loaded once and never swapped — can
+ * report where Lyra is without an area having to reach into it.
+ */
+export const Area = defineComponent('Area', {
+ nameKey: '',
+});
+
+/** The HUD line that names the current area, filled in from {@link Area}. */
+export const AreaLabel = defineTag('AreaLabel');
+
/** A way out of an area. `toScene` is the packaged scene name, e.g. `main`. */
export const Gate = defineComponent('Gate', {
toScene: '',
diff --git a/examples/celestial-heights/src/main.ts b/examples/celestial-heights/src/main.ts
index 8cd2b909b..06a55a7e1 100644
--- a/examples/celestial-heights/src/main.ts
+++ b/examples/celestial-heights/src/main.ts
@@ -10,7 +10,9 @@ import {
meleeResolveSystem, damageSystem, invulnerabilitySystem, deathSystem,
} from './systems/combat';
import { healthBarSystem, hitFlashSystem, vitalityMeterSystem } from './systems/feedback';
-import { cameraBindSystem, navFromTerrainSystem, gateSystem } from './systems/world';
+import {
+ cameraBindSystem, navFromTerrainSystem, gateSystem, hudSystem, areaLabelSystem,
+} from './systems/world';
import { pauseInputSystem, pauseTimeSystem, pauseOverlaySystem } from './systems/pause';
import { applySettingsSystem, cycleLanguageSystem } from './systems/settings';
import {
@@ -31,8 +33,10 @@ import { perceiverFacingSystem } from './ai/wisp';
// brings a new camera, a new terrain and a new player, and startup is long past.
addStartupSystem(applySettingsSystem);
+addSystemToSchedule(Schedule.PreUpdate, hudSystem);
addSystemToSchedule(Schedule.PreUpdate, navFromTerrainSystem);
addSystemToSchedule(Schedule.PreUpdate, cameraBindSystem);
+addSystemToSchedule(Schedule.PreUpdate, areaLabelSystem);
addSystemToSchedule(Schedule.PreUpdate, rememberRosterSystem);
addSystemToSchedule(Schedule.PreUpdate, applyRestoreSystem);
addSystemToSchedule(Schedule.PreUpdate, inventoryBuildSystem);
diff --git a/examples/celestial-heights/src/systems/inventory.ts b/examples/celestial-heights/src/systems/inventory.ts
index 0c1abf9d1..e428ed9e7 100644
--- a/examples/celestial-heights/src/systems/inventory.ts
+++ b/examples/celestial-heights/src/systems/inventory.ts
@@ -45,9 +45,9 @@ export const inventoryInputSystem = defineSystem(
{ name: 'InventoryInputSystem' },
);
-// The pack's grid is built into an authored anchor, and an area switch replaces
-// that anchor along with the rest of its scene — so the guard is whether the
-// anchor this was built into is still alive, not whether it was ever built.
+// The pack's grid is built into an authored anchor, so the guard is whether the
+// anchor it was built into is still alive rather than whether it was ever built
+// — a rebuilt HUD hands out a new anchor and the old grid goes with the old one.
let built: { anchor: Entity; data: ArrayDataSource<Slot>; shown: Slot[] } | null = null;
const tileLabel = new Map<Entity, Entity>();
diff --git a/examples/celestial-heights/src/systems/world.ts b/examples/celestial-heights/src/systems/world.ts
index 3630ee906..384a2b2a0 100644
--- a/examples/celestial-heights/src/systems/world.ts
+++ b/examples/celestial-heights/src/systems/world.ts
@@ -1,9 +1,9 @@
import {
defineSystem, Query, Mut, Res, Commands, GetWorld,
- Transform, Camera, FollowTarget, TilemapLayer, RuntimeOnly,
+ Transform, Camera, FollowTarget, TilemapLayer, RuntimeOnly, Text,
Nav, navGridFromTilemapLayer, SceneManager, transitionTo,
} from 'esengine';
-import { Player, Gate, NavGridBuilt } from '../components';
+import { Area, AreaLabel, Player, Gate, NavGridBuilt } from '../components';
/**
* Points the camera at whoever is playing. The camera is authored per area and
@@ -59,6 +59,41 @@ export const navFromTerrainSystem = defineSystem(
/** Tiles that stop movement — mirrors `collision` in assets/tilesets/heights.estileset. */
const SOLID_TILES = [4, 5, 6];
+/** The scene that holds the HUD, the pause panel and the pack. */
+const HUD_SCENE = 'hud';
+
+let hudArriving = false;
+
+/**
+ * Brings the HUD up beside whichever area is playing. An area switch retires
+ * only the scene it replaces, so a HUD loaded additively is authored once and
+ * survives every gate — rather than being copied into each area's scene, where
+ * the copies drift apart the moment one of them is edited.
+ */
+export const hudSystem = defineSystem(
+ [Res(SceneManager)],
+ (scenes) => {
+ if (hudArriving || scenes.isLoaded(HUD_SCENE)) return;
+ hudArriving = true;
+ void scenes.loadAdditive(HUD_SCENE).finally(() => { hudArriving = false; });
+ },
+ { name: 'HudSystem' },
+);
+
+/** Tells the shared HUD which area it is reporting on. */
+export const areaLabelSystem = defineSystem(
+ [Query(Mut(Text), AreaLabel), Query(Area)],
+ (labels, areas) => {
+ for (const [, area] of areas) {
+ for (const [, text] of labels) {
+ if (text.i18nKey !== area.nameKey) text.i18nKey = area.nameKey;
+ }
+ return;
+ }
+ },
+ { name: 'AreaLabelSystem' },
+);
+
/** Walking into a gate hands the game to the next area. */
export const gateSystem = defineSystem(
[Query(Transform, Gate), Query(Transform, Player), Res(SceneManager)],