5.1 KiB
Gamekit
Gamekit is the code games share: the game standard they implement, the host
that runs them under supervision, and the tool that packs a game into its own
portable .zx app. Games import it through ziran.toml; nothing in it depends
on a particular collection or player.
[dependencies.gamekit]
git = "https://git.waozi.xyz/kryonlabs/gamekit.git"
ref = "master"
Modules
gamekit/contractis the game standard,standards/game-v1.json: contract, module and host API versions, the required and optional host calls, record and resource limits,GameDescriptorRead/GameDescriptorAcceptedfor a game'scatalog.json,GameLocaleLookupfor its locale files and the sharedGameProfile. Portable; games import it too.gamekit/hostruns one game bundle for a native host:GameOpen(game, data_directory, locale),GameFrame(frame)andGameClose(). It checks the bundle against the standard, answers the standard's host calls, keeps records underDATA/games/<id>/recordsand extracts assets under.../resources.GameSetProfile(profile)sets the profileAppProfileHostgives every game: a collection shares its one profile with each downloaded game, and a standalone game keeps its own local one.
A game asks for the profile with
AppProfileHost :: () -> GameProfile #foreign host_api; and treats an empty
identity as signed out.
Packing a game
From the game's own project:
ziran tool gamekit pack catalog.json build/apps/wurm.zx
ziran tool gamekit pack editor/catalog.json build/apps/wurm-editor.zx
MANIFEST is the app's catalog.json, relative to the project root. pack
then:
- stages
assetsasbuild/gamekit/<name>/assets/<name>/, adds the copies in ashared_assets.jsonbeside the manifest and writescatalog.jsonwithoutbuild_definesandprepare_assets; - removes what a
bundle.jsonbeside the manifest leaves out (leave_outwildcard patterns, plusrelease_leave_outwith--release) and keepsart.jsonto the remaining files; - writes the
[<locale_prefix>…]blocks of eachlocales/*.txttolocales/and the matchingGameLocaleText(language, key)tobuild/gamekit/<name>-generated/translations.zi; - runs the game's
prepare_assetsprogram, a Ziran program built from the game's project (or the game's own Python script), asPROGRAM RESOURCES GENERATED; - for an app whose
apps.jsonentryrequiresanother app of the project, replaces byte-identical shared copies by links to that app's resources and writesrequirements.jsonwith the links and the required bundle's SHA-256. An add-on that reuses the game's code imports the game's modules; the linker builds that code into the add-on's own bundle; - bundles
sourceandentrywithziran bundle --project, using the game's own lock (--lockedwithout aziran.local.toml), itsbuild_definesandKRYON_HOSTED_UI.
Pack an app before the apps that require it; they are looked up as
<name>.zx in the output's folder.
The bundle step passes build/gamekit/<name>-generated as
--module-path, so the game imports translations and the modules its
preparation program writes like its own modules; its locked packages never
see them. This needs a game lock pinning Ziran 0c95f849 or later.
Hosted TSX composition
The maintained fixture game and editor compose their screens in
tests/fixture-game/src/fixture.tsx and editor.tsx. The shared
fixture_screen.tsx uses the published kryon/tsx/text and kryon/tsx/button
components with generated English and German translations. Playing a round or
applying an edit updates the native scoring state in fixture_model.zi and
changes the action's label on the next frame. The catalog's source names the
TSX file and its entry names the exported Main function. Packing keeps each
screen and its reachable native rules in its own portable bundle.
The exported contract, supervision, resource handling and pack tool remain
native Ziran. Gamekit does not declare a standalone desktop or browser app;
a native consumer runs its portable screens through GameOpen and GameFrame.
Tests
make test
It checks the modules, compares the contract with standards/game-v1.json,
tests the profile record, locale generation, exclusions and add-on links, and
packs tests/fixture-game and its add-on with the tool built from this tree.
It then opens both bundles with Ziran's bundle loader and checks their frame
and widget capabilities. The staged fixture resolves its published compiler,
Kryon, Apps and Gamekit pins with ziran lock.
The fixture also pins the published Gamekit tool. From tests/fixture-game,
exercise that package route with:
ziran lock
ziran tool gamekit pack catalog.json build/apps/fixture.zx
ziran tool gamekit pack editor/catalog.json build/apps/fixture-editor.zx --release
The fixture declares Arcade as its host. On Linux desktop, the game was verified from Arcade's library and the editor from a private Apps collection that selects the add-on by ID. Both actions repainted after X11 pointer input. Android, Windows and browser hosts are unverified for these fixtures.