Module Draft
Draft library for TheoTown
A draft can be considered a single "plugin object" like the template for 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(d:getId())
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 json definition. |
Draft:getBridgePrice () | Returns the bridge price defined for this road draft. |
Draft:getBuildHeight () | Returns the build height of the building. |
Draft:getContent () | For data drafts only: returns the raw json definition of the draft. |
Draft:getDiamondPrice () | Returns the diamond price defined for this draft. |
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:getFrameType ([frameIndex=1]) | Returns the frame type of a frame based on its index (starting with 1). |
Draft:getHeight () | Returns the height of the building. |
Draft:getId () | Returns the ID of the draft. |
Draft:getLevel () | Returns the wealth level of building drafts. |
Draft:getMeta () | Returns the meta table of the draft if available. |
Draft:getMonthlyPrice () | Returns the monthly price defined for this draft. |
Draft:getOrdinal () | Returns the ordinality of the draft. |
Draft:getPluginId () | Returns the plugin ID of the plugin the draft belongs to. |
Draft:getPower () | Returns the amount of power the building produces. |
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:getTunnelDiamondPrice () | Returns the diamond price defined for this road draft. |
Draft:getTunnelPrice () | Returns the tunnel price defined for this road draft. |
Draft:getType () | Returns a string that represents the concrete type of the draft. |
Draft:getUnifiedId () | Returns the unified ID of the draft. |
Draft:getWater () | Returns the amount of water the building produces. |
Draft:getWidth () | Returns the width of the building. |
Draft:hasDecorations () | Returns true iff the draft is a road draft and has automatic road decorations. |
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:isComposition () | Returns true iff the building is a composition. |
Draft:isFinal () | Returns true iff the draft is declared as final (isFinal in json definition). |
Draft:isGround () | Returns true iff the draft defines a ground type. |
Draft:isIndexed () | Returns true if the draft has "index" set to true. |
Draft:isIndustrial () | Returns true iff the draft defines a industrial building. |
Draft:isLoaded () | True unless the plugin is unloaded right now. |
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 (corresponds to negated hidden attribute in json). |
Draft:setFrame (frameIndex, frame) | Overrides a frame by index. |
Draft:setFrameType (frameIndex, frameType) | Sets the frame type of a frame based on its index (starting with 1). |
Draft:setPreviewFrame (frameIndex, frame) | Overrides a frame by index. |
Draft:setVisible (state) | Sets the visibility state of the draft (corresponds to negated hidden attribute in json). |
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:
- id string
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:
- tag string (optional)
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.merge(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 json definition.
Returns:
-
string
The author.
- Draft:getBridgePrice ()
-
Returns the bridge price defined for this road draft.
The actual price for the bridge will depend on the actual height of it.
For levels of 2 and more the bridge price will usually be used twice.
New feature:
-
This is a new feature that was added in version 1.10.69
Returns:
-
int
The price of bridges.
- Draft:getBuildHeight ()
-
Returns the build height of the building. Only available for building drafts.
The build height is the visiual height of the building divided by 8.
Not to be confused with regular height which refers to the height of the
basement of the building from top view.
New feature:
-
This is a new feature that was added in version 1.10.69
Returns:
-
int
- Draft:getContent ()
-
For data drafts only: returns the raw json definition of the draft.
New feature:
-
This is a new feature that was added in version 1.10.66
Returns:
-
table
The json object of the data draft as a Lua table.
- Draft:getDiamondPrice ()
-
Returns the diamond price defined for this draft. Not all draft types support
to have a price. In the desktop version of the game this function will
always return 0.
New feature:
-
This is a new feature that was added in version 1.10.15
Returns:
-
int
Diamond price or 0 if there was no diamond price set.
nil if the draft does not support to have a dimaond price.
- Draft:getFrame ([frameIndex=1])
-
Returns a frame specified by its index (starting with 1).
Parameters:
- frameIndex int (default 1)
Returns:
-
int
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:
-
int
- Draft:getFrameType ([frameIndex=1])
-
Returns the frame type of a frame based on its index (starting with 1).
The frame type is a 0-255 integer number that can be accessed from within
the shader. The values 0-64 can be considered as reserved by the game.
New feature:
-
This is a new feature that was added in version 1.10.91
Parameters:
- frameIndex int (default 1)
Returns:
-
int
The frame type of the queried frame.
- Draft:getHeight ()
-
Returns the height of the building. Only available for building drafts.
Returns:
-
int
- Draft:getId ()
-
Returns the ID of the draft.
Returns:
-
string
The draft ID.
- Draft:getLevel ()
-
Returns the wealth level of building drafts.
New feature:
-
This is a new feature that was added in version 1.10.69
Returns:
-
int
The level of the building ranging from 0 to 2 with 0 being poor.
- Draft:getMeta ()
-
Returns the meta table of the draft if available. nil otherwise.
Returns:
- Draft:getMonthlyPrice ()
-
Returns the monthly price defined for this draft. Not all draft types support
to have a monthly price.
Returns:
-
int
- Draft:getOrdinal ()
-
Returns the ordinality of the draft.
In case of ranks this matches the rank index.
Returns:
-
int
- 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:getPower ()
-
Returns the amount of power the building produces.
Negative numbers indicate consumption. For buildings only.New feature:
-
This is a new feature that was added in version 1.11.37
Returns:
-
int
- Draft:getPreviewFrame ([frameIndex=1])
-
Returns a preview frame specified by its index (starting with 1).
Parameters:
- frameIndex int (default 1)
Returns:
-
int
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:
-
int
- Draft:getPrice ()
-
Returns the price defined for this draft. Not all draft types support
to have a price.
Returns:
-
int
- Draft:getScripts ()
-
Returns an array of all attached scripts to this draft.
Do not 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:getTunnelDiamondPrice ()
-
Returns the diamond price defined for this road draft.
If a diamond price is set it will take precedence to a regular price.
New feature:
-
This is a new feature that was added in version 1.10.69
Returns:
-
int
The diamond price of tunnels.
- Draft:getTunnelPrice ()
-
Returns the tunnel price defined for this road draft.
New feature:
-
This is a new feature that was added in version 1.10.69
Returns:
-
int
The price of tunnels.
- Draft:getType ()
-
Returns a string that represents the concrete type of the draft.
Returns:
- Draft:getUnifiedId ()
-
Returns the unified ID of the draft.
The unified id is the id of the draft but adjusted to be used e.g. for
file names.
Duplicate unified ids are allowed.
New feature:
-
This is a new feature that was added in version 1.10.69
Returns:
-
string
The unified draft ID.
- Draft:getWater ()
-
Returns the amount of water the building produces.
Negative numbers indicate consumption. For buildings only.New feature:
-
This is a new feature that was added in version 1.11.37
Returns:
-
int
- Draft:getWidth ()
-
Returns the width of the building. Only available for building drafts.
Returns:
-
int
- Draft:hasDecorations ()
-
Returns true iff the draft is a road draft and has automatic road decorations.
New feature:
-
This is a new feature that was added in version 1.10.81
Returns:
-
bool
True if the road draft has road decorations
- 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:isComposition ()
-
Returns true iff the building is a composition.
Only available for building drafts.
New feature:
-
This is a new feature that was added in version 1.10.68
Returns:
-
bool
True iff the building is a composition.
- Draft:isFinal ()
-
Returns true iff the draft is declared as final (isFinal in json
definition). Cannot be altered during runtime.
Returns:
-
bool
True iff this draft is final.
- Draft:isGround ()
-
Returns true iff the draft defines a ground type.
Returns:
-
bool
- Draft:isIndexed ()
-
Returns true if the draft has "index" set to true.
This is the default for non privileged drafts.
New feature:
-
This is a new feature that was added in version 1.11.76
Returns:
-
bool
True if index flag is set.
- Draft:isIndustrial ()
-
Returns true iff the draft defines a industrial building.
Returns:
-
bool
- Draft:isLoaded ()
-
True unless the plugin is unloaded right now. This happens for example
when the user enters a city in online mode that doesn't allow plugins.
New feature:
-
This is a new feature that was added in version 1.9.80
Returns:
-
bool
True if the plugin is loaded, otherwise false.
- 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 (corresponds to negated hidden
attribute in json).
Returns:
-
bool
- Draft:setFrame (frameIndex, frame)
-
Overrides a frame by index. Starting index is 1.
Parameters:
- frameIndex int The frame position to overwrite.
- frame int New frame.
- Draft:setFrameType (frameIndex, frameType)
-
Sets the frame type of a frame based on its index (starting with 1).
The frame type is a 0-255 integer number that can be accessed from within
the shader. The values 0-64 can be considered as reserved by the game.
You should only use frame types that are either defined by the game or
were previously allocated using Drawing.allocateFrameType().
Use the frameType value 0 to indicate that the frame has no specific type
(in this case Drawing.setFrameType will take precedence).
New feature:
-
This is a new feature that was added in version 1.10.91
Parameters:
- frameIndex int
- frameType int The frame type to set.
Returns:
-
int
The previously set frame type of the frame.
- Draft:setPreviewFrame (frameIndex, frame)
-
Overrides a frame by index. Starting index is 1.
Parameters:
- frameIndex int The frame position to overwrite.
- frame int New preview frame.
- Draft:setVisible (state)
-
Sets the visibility state of the draft (corresponds to negated hidden
attribute in json).
For buildings the visibility state defined whether they are present in
the toolbar.
You may have to call City.rebuildUI() for the change to become visible
in the toolarbar.
Parameters:
- state bool The new visibility state.