Module Draft

Draft library for TheoTown

A draft can be considered a single "plugin object" like a building.

This library contains functions and methods to access drafts and query basic information about them.

Multiple scripts can be attached to a single draft.

Usage:

    local d = Draft.getDraft('$park00')
    print(tostring(d))
    

Functions

append (json) Adds a JSON code to the list of JSON codes that will be loaded by the game.
callAll (name[, arg1[, arg2[, ...]]]) Calls the event function called name on all scripts if defined.
getDraft (id) Returns the draft of the given id.
getDrafts ([tag]) Returns an array of drafts that have the given tag defined.
merge (json) Merges the provided JSON object into the json object that is being loaded by the game right now.

Class Draft

Draft:call (name[, arg1[, arg2[, ...]]]) Calls the event function called name on all scripts of the draft if defined.
Draft:getAuthor () Returns the author of the draft as defined in it's definition.
Draft:getFrame ([frameIndex=1]) Returns a frame specified by its index (starting with 1).
Draft:getFrameCount () Returns the number of frames defined in that draft.
Draft:getHeight () Returns the height of the building.
Draft:getId () Returns the id of the draft.
Draft:getMeta () Returns the meta table of the draft if available.
Draft:getMonthlyPrice () Returns the monthly price defined for this draft.
Draft:getPluginId () Returns the plugin id of the plugin the draft belongs to.
Draft:getPreviewFrame ([frameIndex=1]) Returns a preview frame specified by its index (starting with 1).
Draft:getPreviewFrameCount () Returns the number of preview frames defined in that draft.
Draft:getPrice () Returns the price defined for this draft.
Draft:getScripts () Returns an array of all attached scripts to this draft.
Draft:getText () Returns the localized description of the draft.
Draft:getTitle () Returns the localized title of the draft.
Draft:getType () Returns a string that represents the concrete type of the draft.
Draft:getWidth () Returns the width of the building.
Draft:isAnimation () Returns true iff the draft defines an animation.
Draft:isBuilding () Returns true iff the draft defines a building.
Draft:isCar () Returns true iff the draft defines a car.
Draft:isCategory () Returns true iff the draft defines a category.
Draft:isCommercial () Returns true iff the draft defines a commercial building.
Draft:isGround () Returns true iff the draft defines a ground type.
Draft:isIndustrial () Returns true iff the draft defines a industrial building.
Draft:isPlugin () Returns true iff the draft is part of a plugin (also local ones).
Draft:isPrivileged () Returns true iff the draft is privileged.
Draft:isRCI () Returns true iff the draft defines a building that is either residential, commercial or industrial.
Draft:isResidential () Returns true iff the draft defines a residential building.
Draft:isRoad () Returns true iff the draft defines a road.
Draft:isRoadDecoration () Returns true iff the draft defines a road decoration.
Draft:isTemplate () Returns true iff the draft defines a draft template.
Draft:isTree () Returns true iff the draft defines a tree.
Draft:isUnlocked () Returns whether this draft is unlocked.
Draft:isVisible () Returns true iff the draft is visible.
Draft:setFrame (frameIndex, frame) Overrides a frame by index.
Draft:setPreviewFrame (frameIndex, frame) Overrides a frame by index.
Draft:setVisible (state) Sets the visibility state of the draft.


Functions

append (json)
Adds a JSON code to the list of JSON codes that will be loaded by the game. Can only be called during the main call of the Lua script. That is, when the script's main body is called. Can be useful to generate JSON code dynamically.

Parameters:

  • json string A string containing the JSON code to load.

Usage:

    local json1 = [[
    [
      {
        "id":"somerandoasdfjldjfkl1",
        "type":"script",
        "script":"function script:init() Debug.toast('Appending draft is working 1') end"
      }
    ]
    ]]
    Draft.append(json1)
    
callAll (name[, arg1[, arg2[, ...]]])
Calls the event function called name on all scripts if defined.

Parameters:

  • name string
  • arg1 (optional)
  • arg2 (optional)
  • ... (optional)
getDraft (id)
Returns the draft of the given id. nil is returned if no draft of the given id was found.

Parameters:

Returns:

    draft
getDrafts ([tag])
Returns an array of drafts that have the given tag defined. If no tag is provided this function returns a list of all available drafts.

Parameters:

Returns:

    array
merge (json)
Merges the provided JSON object into the json object that is being loaded by the game right now. Can only be called during the main call of the Lua script. That is, when the script's main body is called. Can be useful to define JSON code dynamically for the current draft. Will only have an effect for attributes that were not read by the game, yet.

Parameters:

  • json string A string containing the JSON code to merge. Must be a JSON object.

Usage:

    local json = [[
      {
        "animation":[{"id":"3x2l_right_1","x":1,"y":2}]
      }
    ]]
    Draft.mege(json)
    

