Lua API:Tools

From The Powder Toy
Revision as of 05:12, 15 December 2024 by jacob1 (talk | contribs) (Add to Lua category)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The tools API contains methods for creating and reading properties of custom tools and built-in tools.

"Tools" in a general sense refers to any selectable tool in the game, including elements, tools, walls, and decoration tools. If you can select it and it gets a red border around it, it's a tool, and you can read its properties with this API.

Most of the usefulness of the API comes from creating custom tools. Custom tools receive the same callbacks as everything in the Tools menu. They interact with locations the user is drawing the brush at.

Methods

tools.allocate

tools.free

tools.property

tools.exists

tools.isCustom

Constants

tools.index

A table that maps Identifiers to their tool indices.

airTool = tools.index.DEFAULT_TOOL_AIR

Tool indicies are arbitrary and not guaranteed to be constant for any particular tool between versions.

The identifiers for all built-in and custom tools are in this table. The format for an Identifier depends on the type of tool. It is roughly [group]_[type]_[name], where [group] is DEFAULT for built-in tools, and [type] could be PT, TOOL, WL, or more depending on the type.

You can get an identifier by selecting it and checking ui.activeTool(0). Every selectable tool is available in tools.index for lookup.