tecs.files
Where a game reads its shipped content from.
nupp.io.files owns every filesystem operation and every writable root: reading, writing, atomic commits, directory streams, temporaries, metadata, and the platform's own configuration, data and cache directories for one named application. This module keeps the one thing Nupp cannot supply, because it is a property of the product rather than of the platform: where this build's content was installed.
const disk = require("nupp.io.files")
disk.setApplicationIdentity("Ex Nihilo", "Starfarer")
const saves = assert(disk.dataPath()):join("saves")
disk.writeAtomic(saves:join("slot1.json"), bytes)
const level = disk.read(tecs.files.assetPath("levels/one.json"))The asset root#
assetRoot is where shipped content lives and is never a place a build may write. TECS_ASSETS wins, which is how a development run reads straight out of a build tree instead of a staged copy. Then the __tecsContent global, since a host knows the layout it installed and this is not something to sniff for. Then the directory the running executable was loaded from, which is where a single-directory build puts everything. assetPath joins against it without checking existence, because a path that is about to be read is as valid a request as one that is already there.
Writable roots#
A game names itself through nupp.io.files.setApplicationIdentity and then asks nupp.io.files for configurationPath, dataPath or cachePath, each of which is a distinct directory that is created before it is answered. Saves and settings belong under dataPath, and anything the game can rebuild belongs under cachePath, which the operating system may empty between any two runs. tecs.application.newApplication names the identity "tecs", "tecs" when a game named none, so an engine test and an unnamed tool write somewhere stable.
Module contents
Functions
| Function | Kind | Description |
|---|---|---|
assetPath | function | Resolves relative against the asset root. |
assetRoot | function | Returns the root the engine reads shipped content from. |
reset | function | Forgets the cached asset root so the next call resolves again. |
setAssetRoot | function | Overrides the asset root, for a test or a tool. |
Values
| Value | Kind | Description |
|---|---|---|
ASSET_ROOT_VARIABLE | variable | Read-only. |
CONTENT_GLOBAL | variable | Read-only. |
Functions#
assetPathfunction#
function assetPath(relative: string): stringResolves relative against the asset root.
Arguments
| Name | Type | Description |
|---|---|---|
relative | string | a path under the content root, with |
Returns
| Type | Description |
|---|---|
string | the joined path, without checking that anything is there |
Raises
| Type | Condition |
|---|---|
string | when relative is empty |
assetRootfunction#
function assetRoot(): stringReturns the root the engine reads shipped content from.
The root is resolved once and remembered, and reset forgets it. An empty answer is not a failure: it means no override named a root and the platform declined to say where the executable is, and a caller falls back to a path relative to the working directory.
Returns
| Type | Description |
|---|---|
string | the root with a trailing separator, or an empty string |
resetfunction#
function reset(): nilForgets the cached asset root so the next call resolves again.
A test that moves TECS_ASSETS between cases needs this. A game does not: nothing under a running process changes where content was installed. The writable roots are nupp.io.files', and resetApplicationPaths forgets those.
Returns
| Type | Description |
|---|---|
nil |
setAssetRootfunction#
function setAssetRoot(root: string): nilOverrides the asset root, for a test or a tool.
Arguments
| Name | Type | Description |
|---|---|---|
root | string | the content directory to read from, with or without a trailing separator |
Returns
| Type | Description |
|---|---|
nil |
Raises
| Type | Condition |
|---|---|
string | when root is empty |
Values#
ASSET_ROOT_VARIABLEvariable#
const ASSET_ROOT_VARIABLERead-only. Names the environment variable that overrides the asset root.
CONTENT_GLOBALvariable#
const CONTENT_GLOBALRead-only. Names the global a host sets to the content root it installed.