Jump to content

Recommended Posts

Hello,

 

i was wondering how one is supposed to handle the api changes made to the recipe constructor in shipwrecked.

 

For now i am overwriting the recipes of my mod via AddSimPostInit(FixRecipes)

local function FixRecipes()	if GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC) then			-- add recipes including GLOBAL.RECIPE_GAME_TYPE.COMMON	endend

But it feels kind of hacky...

Is there any other way to deal with these changes for now?

 

You could make a function that takes the Shipwrecked parameters, and ignores the extra one if you don't have Shipwrecked enabled:

local function FixedRecipes(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance)	if GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC) then		GLOBAL.Recipe(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance)	else		GLOBAL.Recipe(name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive)	endend

and just use that to declare your recipes.

You could make a function that takes the Shipwrecked parameters, and ignores the extra one if you don't have Shipwrecked enabled:

local function FixedRecipes(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance)	if GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC) then		GLOBAL.Recipe(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance)	else		GLOBAL.Recipe(name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive)	endend

and just use that to declare your recipes.

 

Unfortunately that wont work that easy since the constants for game_type are only available if shipwrecked is loaded and i really dont want to redeclare them if they dont exist or pass the raw values,

i was more looking for a predfined way of doing this. Like a build in function that deals with this.

 

Hopefully there will be an api update  when shipwrecked will be released.

@Epicycle, you could simply use a string instead of the variable name.

 

Instead of this:

	RECIPE_GAME_TYPE.SHIPWRECKED = "shipwrecked",        RECIPE_GAME_TYPE.ROG = "rog",	RECIPE_GAME_TYPE.COMMON = "common",	RECIPE_GAME_TYPE.VANILLA = "vanilla",

Just use:

"shipwrecked""rog""common""vanilla"

So using Arkathorn's solution you can simply do this:

local function FixedRecipes(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance)    if GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC) then        GLOBAL.Recipe(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance)    else        GLOBAL.Recipe(name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive)    endendFixedRecipes(name, ingredients, tab, level, "shipwrecked")FixedRecipes(name, ingredients, tab, level, "rog")FixedRecipes(name, ingredients, tab, level, "common")FixedRecipes(name, ingredients, tab, level, "vanilla")

It will work in all versions of the gamebecause GLOBAL.CAPY_DLC is global for the entire game. The only game it won't work on is DST.

@Epicycle, technically you could do it differently.

 

Example from Wayrra mod I coauthor.

local sanityorb_recipe = Recipe("sanityorb", {Ingredient("livinglog", 1), Ingredient("green_cap", 3), Ingredient("pinecone", 1)}, RECIPETABS.MAGIC, TECH.NONE)if IsDLCEnabled(CAPY_DLC) then    sanityorb_recipe.game_type = RECIPE_GAME_TYPE.COMMON    sanityorb_recipe.aquatic = false    sanityorb_recipe.distance = nilendsanityorb_recipe.placer = "sanityorb_placer"sanityorb_recipe.sortkey = -8812221sanityorb_recipe.atlas = resolvefilepath("images/inventoryimages/sanityorb.xml")

The easiest method is simply redefining them if shipwrecked isn't enabled.

Edited by Kzisor

But i agree, it would be much easier if they added game_type at the end and not somewhere in the middle

:-)

for some reason aquatic and distance made it to the end of the parameter list

but there is still hope until its released  :juggling:

i think/hope that parameter game_type will be added to the standard recipe constructor and RECIPE_GAME_TYPE will be available without any dlc

Edited by Epicycle
On 12/8/2015 at 9:39 PM, Kzisor said:

local function FixedRecipes(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance) if GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC) then GLOBAL.Recipe(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance) else GLOBAL.Recipe(name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive) endendFixedRecipes(name, ingredients, tab, level, "shipwrecked")FixedRecipes(name, ingredients, tab, level, "rog")FixedRecipes(name, ingredients, tab, level, "common")FixedRecipes(name, ingredients, tab, level, "vanilla")

Fixed newlines:

_G = GLOBAL

--[[
New function for add recipes.
Examples:
FixedRecipes(name, ingredients, tab, level, "shipwrecked")
FixedRecipes(name, ingredients, tab, level, "rog")
FixedRecipes(name, ingredients, tab, level, "both") --both means it should work everywhere, not only in sw
FixedRecipes(name, ingredients, tab, level, "common")
FixedRecipes(name, ingredients, tab, level, "vanilla")
--]]
local Ingredient, RECIPETABS, TECH = _G.Ingredient, _G.RECIPETABS, _G.TECH
local function AddRecipe(name, ingredients, tab, level, game_type, atlas, placer, min_spacing, nounlock, numtogive, aquatic, distance)
    local recipe, recipe_rog
    if _G.IsDLCEnabled(_G.CAPY_DLC) then
		if game_type == "both" then
			recipe = _G.Recipe(name, ingredients, tab, level, "shipwrecked", placer, min_spacing, nounlock, numtogive, aquatic, distance)
			recipe_rog = _G.Recipe(name, ingredients, tab, level, "rog", placer, min_spacing, nounlock, numtogive, aquatic, distance)
		else
			recipe = _G.Recipe(name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance)
		end
    else
        recipe = _G.Recipe(name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive)
    end
    if atlas then
        recipe.atlas = atlas
    end
    return recipe, recipe_rog
end
 
AddRecipe("my_item",
    { Ingredient("twigs", 2), Ingredient("fish", 8), Ingredient("rope", 2)},
    RECIPETABS.WAR, TECH.SCIENCE_TWO, "both", "images/inventoryimages/my_item.xml"
)

 

Edited by Maris

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...