@vaguevoid/fiasco / ecs/resources / TextAssetManager
Class: TextAssetManager
Defined in: src/ecs/resources.ts:358
The TextAssetManager
Resource is for loading text files into the engine.
Useful for loading config files at runtime, or providing ID's to the Material Manager.
import { TextAssetManager, EventWriter, Events } from '@vaguevoid/fiasco'
function system(
textAssetManager: TextAssetManager,
writer: EventWriter<Events.Graphics.NewText>
) {
const pendingText = textAssetManager.loadText(writer, "/some/path/file.json")
console.log("text id", pendingText?.id)
}
Extends
Methods
areIdsLoaded()
areIdsLoaded(
ids
):boolean
Defined in: src/ecs/resources.ts:391
Check if multiple text id's are loaded.
import { TextAssetManager} from '@vaguevoid/fiasco'
function system(textAssetManager: TextAssetManager) {
const loaded = textAssetManager.areIdsLoaded([id1, id2, id3])
console.log(`text ids are loaded ${loaded}`)
}
Parameters
ids
TextId
[]
An array of TextId's.
Returns
boolean
True if all the id's are loaded.
deserialize()
deserialize(
bytes
):boolean
Defined in: src/ecs/resources.ts:70
Parameters
bytes
Uint8Array
Returns
boolean
Inherited from
getTextById()
getTextById(
id
):undefined
|Text
Defined in: src/ecs/resources.ts:484
Get the text object for a given text id. The text object can be in any of the 4 states: pending
, loaded
, engine
, failed
.
Check the kind
field to narrow the type and gain access to the fields for that kind.
import { TextAssetManager } from '@vaguevoid/fiasco'
function system(textAssetManager: TextAssetManager) {
const text = textAssetManager.getTextById(id)
if (text?.kind === 'pending') {
// access to pending fields available now
console.log(text.textPath)
}
}
Parameters
id
The text id to retrieve.
Returns
undefined
| Text
A Text discriminate union or undefined
if not available.
isIdLoaded()
isIdLoaded(
id
):boolean
Defined in: src/ecs/resources.ts:409
Check if a given text id is loaded.
import { TextAssetManager } from '@vaguevoid/fiasco'
function system(textAssetManager: TextAssetManager) {
const loaded = textAssetManager.isIdLoaded(id)
console.log(`text id ${id} is loaded ${loaded}`)
}
Parameters
id
The TextId available on a PendingText.
Returns
boolean
True if the id is loaded.
loadText()
loadText(
newTextEventWriter
,textPath
,setUpWatcher
):undefined
|PendingText
Defined in: src/ecs/resources.ts:432
Load a text file into the engine. Supported file types are json
, toml
, csv
or text
.
import { TextAssetManager, EventWriter, Events } from '@vaguevoid/fiasco'
function system(
textAssetManager: TextAssetManager,
writer: EventWriter<Events.Graphics.NewText>
) {
const pendingText = textAssetManager.loadText(writer, "/some/path/file.json")
console.log("text id", pendingText?.id)
}
Parameters
newTextEventWriter
The event writer for NewText.
textPath
string
A path representing a location to the file.
setUpWatcher
boolean
= false
If a watcher should be set up for the given text path.
Returns
undefined
| PendingText
A pending texture or undefined if the text was unable to be loaded.
serialize()
serialize():
Uint8Array
Defined in: src/ecs/resources.ts:65
Returns
Uint8Array