Class Draft

This type represents drafts.
Draft:call (name[, arg1[, arg2[, ...]]])
Calls the event function called name on all scripts of the draft if defined.

Parameters:

  • name string
  • arg1 (optional)
  • arg2 (optional)
  • ... (optional)
Draft:getAuthor ()
Returns the author of the draft as defined in it's definition.

Returns:

    string The author.
Draft:getFrame ([frameIndex=1])
Returns a frame specified by its index (starting with 1).

Parameters:

  • frameIndex number (default 1)

Returns:

    number A frame, represented by a single number.
Draft:getFrameCount ()
Returns the number of frames defined in that draft. Only available for draft types that use frames (e.g. buildings, roads and cars).

Returns:

    number
Draft:getHeight ()
Returns the height of the building. Only available for building drafts.

Returns:

    number
Draft:getId ()
Returns the id of the draft.

Returns:

    string The id.
Draft:getMeta ()
Returns the meta table of the draft if available. nil otherwise.

Returns:

    table
Draft:getMonthlyPrice ()
Returns the monthly price defined for this draft. Not all draft types support to have a monthly price.

Returns:

    number
Draft:getPluginId ()
Returns the plugin id of the plugin the draft belongs to. Only plugins downloaded from Plugin Store have such an id.

Returns:

    int Plugin id of the plugin the draft belongs to; 0 if the plugin was not downloaded from the Plugin Store or if the draft is not part of a plugin
Draft:getPreviewFrame ([frameIndex=1])
Returns a preview frame specified by its index (starting with 1).

Parameters:

  • frameIndex number (default 1)

Returns:

    number A preview frame, represented by a single number.
Draft:getPreviewFrameCount ()
Returns the number of preview frames defined in that draft. Preview frames are frames used to preview the draft in the toolbar.

Returns:

    number
Draft:getPrice ()
Returns the price defined for this draft. Not all draft types support to have a price.

Returns:

    number
Draft:getScripts ()
Returns an array of all attached scripts to this draft. Don't modify the returned array.

Returns:

    array
Draft:getText ()
Returns the localized description of the draft.

Returns:

    string The description.
Draft:getTitle ()
Returns the localized title of the draft.

Returns:

    string The title.
Draft:getType ()
Returns a string that represents the concrete type of the draft.

Returns:

    string
Draft:getWidth ()
Returns the width of the building. Only available for building drafts.

Returns:

    number
Draft:isAnimation ()
Returns true iff the draft defines an animation.

Returns:

    bool
Draft:isBuilding ()
Returns true iff the draft defines a building.

Returns:

    bool
Draft:isCar ()
Returns true iff the draft defines a car.

Returns:

    bool
Draft:isCategory ()
Returns true iff the draft defines a category.

Returns:

    bool
Draft:isCommercial ()
Returns true iff the draft defines a commercial building.

Returns:

    bool
Draft:isGround ()
Returns true iff the draft defines a ground type.

Returns:

    bool
Draft:isIndustrial ()
Returns true iff the draft defines a industrial building.

Returns:

    bool
Draft:isPlugin ()
Returns true iff the draft is part of a plugin (also local ones).

Returns:

    bool True iff the draft is part of a plugin
Draft:isPrivileged ()
Returns true iff the draft is privileged.

Returns:

    bool True iff the draft is privileged
Draft:isRCI ()
Returns true iff the draft defines a building that is either residential, commercial or industrial.

Returns:

    bool
Draft:isResidential ()
Returns true iff the draft defines a residential building.

Returns:

    bool
Draft:isRoad ()
Returns true iff the draft defines a road.

Returns:

    bool
Draft:isRoadDecoration ()
Returns true iff the draft defines a road decoration.

Returns:

    bool
Draft:isTemplate ()
Returns true iff the draft defines a draft template.

Returns:

    bool
Draft:isTree ()
Returns true iff the draft defines a tree.

Returns:

    bool
Draft:isUnlocked ()
Returns whether this draft is unlocked. A draft can be locked if e.g. it depends on a feature to be available.

Returns:

    bool True iff this draft is unlocked.
Draft:isVisible ()
Returns true iff the draft is visible.

Returns:

    bool
Draft:setFrame (frameIndex, frame)
Overrides a frame by index. Starting index is 1.

Parameters:

  • frameIndex number The frame position to overwrite.
  • frame number New frame.
Draft:setPreviewFrame (frameIndex, frame)
Overrides a frame by index. Starting index is 1.

Parameters:

  • frameIndex number The frame position to overwrite.
  • frame number New preview frame.
Draft:setVisible (state)
Sets the visibility state of the draft. For buildings the visibility state defined whether they are present in the toolbar.

Parameters:

  • state bool The new visibility state.
generated by LDoc 1.4.3 Last updated 2020-11-25 06:27:19