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
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