Mod Development of Don't Starve Together - Production Bar (9)

Mod Development of Don't Starve Together - Production Bar (9)

foreword

The API of the inventory is written in modmain.lua , basically one line of code. But before using it, add the following line of code to realize one-click GLOBAL, and directly use XXX to access GLOBAL.XXX.

GLOBAL.setmetatable(env,{
    
    __index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end})

Add items to crafting

--写法参考:recipes.lua,直接把Recipe2(...)的那堆参数copy过来用就行,参数是对应的

--添加配方,默认添加在MODS过滤器中
--name: 预设物名,自定义预设物需要配置config中的atlas

--ingredients:{Ingredient(...),Ingredient(...)} Ingredient定义在在recipe.lua
--Ingredient(prefab, amount, atlas=nil, deconstruct=false, imageoverride=nil)
--当材料是自定义prefab时,指定atlas为材料物品栏贴图即可, "images/inventoryimages/yyy.xml" 

--tech:TECH.NONE TECH.SCIENCE_ONE TECH.SCIENCE_TWO,看constants.lua中的TECH表
--[[ 
config={
	builder_tag = {"wilson"},	--建筑者需要的tag,一般用于专属配方
	atlas = "images/inventoryimages/xxx.xml", 	--自定义预设物需要指定贴图
	image = "xxx.tex",	--不填就默认是参数 name..".tex"
	--其他参数如:build_distance,min_spacing,nounlock等建筑解锁相关的
}  
--看recipe.lua中Recipe2的config参数]]
--filters = {"TOOLS", "LIGHT"},recipes_filter.lua中CRAFTING_FILTER_DEFS的name
AddRecipe2(name, ingredients, tech, config=nil, filters=nil)

--添加角色专属配方
--在建筑者标签是必须的,记得在你人物的预设物中添加这个标签
--config={builder_tag = ""}
--extra_filters:除角色过滤器外的过滤器名,如{"TOOLS", "LIGHT"}
AddCharacterRecipe(name, ingredients, tech, config, extra_filters=nil)

Example: Adding custom presets to the mods filter

--modmain.lua
GLOBAL.setmetatable(env,{
    
    __index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end})	

PrefabFiles = {
    
    
	"xxx",
}
--[[
xxx.lua 预设物中记得加载贴图
local assets = {
	Asset( "IMAGE", "images/inventoryimages/xxx.tex" ),	
	Asset( "ATLAS", "images/inventoryimages/xxx.xml" ),
}
--]]
AddRecipe2("xxx", {
    
    Ingredient("cutgrass", 2), Ingredient("ice", 1)},
 TECH.NONE, {
    
    atlas = "images/inventoryimages/xxx.xml"})

Added Breakdown Recipe

--recipes.lua,直接把DeconstructRecipe(...)的那堆参数copy过来用就行,参数是对应的
--name和ingredients参数同上
AddDeconstructRecipe(name, ingredients)

Custom Made Bar Filters

--[[
filter_def = {	--参考recipes_filter.lua中的CRAFTING_FILTER_DEFS的写法
	name = "MYFILTER",	--独一无二的过滤器名
	atlas = "images/myfilter.xml",	--原始贴图54x54像素,64x64的也会默认缩放成54x54
	image = "myfilter.tex",
	--下面是可选参数
	--image_size = 80,  --表示缩放到80x80像素	
	--custom_pos = true,  --表示不添加在下面的网格中,如FAVORITES(收藏夹)
}
--]]
--index:插入表的位置,默认是插在最后面
同时要在modmain.lua中设置鼠标悬浮时的文字
STRINGS.UI.CRAFTING_FILTERS[filter_def.name] = "Hover Text"

AddRecipeFilter(filter_def, index=#CRAFTING_FILTER_DEFS+1)

--从过滤器中添加/删除配方
--recipe_name:Recipe2及AddRecipe2中的name
--filter_name:filter_def中的name,及recipes_filter.lua中CRAFTING_FILTER_DEFS的name
AddRecipeToFilter(recipe_name, filter_name)
RemoveRecipeFromFilter(recipe_name, filter_name)

example:

--modmain.lua
GLOBAL.setmetatable(env,{
    
    __index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end})		

--加载必须的贴图资源
Assets = {
    
    
    Asset( "IMAGE", "images/myfilter.tex" ),	--64x64像素即可
	Asset( "ATLAS", "images/myfilter.xml" ),
}

--添加悬浮文字
STRINGS.UI.CRAFTING_FILTERS["myfilter"] = "Hover Text"
--自定义过滤器
AddRecipeFilter({
    
    
	name = "MYFILTER",	--独一无二的过滤器名
	atlas = "images/myfilter.xml",	--原始贴图54x54像素,64x64的也会默认缩放成54x54
	image = "myfilter.tex",
	--下面是可选参数
	--image_size = 80,  --表示缩放到80x80像素	
	--custom_pos = true,  --表示不添加在下面的网格中,如FAVORITES(收藏夹)
})
--添加配方到过滤器
AddRecipeToFilter("tophat", "MYFILTER")
AddRecipe2("waterballoon",{
    
    Ingredient("cutgrass", 2), Ingredient("ice", 1)},  
TECH.NONE, nil, {
    
    "MYFILTER"})

insert image description here

Initialize after recipe

--fn参数:self,对应recipe中的Recipe类的对象
AddRecipePostInitAny(fn)
AddRecipePostInit(recipe_name, fn)

Portal

→Mod development of the Famine Online version - two kinds of hats (10)
←Mod development of the Famine Online version - common inst methods (8)

Guess you like

Origin blog.csdn.net/weixin_46068322/article/details/127021044