Options
All
  • Public
  • Public/Protected
  • All
Menu

JsonManager loads json files (using XMLHttpRequest), using the "json" resources registered in the game resources.

Contrary to audio/fonts, json files are loaded asynchronously, when requested. You should properly handle errors, and give the developer/player a way to know that loading failed.

Hierarchy

  • JsonManager

Index

Constructors

Methods

  • getLoadedJson(resourceName: string): null | Object
  • Get the object for the given resource that is already loaded (preloaded or loaded with loadJson). If the resource is not loaded, null will be returned.

    Parameters

    • resourceName: string

      The name of the json resource.

    Returns null | Object

    the content of the json resource, if loaded. null otherwise.

  • isJsonLoaded(resourceName: string): boolean
  • Check if the given json resource was loaded (preloaded or loaded with loadJson).

    Parameters

    • resourceName: string

      The name of the json resource.

    Returns boolean

    true if the content of the json resource is loaded. false otherwise.

  • Request the json file from the given resource name. This method is asynchronous. When loaded, the callback is called with the error (null if none) and the loaded json (a JS Object).

    Parameters

    • resourceName: string

      The resource pointing to the json file to load.

    • callback: JsonManagerRequestCallback

      The callback function called when json is loaded (or an error occurred).

    Returns void

  • preloadJsons(onProgress: JsonManagerOnProgressCallback, onComplete: JsonManagerOnCompleteCallback): void
  • Request all the json resources to be preloaded (unless they are marked as not preloaded).

    Note that even if a JSON is already loaded, it will be reloaded (useful for hot-reloading, as JSON files can have been modified without the editor knowing).

    Parameters

    • onProgress: JsonManagerOnProgressCallback

      The function called after each json is loaded.

    • onComplete: JsonManagerOnCompleteCallback

      The function called when all jsons are loaded.

    Returns void

  • setResources(resources: ResourceData[]): void
  • Update the resources data of the game. Useful for hot-reloading, should not be used otherwise.

    Parameters

    • resources: ResourceData[]

      The resources data of the game.

    Returns void

Generated using TypeDoc