Tree Planter Tool (Open Source)
Posted: 28 Aug 2020, 12:04
@THEMAX .
The general structure of the code looks like that (omitted implementations for readability) :
The json features real time scripting for testing purposes :
You'll find the git repository here: https://github.com/LobbyDivinus/TreePlanterTool
You can use the option "Download ZIP" to download the whole plugin.
Please feel free to create your own tools based on this one. You can also make changes to this tool and make a pull request of the changes on GitHub.
More detailed documentation about the GUI features in Lua can be found in the GUI Compendium
As of version 1.9.32 the game contains the so called tree planter tool that allows to plant a variety of trees easily by tapping somewhere on the map. This tool was implemented as a plugin and serves as a basic example of how to use Lua for tools and the new GUI features. The concept of the UI and the icon were made by The general structure of the code looks like that (omitted implementations for readability) :
Code: Select all Reset
-- Some local variables used for state local minBrushSize local maxBrushSize local treeDrafts local density local roughness local brushSize local treeSelection -- Cache drawing functions for performance reasons local setTile = Drawing.setTile local drawTileFrame = Drawing.drawTileFrame -- Gets the storage table we use for saving/loading the settings local function getStorage() end -- Save settings to storage local function saveState() end -- Load settings from storage local function loadState() end -- Show about dialog local function about() end -- Show configuration dialog local function configure() end -- True if trees can be placed here in general local function isValid(x, y) end -- Initialize stuff, e.g. load settings function script:init() end -- Setup tool, including the buttons for configuration and about dialog function script:event(x, y, level, event) end -- Draw tile based overlay, red frame for invalid placed function script:draw(tileX, tileY, hoverX, hoverY) end -- Execute action function script:click(tileX, tileY) end
Interactive Lua editor
Code: Select all Reset
[ { "id":"$treeplantertool00_open", "type":"tool", "preview frames":[{"bmp":"icon.png"}], "title id":"draft_treeplantertool00_title", "text id":"draft_treeplantertool00_text", "category":"$cat_tree00", "script":"#LuaWrapper", "meta":{ "luawrapper":{ "script":"script.lua", "dev":true } } } ]
JSON checker
You'll find the git repository here: https://github.com/LobbyDivinus/TreePlanterTool
You can use the option "Download ZIP" to download the whole plugin.
Please feel free to create your own tools based on this one. You can also make changes to this tool and make a pull request of the changes on GitHub.
More detailed documentation about the GUI features in Lua can be found in the GUI Compendium