Let catalog packages award their own achievements

Add the bounded entity.achievements service to the package bridge. It
takes metric, source and amount (1..1000), derives the app from the
verified node identity, accepts only <package id>.<name> metrics and
records the fact for today.

Installed package leaves that are not legacy Inbe apps are now captured
under their expected_id asset folder and canonical id, so their
achievements.json registers, evaluates and shows the usual toast. The
saved leaves format moves to 2 so older caches rescan once.
This commit is contained in:
waozi committed 2026-10-29 20:26:08 -03:00
1 parent cf1323ac8f
commit 7198ba453e
8 files changed
+153 -16

No files matched your search

+4
View File
@@ -1,5 +1,9 @@
# Changelog
## [Unreleased]
- Catalog games can award their own achievements, with the usual top-right notification.
## [2.1.61] - 2026-10-29
- Sync no longer gets stuck after something is deleted.
+3
View File
@@ -11,6 +11,8 @@
AchievementLocaleAssetFn :: #type (app: string, path: string) -> AssetView;
achievement_locale_asset: AchievementLocaleAssetFn;
AchievementLocaleDirectoryFn :: #type (app: string) -> string;
achievement_locale_directory: AchievementLocaleDirectoryFn;
// A badge's shape from its own app's package, or "" without one.
AchievementIconShape :: (entry: *AchievementDefinition) -> string {
@@ -32,6 +34,7 @@ achievement_translation_at: s32;
AchievementLocaleRead :: (app: string, code: string, key: string, maximum: s32) -> string {
directory := ifx app == "inbe" then "app" else (ifx app.count > 5 && app[:5] == "inbe." then app[5:] else "")
if directory == "" && achievement_locale_directory != null { directory = achievement_locale_directory(app) }
if directory == "" { return "" }
out: Vec(u8)
BuilderPrint(*out, "assets/%/achievement-locales/%.json", directory, code)
+15 -13
View File
@@ -53,12 +53,7 @@ AchievementInstalled :: (id: string) -> bool {
count := NodeAppInstalledLeafCount()
if count > 64 { count = 64 }
for slot: cast(s32)0..count - 1 {
owner := NodeAppInstalledLeafName(slot)
if owner == "" { continue }
canonical := PackageText("inbe.", owner)
installed := canonical == id
PackageFree(canonical)
if installed { return true }
if NodeAppInstalledLeafName(slot) != "" && NodeAppInstalledLeafID(slot) == id { return true }
}
return false
}
@@ -78,10 +73,9 @@ AchievementNodeCatalogs :: () {
owner := NodeAppInstalledLeafName(slot)
if owner == "" { continue }
path := NodeAppAssetPath(owner, "achievements.json")
app := PackageText("inbe.", owner)
defer { PackageFree(path); PackageFree(app) }
defer { PackageFree(path) }
asset := NodeAppInstalledLeafAsset(slot, owner, path)
if asset.found { unused AchievementCatalog(asset.data, app) }
if asset.found { unused AchievementCatalog(asset.data, NodeAppInstalledLeafID(slot)) }
}
}
@@ -91,14 +85,21 @@ AchievementLocaleAsset :: (app: string, path: string) -> AssetView {
for slot: cast(s32)0..count - 1 {
owner := NodeAppInstalledLeafName(slot)
if owner == "" { continue }
id := PackageText("inbe.", owner)
match := app == id
PackageFree(id)
if match { return NodeAppInstalledLeafAsset(slot, owner, path) }
if NodeAppInstalledLeafID(slot) == app { return NodeAppInstalledLeafAsset(slot, owner, path) }
}
return AssetRead(path)
}
// An installed package's asset directory, by its canonical id.
AchievementLocaleDirectory :: (app: string) -> string {
count := NodeAppInstalledLeafCount()
if count > 64 { count = 64 }
for slot: cast(s32)0..count - 1 {
if NodeAppInstalledLeafID(slot) == app { return NodeAppInstalledLeafName(slot) }
}
return ""
}
AchievementLumiPracticeSaved :: (id: string, activity: s32, day: s32) {
app := CurrentApp()
if app != null && app.lumi_practice != 0 {
@@ -143,6 +144,7 @@ AchievementFrame :: (app: *InnerBreeze) {
achievement_dirty = true
}
achievement_locale_asset = AchievementLocaleAsset
achievement_locale_directory = AchievementLocaleDirectory
AchievementLocaleFrame()
AchievementVisibility()
revision := AchievementSourceRevision()
+40 -1
View File
@@ -20,6 +20,7 @@
#import "std/byte_text_linux"
#import, file "../app/assets.zi";
#import, file "../storage/achievements.zi";
#import, file "../storage/achievement_records.zi";
NodeInstalledLeaf :: struct {
identity: AppIdentity
@@ -70,6 +71,25 @@ NodeInstalledPath :: (owner: string, index: s32) -> string {
return BuilderFinish(out)
}
// Any other package keeps its assets under "assets/<expected_id>/" and its
// achievements under its own verified id. It never takes an Inbe app's id.
NodeInstalledPackageOwner :: (node: *AppNode, output: []u8) -> bool {
id := TextUntilNul(node.identity.id[:])
name := TextUntilNul(node.entry.expected_id[:])
if id == "inbe" || (id.count > 5 && id[:5] == "inbe.") || !AchievementNameValid(id) ||
name.count < 1 || name.count > 24 {
return false
}
for byte: name {
letter := byte >= #char "a" && byte <= #char "z"
digit := byte >= #char "0" && byte <= #char "9"
if !letter && !digit && byte != #char "-" {
return false
}
}
return CopyCString(name, output)
}
NodeInstalledCapture :: (slot: s32, node: *AppNode) -> bool {
account := NodeTreeAccount()
if account != TextUntilNul(node_installed_account[:]) {
@@ -78,6 +98,12 @@ NodeInstalledCapture :: (slot: s32, node: *AppNode) -> bool {
}
runner := *node_runners[slot]
owner := ifx node != null then NodeTreeLegacyOwner(runner, node) else NodeAppVerifiedLeafName(slot)
other_package := false
package_owner: [25]u8
if owner == "" && node != null && NodeInstalledPackageOwner(node, package_owner[:]) {
owner = TextUntilNul(package_owner[:])
other_package = true
}
if owner == "" { return true }
entry: NodeInstalledLeaf
unused CopyCString(owner, entry.owner[:])
@@ -95,6 +121,8 @@ NodeInstalledCapture :: (slot: s32, node: *AppNode) -> bool {
PackageFree(path)
if !asset.found { continue }
if asset.data.count > 262144 || (index == 0 && !AchievementCatalog(asset.data, canonical, false)) {
// A package's faulty catalog only loses its own achievements.
if other_package { continue }
for text: entry.assets { PackageFree(text) }
return false
}
@@ -234,7 +262,8 @@ NodeInstalledScanStep :: (slot: s32) -> bool {
// release and account, so a launch knows an installed collection's games
// and their achievements without opening it: opening Arcade's five bundles
// before anything else froze a phone for seconds.
NODE_SNAPSHOT_FORMAT :: "inbe-leaves-1"
// Format 2 also holds other packages' leaves, so older files rescan once.
NODE_SNAPSHOT_FORMAT :: "inbe-leaves-2"
NodeSnapshotCursor :: struct {
at: s64
@@ -423,6 +452,16 @@ NodeAppInstalledLeafName :: (index: s32) -> string {
return ""
}
NodeAppInstalledLeafID :: (index: s32) -> string {
for at: cast(s64)0..node_installed_leaves.count - 1 {
entry := *node_installed_leaves[at]
if !NodeInstalledRepresentative(at) { continue }
if index == 0 { return TextUntilNul(entry.identity.id[:]) }
index -= 1
}
return ""
}
NodeAppInstalledLeafAsset :: (index: s32, owner: string, path: string) -> AssetView {
for at: cast(s64)0..node_installed_leaves.count - 1 {
entry := *node_installed_leaves[at]
+10 -1
View File
@@ -42,6 +42,7 @@ Legacy :: #import "apps/node_types";
#import, file "../storage/game_scores.zi";
#import, file "../storage/entity_service.zi";
#import, file "../storage/dew_rewards.zi";
#import, file "../storage/achievements.zi";
#import, file "../app/smooth_frames.zi";
#import, file "app_identity_storage.zi";
#import, file "../storage/storage_settings.zi";
@@ -167,7 +168,8 @@ NodeTreeAllows :: (context: *void, node: *AppNode, name: string) -> bool {
return false
}
if name == "AppServiceHost" || name == "entity.records" || name == "entity.dew" || name == PublicationsService || name == "leaderboard" ||
name == "arcade.navigation" || name == "entity.profile" || name == "tile_map.sampling" { return true }
name == "arcade.navigation" || name == "entity.profile" || name == "tile_map.sampling" ||
name == "entity.achievements" { return true }
if name == "AppRecordHost" || name == "SaveAppRecordHost" || name == "AppLocaleHost" ||
name == "SmoothFramesHost" || name == "ClipboardCopyHost" || name == "ReadStoreHost" ||
name == "WriteStoreHost" || name == "AppNowHost" || name == "AppLocalOffsetHost" ||
@@ -222,6 +224,13 @@ NodeTreeCall :: (context: *void, node: *AppNode, module: *u8, function: *u8,
result.* = NodeAppString(DewGameAnswer(AppArgumentText(arguments[1])))
return 1
}
// A package's own achievement fact; Breeze evaluates it and shows
// its usual toast. The metric must carry the verified package id.
if AppArgumentText(arguments[0]) == "entity.achievements" && !node_tree_validating && !node_snapshot_scanning {
saved := AchievementPackageReport(TextUntilNul(node.identity.id[:]), AppArgumentText(arguments[1]))
result.* = NodeAppString(ifx saved then "{\"status\":\"saved\"}" else "{\"status\":\"rejected\"}")
return 1
}
if AppArgumentText(arguments[0]) == "leaderboard" && !node_tree_validating && !node_snapshot_scanning {
saved := GameScoreReport(NodeAppName(NodeAppSlotOf(runner)), TextUntilNul(node.identity.id[:]),
TextUntilNul(node.entry.title[:]), AppArgumentText(arguments[1]))
+29
View File
@@ -256,6 +256,35 @@ AchievementRecord :: (metric: string, source: string, day: s32, amount: s64 = 1,
return true
}
// A hosted package's own fact, from {"metric","source","amount"}. The app is
// the package's verified identity, never a name the package reports.
AchievementPackageReport :: (app: string, request: string) -> bool {
if app == "inbe" || (app.count > 5 && app[:5] == "inbe.") || !AchievementNameValid(app) ||
request.count < 2 || request.count > 1024 {
return false
}
end := ValueEnd(request, Space(request, 0), 0)
if end < 0 || Space(request, end) != request.count {
return false
}
metric: [97]u8
source: [129]u8
amount := ReadNumber(request, FieldAt(request, 0, "amount"))
if ReadStringText(request, FieldAt(request, 0, "metric"), metric[:]) < 1 ||
ReadStringText(request, FieldAt(request, 0, "source"), source[:]) < 1 {
return false
}
if !amount.valid || amount.value < 1 || amount.value > 1000 ||
amount.value != cast(float64)cast(s64)amount.value {
return false
}
name := TextUntilNul(metric[:])
if !AchievementAppMetricAllowed(app, name) {
return false
}
return AchievementRecord(name, TextUntilNul(source[:]), AchievementToday(), cast(s64)amount.value)
}
AchievementToday :: () -> s32 {
day := LocalNow()
if !day.valid { return 0 }
+30
View File
@@ -197,6 +197,36 @@ Check :: () -> s32 {
check_int("radio day needs a minute", metric_value("radio.playback", "days"), 1)
check_int("count each sufficiently heard station once", metric_value("radio.playback", "station_minutes"), 1)
check_true("reject fabricated radio duration", !AchievementRecord("radio.playback", "invalid-radio", 20261001, 100, started = 1000, ended = 1001))
// A hosted package awards only its own metric, under its verified id.
package_catalog := "{\"schema\":1,\"app\":\"xyz.waozi.choano\",\"achievements\":[{\"id\":\"xyz.waozi.choano.full_size\",\"group\":\"choano\",\"metric\":\"xyz.waozi.choano.full_size\",\"rule\":\"count\",\"target\":1,\"variant\":\"\",\"pack\":\"\",\"needs\":\"\",\"title_key\":\"achievement_choano_full_size_title\",\"description_key\":\"achievement_choano_full_size_description\",\"title\":\"Full size\",\"description\":\"Grow to full size in the amoeba dish and unlock Fish mode.\",\"icon\":\"assets/choano/icons/xyz.waozi.choano.full_size.shape\",\"icon_source\":\"mingcute_regular_trophy\"}]}"
check_true("reject a package catalog under another id", !AchievementCatalog(package_catalog, "xyz.waozi.other", false))
check_true("reject a package catalog under an Inbe id", !AchievementCatalog(package_catalog, "inbe.lists", false))
check_true("accept a package catalog under its own id", AchievementCatalog(package_catalog, "xyz.waozi.choano"))
package_index := achievement_count - 1
achievement_definitions[package_index].visible = true
full_size := "{\"metric\":\"xyz.waozi.choano.full_size\",\"source\":\"full-size\",\"amount\":1}"
check_true("reject another package's metric", !AchievementPackageReport("xyz.waozi.other", full_size))
check_true("reject an Inbe identity", !AchievementPackageReport("inbe.lists", "{\"metric\":\"inbe.lists.done\",\"source\":\"a\",\"amount\":1}"))
check_true("reject a metric with a longer prefix", !AchievementPackageReport("xyz.waozi.choano",
"{\"metric\":\"xyz.waozi.choanox.full_size\",\"source\":\"full-size\",\"amount\":1}"))
check_true("reject the bare package id", !AchievementPackageReport("xyz.waozi.choano",
"{\"metric\":\"xyz.waozi.choano\",\"source\":\"full-size\",\"amount\":1}"))
check_true("reject a zero amount", !AchievementPackageReport("xyz.waozi.choano",
"{\"metric\":\"xyz.waozi.choano.full_size\",\"source\":\"full-size\",\"amount\":0}"))
check_true("reject an amount above 1000", !AchievementPackageReport("xyz.waozi.choano",
"{\"metric\":\"xyz.waozi.choano.full_size\",\"source\":\"full-size\",\"amount\":1001}"))
check_true("reject a fractional amount", !AchievementPackageReport("xyz.waozi.choano",
"{\"metric\":\"xyz.waozi.choano.full_size\",\"source\":\"full-size\",\"amount\":1.5}"))
check_true("reject a missing source", !AchievementPackageReport("xyz.waozi.choano",
"{\"metric\":\"xyz.waozi.choano.full_size\",\"amount\":1}"))
check_true("reject trailing request data", !AchievementPackageReport("xyz.waozi.choano", "{\"metric\":\"x\"} {}"))
check_int("rejected reports record nothing", metric_value("xyz.waozi.choano.full_size", "count"), 0)
check_true("accept the package's own metric", AchievementPackageReport("xyz.waozi.choano", full_size))
check_true("a repeated report is idempotent", AchievementPackageReport("xyz.waozi.choano", full_size))
check_int("count the package fact once", metric_value("xyz.waozi.choano.full_size", "count"), 1)
AchievementEvaluate()
check_true("award the package achievement", achievement_definitions[package_index].awarded)
check_int("present the package award once", AchievementConsumeAlerts(), 1)
AchievementReset()
check_true("reload durable catalog", AchievementCatalog(catalog, "inbe"))
achievement_definitions[0].visible = true
+22 -1
View File
@@ -251,6 +251,24 @@ SnapshotRootOpenCheck :: () -> s32 {
return 0
}
snapshot_package_node: AppNode;
// Other packages keep their own asset folder and canonical id, but can
// never stand in for an Inbe app.
SnapshotPackageOwnerCheck :: () -> s32 {
node := *snapshot_package_node
owner: [25]u8
unused CopyCString("xyz.waozi.choano", node.identity.id[:])
unused CopyCString("choano", node.entry.expected_id[:])
if !NodeInstalledPackageOwner(node, owner[:]) || TextUntilNul(owner[:]) != "choano" { return 110 }
unused CopyCString("inbe.photos", node.identity.id[:])
if NodeInstalledPackageOwner(node, owner[:]) { return 111 }
unused CopyCString("xyz.waozi.choano", node.identity.id[:])
unused CopyCString("../photos", node.entry.expected_id[:])
if NodeInstalledPackageOwner(node, owner[:]) { return 112 }
return 0
}
#program_export
Check :: () -> s32 {
root: [14]u8
@@ -277,7 +295,8 @@ Check :: () -> s32 {
NodeAppSetMark("photos", true)
NodeAppSetMark("arcade", true)
before := NodeAppInstalledLeafRevision()
if NodeAppInstalledLeafCount() != 1 || NodeAppInstalledLeafName(0) != "photos" { return 3 }
if NodeAppInstalledLeafCount() != 1 || NodeAppInstalledLeafName(0) != "photos" ||
NodeAppInstalledLeafID(0) != "inbe.photos" { return 3 }
NodeAppSetMark("arcade", false)
if NodeAppInstalledLeafCount() != 1 || NodeAppInstalledLeafRevision() == before { return 4 }
asset := NodeAppInstalledLeafAsset(0, "photos", "assets/photos/achievements.json")
@@ -300,6 +319,8 @@ Check :: () -> s32 {
if icons != 0 { return icons }
images := NodeTreeImagesCheck()
if images != 0 { return images }
packages := SnapshotPackageOwnerCheck()
if packages != 0 { return packages }
storage_close()
return 0
}