An API for mod development, written in Lua, for the Klei Entertainment's game, Don't Starve.
The API can be imported in 2 ways:
-
-
Download the API file.
-
Put the downloaded file in your mod files.
-
Import it with the
modimport
function.
modimport("path/to/inv_images_API.lua")
-
-
-
- Add the mod as a dependency on your mod's workshop page.
- Import the API with the
modimport
function.
modimport("../workshop-2840451757/inv_images_API.lua")
Handling possible errors: (recommended)
local _G = GLOBAL local API_path = "../workshop-2840451757/inv_images_API.lua" local API_file_exist = _G.softresolvefilepath(MODROOT..API_path) if API_file_exist then modimport(API_path) AddInventoryItemAtlas("path/to/atlas.xml", Assets) else --> Show a simple warning popup. local PopupDialogScreen = _G.require "screens/popupdialog" local API_mod_url = "steam://openurl/https://steamcommunity.com".. "/sharedfiles/filedetails/?id=2840451757" local API_warning_showed = false AddGlobalClassPostConstruct("screens/mainscreen", "MainScreen", function(self) local _OnBecomeActive = self.OnBecomeActive function self:OnBecomeActive() _OnBecomeActive(self) if not API_warning_showed then API_warning_showed = true local popup = PopupDialogScreen( _G.KnownModIndex:GetModFancyName(modname).." Warning", "The mod needs the \"[API] Inventory Images\" mod downloaded!", { {text="Ok", cb = function() _G.TheFrontEnd:PopScreen() end}, {text="Download It", cb = function() _G.VisitURL(API_mod_url) end} } ) popup.title:SetPosition(0, 60, 0) popup.text:SetPosition(0, -50, 0) _G.TheFrontEnd:PushScreen(popup) end end end) end
Obs:
This method is good for keeping the API up to date.
-
Simply call this function in modmain.lua
:
AddInventoryItemAtlas(atlas_path, assets_table)
-
Adds a global inventory items atlas, compatible with mini signs, crafts, ingredients and shelves.
It can be called indefinitely.-
atlas_path
(string) - The xml file path.assets_table
(table) - The "Assets" table, to load the atlas assets. Not required.
-
-
Example: AddInventoryItemAtlas("inventoryimages.xml", Assets)
- These are just examples! Your mod doesn't need to be organized this way.
-
It also demonstrates the use of the
AddInventoryItemAtlas
load assets feature.📁 mod_folder/ 📁 images/ 📄 itemicons.xml 🌆 itemicons.tex 📁 scripts/ 📄 inv_images_API.lua 📄 modmain.lua >> modimport("scripts/inv_images_API.lua") >> Assets = {...} >> AddInventoryItemAtlas("images/itemicons.xml", Assets)
-
-
It also demonstrates the
NOT
use ofAddInventoryItemAtlas
load assets feature. Notice theATLAS_BUILD
asset.📁 mod_folder/ 📁 images/ 📄 myinventoryimages.xml 🌆 myinventoryimages.tex 📄 modmain.lua >> Assets = { Asset("ATLAS", "images/myinventoryimages.xml"), Asset("IMAGE", "images/myinventoryimages.tex"), Asset("ATLAS_BUILD", "images/myinventoryimages.xml", 256), } >> modimport("../workshop-2840451757/inv_images_API.lua") >> AddInventoryItemAtlas("images/myinventoryimages.xml")
-
-
It is
NOT
necessary to set an inventoryitem.atlasname in each prefab. -
Ideally, all your images should be in a single or few atlas, otherwise there may be a delay in loading the mod.
Use some tool like Ztools to do this. -
In order for icons to appear on mini signs and shelves, the dimension of textures (the images) must be a power of 2 (usually 64x64).
This project is under MIT license. See the LICENSE file for more details.