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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(game): three achievements, and something that says so
esengine0411832e5688
diff --git a/examples/celestial-heights/assets/i18n/en.eslocale b/examples/celestial-heights/assets/i18n/en.eslocaleindex 24261239f..cce5175de 100644--- a/examples/celestial-heights/assets/i18n/en.eslocale+++ b/examples/celestial-heights/assets/i18n/en.eslocale@@ -9,6 +9,9 @@"menu.pack": "Pack","item.petal": "Petal","item.shard": "Shard",- "item.ember": "Ember"+ "item.ember": "Ember",+ "achievement.first-blood": "Unlocked — First Blood",+ "achievement.collector": "Unlocked — Collector",+ "achievement.wayfarer": "Unlocked — Wayfarer"}}diff --git a/examples/celestial-heights/assets/i18n/zh-CN.eslocale b/examples/celestial-heights/assets/i18n/zh-CN.eslocaleindex 243d43539..2acfa75a6 100644--- a/examples/celestial-heights/assets/i18n/zh-CN.eslocale+++ b/examples/celestial-heights/assets/i18n/zh-CN.eslocale@@ -9,6 +9,9 @@"menu.pack": "行囊","item.petal": "花瓣","item.shard": "晶屑",- "item.ember": "余烬"+ "item.ember": "余烬",+ "achievement.first-blood": "达成——初战告捷",+ "achievement.collector": "达成——采集者",+ "achievement.wayfarer": "达成——远行者"}}diff --git a/examples/celestial-heights/assets/scenes/main.esscene b/examples/celestial-heights/assets/scenes/main.essceneindex ebceb19bb..4d02caeaa 100644--- a/examples/celestial-heights/assets/scenes/main.esscene+++ b/examples/celestial-heights/assets/scenes/main.esscene@@ -998,7 +998,8 @@"parent": 50,"children": [52,- 53+ 53,+ 55],"visible": true,"components": [@@ -1181,6 +1182,53 @@}]},+ {+ "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",diff --git a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene b/examples/celestial-heights/assets/scenes/moonlit-gallery.essceneindex 4a837dc55..9cef1ef39 100644--- a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene+++ b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene@@ -726,7 +726,8 @@"parent": 50,"children": [52,- 53+ 53,+ 55],"visible": true,"components": [@@ -909,6 +910,53 @@}]},+ {+ "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",diff --git a/examples/celestial-heights/project.esproject b/examples/celestial-heights/project.esprojectindex ccd5c2d85..2ff4040e1 100644--- a/examples/celestial-heights/project.esproject+++ b/examples/celestial-heights/project.esproject@@ -13,12 +13,34 @@"features": {"physics": {"enabled": true,- "gravity": { "x": 0, "y": 0 },- "collisionLayers": ["World", "Player", "Enemy"]+ "gravity": {+ "x": 0,+ "y": 0+ },+ "collisionLayers": [+ "World",+ "Player",+ "Enemy"+ ]},"rendering": {- "sortingLayers": ["Ground", "GroundDetail", "Actors", "Overhead", "Vfx"],- "ySortLayers": [2]+ "sortingLayers": [+ "Ground",+ "GroundDetail",+ "Actors",+ "Overhead",+ "Vfx"+ ],+ "ySortLayers": [+ 2+ ]}+ },+ "packaging": {+ "achievements": [+ "first-blood",+ "collector",+ "wayfarer"+ ]}}diff --git a/examples/celestial-heights/src/components.ts b/examples/celestial-heights/src/components.tsindex 0d24b3eed..5672e102f 100644--- a/examples/celestial-heights/src/components.ts+++ b/examples/celestial-heights/src/components.ts@@ -27,6 +27,9 @@ export const VitalityMeter = defineTag('VitalityMeter');/** The panel shown while the game is paused. */export const PauseOverlay = defineTag('PauseOverlay');+/** The HUD line that announces an unlock, since no local store draws one. */+export const AchievementToast = defineTag('AchievementToast');+/** A pickup lying in the world. `kind` keys into ITEM_COLOR and the locale table. */export const Item = defineComponent('Item', {kind: '',diff --git a/examples/celestial-heights/src/main.ts b/examples/celestial-heights/src/main.tsindex 932809e9e..df28e9564 100644--- a/examples/celestial-heights/src/main.ts+++ b/examples/celestial-heights/src/main.ts@@ -18,6 +18,7 @@ import {import {pickupSystem, inventoryInputSystem, inventoryBuildSystem, inventorySyncSystem,} from './systems/inventory';+import { achievementSystem, achievementToastSystem } from './systems/achievements';import { perceiverFacingSystem } from './ai/wisp';// Perception, nav following, the behaviour-tree tick and scene switching are@@ -59,3 +60,5 @@ addSystemToSchedule(Schedule.PostUpdate, healthBarSystem);addSystemToSchedule(Schedule.PostUpdate, vitalityMeterSystem);addSystemToSchedule(Schedule.PostUpdate, hitFlashSystem);addSystemToSchedule(Schedule.PostUpdate, inventorySyncSystem);+addSystemToSchedule(Schedule.PostUpdate, achievementSystem);+addSystemToSchedule(Schedule.PostUpdate, achievementToastSystem);diff --git a/examples/celestial-heights/src/systems/achievements.ts b/examples/celestial-heights/src/systems/achievements.tsnew file mode 100644index 000000000..4ea2b5832--- /dev/null+++ b/examples/celestial-heights/src/systems/achievements.ts@@ -0,0 +1,66 @@+import {+ defineSystem, Query, Mut, Res, EventReader, Achievements, SceneManager,+ Time, Text, UINode, UIDisplay, Localization,+} from 'esengine';+import { Item, AchievementToast } from '../components';+import { Died } from '../events';+import { session } from '../state';++/**+ * The ids are declared in project.esproject; the runtime refuses an unlock that+ * is not among them, so a typo here is an error rather than a silent no-op on+ * whatever store the game ships against.+ */+export const FIRST_BLOOD = 'first-blood';+export const COLLECTOR = 'collector';+export const WAYFARER = 'wayfarer';++/** How many distinct kinds count as having collected. */+const KINDS_FOR_COLLECTOR = 3;++/** Ids in the order they are announced, so a toast names what just happened. */+const ALL = [FIRST_BLOOD, COLLECTOR, WAYFARER];+const seen = new Set<string>();+let toast = { id: '', left: 0 };++export const achievementSystem = defineSystem(+ [EventReader(Died), Query(Item), Res(Achievements), Res(SceneManager)],+ (deaths, _items, achievements, scenes) => {+ for (const death of deaths) {+ if (!death.isPlayer) {+ void achievements.unlock(FIRST_BLOOD);+ break;+ }+ }+ const kinds = Object.values(session.inventory).filter((n) => n > 0).length;+ if (kinds >= KINDS_FOR_COLLECTOR) void achievements.unlock(COLLECTOR);+ if (scenes.getActive() === 'moonlit-gallery') void achievements.unlock(WAYFARER);++ // The local provider draws nothing — the engine says so — so an unlock+ // nobody announces is an achievement the player never got.+ for (const id of ALL) {+ if (seen.has(id) || !achievements.unlocked(id)) continue;+ seen.add(id);+ toast = { id, left: TOAST_SECONDS };+ }+ },+ { name: 'AchievementSystem' },+);++const TOAST_SECONDS = 3.5;++export const achievementToastSystem = defineSystem(+ [Query(Mut(UINode), Mut(Text), AchievementToast), Res(Time), Res(Localization)],+ (toasts, time, i18n) => {+ if (toast.left > 0) toast.left -= time.delta;+ const show = toast.left > 0;+ for (const [, node, text] of toasts) {+ const display = show ? UIDisplay.Flex : UIDisplay.None;+ if (node.display !== display) node.display = display;+ if (!show) continue;+ const label = i18n.t(`achievement.${toast.id}`);+ if (text.content !== label) text.content = label;+ }+ },+ { name: 'AchievementToastSystem' },+);diff --git a/tools/goldenProjects.mjs b/tools/goldenProjects.mjsindex 6470461c1..6da0bd437 100644--- a/tools/goldenProjects.mjs+++ b/tools/goldenProjects.mjs@@ -79,7 +79,6 @@ export const KNOWN_GAPS = {// through the chain by a project the release argues from.settings: 'no project persists graphics/audio/language/rebinds and reads them back — Celestial Heights P3',controller: 'input-actions binds a gamepad, but no golden run drives one — Celestial Heights P5',- achievements: 'the achievements service has no project that unlocks one in play — Celestial Heights P4',// Measured: hello-world exports a 2.82MB single file, video-puzzle 3.22MB — so// the floor is the runtime, not the game, and no project reaches the 2MB cap.'startup-size': 'the playable runtime floor (~2.8MB) exceeds the 2MB default profile cap; see REARCH_EXPORT',@@ -173,7 +172,7 @@ export const GOLDEN = [certifies: ['tilemap', 'tile-collision', 'navigation', 'behavior-tree','scene-transition', 'y-sort', 'localization', 'ui-layout', 'text',- 'persistence', 'ui-inventory',+ 'persistence', 'ui-inventory', 'achievements',],targets: ['web', 'desktop'],// Nightly, not pr: a project earns the release gate by having run, and this