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. |
| getCurrent () | Returns the draft whose script is currently executing. |
| 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 its json definition. |
| draft:getBridgePrice () | Returns the bridge price defined for this road draft. |
| draft:getBuildHeight () | Returns the build height of the building. |
| draft:getCapacity () | Returns the capacity of a car draft. |
| draft:getColors () | Returns an array of hex colors for shading the primary frames of this draft. |
| draft:getContent () | For data drafts only: returns the raw json definition of the draft. |
| draft:getDepotCapacity () | Returns the amount of vehicles that can be stored in the given depot building. |
| 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:getOverlayColors () | Returns an array of hex colors for shading the overlay frames of this draft. |
| draft:getOverlayFrame ([frameIndex=1]) | Returns an overlay frame specified by its index (starting with 1). |
| draft:getOverlayFrameCount () | Returns the number of overlay frames defined in this car 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:getSpeed () | Returns the speed of a car draft. |
| draft:getTail () | Returns the tail of a car 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:hasLights () | Returns true if a building, road, road decoration, or fence draft has an animation spot whose animation is marked as a light or a switching light. |
| 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:isIndustrial () | Returns true iff the draft defines an 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: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)
- getCurrent ()
-
Returns the draft whose script is currently executing. Returns nil when
called outside a draft script callback or when the draft is not available.
New feature:
-
This is a new feature that was added in version 1.13.00
Returns:
-
draft or nil
The current executing draft, or nil.
Usage:
local current = Draft.getCurrent() if current then print(current:getId()) end
- 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 its json definition.
Returns:
-
string
The author.
- draft:getBridgePrice ()
-
Returns the bridge price defined for this road draft.
The actual bridge price depends on its height.
For levels of 2 and more the bridge price will usually be used twice.
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 visual 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.
Returns:
-
int
- draft:getCapacity ()
-
Returns the capacity of a car draft.
Returns:
-
int
The capacity of the car, bus stop or building.
- draft:getColors ()
-
Returns an array of hex colors for shading the primary frames of this draft.
Only applicable to car drafts.
Returns:
-
array[string] or nil
An array of hex strings. Is nil if there are no colors.
- draft:getContent ()
-
For data drafts only: returns the raw json definition of the draft.
Returns:
-
table
The json object of the data draft as a Lua table.
- draft:getDepotCapacity ()
-
Returns the amount of vehicles that can be stored in the given depot building.
Returns:
-
int
The depot capacity.
- 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.
Returns:
-
int
Diamond price or 0 if there was no diamond price set.
nil if the draft does not support to have a diamond 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.
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.
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:getOverlayColors ()
-
Returns an array of hex colors for shading the overlay frames of this draft.
Only applicable to car drafts.
Returns:
-
array[string] or nil
An array of hex strings. Is nil if there are no colors.
- draft:getOverlayFrame ([frameIndex=1])
-
Returns an overlay frame specified by its index (starting with 1).
Only applicable to car drafts.
Parameters:
- frameIndex int (default 1)
Returns:
-
int
A frame, represented by a single number.
- draft:getOverlayFrameCount ()
-
Returns the number of overlay frames defined in this car draft.
Only applicable to car drafts; returns 0 when no overlay frames are defined.
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.
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:getSpeed ()
-
Returns the speed of a car draft.
Returns:
-
number
The speed of the car.
- draft:getTail ()
-
Returns the tail of a car draft.
Returns:
-
Array[CarDraft] or nil
Returns nil if the car has no tail.
- 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.
Returns:
-
int
The diamond price of tunnels.
- draft:getTunnelPrice ()
-
Returns the tunnel price defined for this road draft.
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.
Returns:
-
string
The unified draft ID.
- draft:getWater ()
-
Returns the amount of water the building produces.
Negative numbers indicate consumption.
For buildings only.
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.
Returns:
-
bool
True if the road draft has road decorations
- draft:hasLights ()
-
Returns true if a building, road, road decoration, or fence draft has an
animation spot whose animation is marked as a light or a switching light.
Checks both regular and foreground animation spots where supported; returns
false for other draft types or when no such spot exists. This describes the
draft's animations, not whether a light is currently visible or turned on.
New feature:
-
This is a new feature that was added in version 1.12.99
Returns:
-
bool
True if the draft has a light animation spot.
- 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.
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:isIndustrial ()
-
Returns true iff the draft defines an 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.
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: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).
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 determines whether they appear in
the toolbar.
You may have to call City.rebuildUI() for the change to become visible
in the toolbar.
Parameters:
- state bool The new visibility state.