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://github.com/waozixyz/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.
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 ziran tool gamekit pack,
then opens both bundles with Ziran's bundle loader. The fixture test locks a
copy of the fixture against this checkout and the packages ziran.lock
already pins, so it fetches nothing.