Перейти к основному содержанию

ModAPI

Module used to share mods' APIs.

Index

Interfaces

ModDocumentation

ModDocumentation:

Objects used to represent mod API documentation.

name

name: string

Full name of the API.

props

props: object

Object containing descriptions of methods and properties of the API, where keys are methods and properties names and values are their descriptions.

Variables

Functions

addAPICallback

  • addAPICallback(apiName: string, func: (api: object) => void): void
  • Adds callback for the specified mod API.


    Parameters

    • apiName: string

      API name from ModAPI.registerAPI call

    • func: (api: object) => void

      callback that is called when API is loaded

      Returns void

    addModCallback

    • addModCallback(modName: string, func: any): void
    • That feature is obsolete

      No longer supported.


      Parameters

      • modName: string
      • func: any

      Returns void

    addTexturePack

    • addTexturePack(path: any): void
    • That feature is obsolete

      No longer supported.


      Parameters

      • path: any

      Returns void

    cloneAPI

    • cloneAPI<T>(api: T, recursive?: boolean): T
    • Recursively copies (duplicates) the value to the new one.


      Type parameters

      • T

      Parameters

      • api: T

        an object to be copied

      • optionalrecursive: boolean

        if true, copies the object recursively

      Returns T

      A copy of the object.

    cloneObject

    • cloneObject<T>(source: T, recursive?: boolean, depth?: number): T
    • Recursively clones object to the new one counting call depth and interrupting copying after 7th recursion call.


      Type parameters

      • T: object

      Parameters

      • source: T

        an object to be cloned

      • optionalrecursive: boolean

        if true, copies the object recursively

      • optionaldepth: number

        current recursion state, if > 6, recursion stops; default value is 0

      Returns T

      Cloned object, all the properties that are less then 8 in depth, get copied.

    debugCloneObject

    • debugCloneObject<T>(source: T, recursive?: boolean, depth?: number): T | string
    • Same as ModAPI.cloneObject, but if call depth is more then 6, inserts "stackoverflow" string value otherwise.


      Type parameters

      • T

      Parameters

      • source: T
      • optionalrecursive: boolean
      • optionaldepth: number

      Returns T | string

    getModByName

    • getModByName(modName: string): void
    • That feature is obsolete

      No longer supported.


      Parameters

      • modName: string

      Returns void

    getModList

    • getModList(): string[]
    • That feature is obsolete

      No longer supported.


      Returns string[]

    getModPEList

    • getModPEList(): string[]
    • That feature is obsolete

      No longer supported.


      Returns string[]

    inheritPrototypes

    • inheritPrototypes<K, T>(source: K, target: T): K & T
    • Ensures target object has all the properties the source object has, if not, copies them from source to target object.


      Type parameters

      • K: object
      • T: object

      Parameters

      • source: K

        object to copy missing values from

      • target: T

        object to copy missing values to

      Returns K & T

    isModLoaded

    • isModLoaded(modName: string): void
    • That feature is obsolete

      No longer supported.


      Parameters

      • modName: string

      Returns void

    registerAPI

    • registerAPI(name: string, api: object, descr?: { name?: string; props?: object }): void
    • Registers new API for the mod and invokes mod API callback.

      More about capabilities

      Sometimes it is useful to provide the ability to run third party code in your own mod, you can create a method that provides such possibility:

      requireGlobal(command) {
      return eval(command);
      }

      Parameters

      • name: string

        API name used to import it in the other mods

      • api: object

        object that is shared with the other mods; may contain other objects, methods, variables, etc.

      • optionaldescr: { name?: string; props?: object }

        simple documentation for the mod API

        • optionalname: string

          Full name of the API, if not specified, name parameter value is used.

        • optionalprops: object

          Object containing descriptions of methods and properties of the API, where keys are methods and properties names and values are their descriptions.

          That feature is obsolete

          Writing documentation that way is not recommended.

      Returns void

    requireAPI

    • requireAPI(name: string): Nullable<object>
    • Gets API by it's name. The best approach is to call this method in the function passed as the second parameter of ModAPI.addAPICallback.

      Learn how to use

      Importing API registered by IndustrialCraft PE:

      let ICore = null;
      ModAPI.addAPICallback("ICore", function(api) {
      ICore = api;
      });

      When using ICore variable from the example, be sure to check it for null because Industrial Craft PE may not be installed on the user's phone.


      Parameters

      Returns Nullable<object>

      API object if an API with specified was previously registered, null otherwise.

    requireAPIPropertyDoc

    • requireAPIPropertyDoc(name: string, prop: string): Nullable<string>
    • Fetches information about the method or property of mod API.

      That feature is obsolete

      Writing documentation that way is not recommended.


      Parameters

      Returns Nullable<string>

      String description of the method or null if no description was provided by API vendor.

    requireAPIdoc

    requireGlobal

    • requireGlobal(name: string): any
    • Executes string in Core Engine's global context. Can be used to get functions and objects directly from Adapted Script.


      Parameters

      • name: string

        string to be executed in Core Engine's global context

      Returns any

      null if execution failed or appropriate variable same.