Epicycle Posted December 7, 2015 Share Posted December 7, 2015 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 endendBut it feels kind of hacky...Is there any other way to deal with these changes for now? Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/ Share on other sites More sharing options...
Epicycle Posted December 7, 2015 Author Share Posted December 7, 2015 Update: Moved the code from AddSimPostInit to the standard functions of the mod that adds the recipes when the mod is loaded.For some reason i thought it doesn't work there, well it didnt but that was my fault, silly me. Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-694000 Share on other sites More sharing options...
Arkathorn Posted December 7, 2015 Share Posted December 7, 2015 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) endendand just use that to declare your recipes. Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-694095 Share on other sites More sharing options...
Epicycle Posted December 7, 2015 Author Share Posted December 7, 2015 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) endendand 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. Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-694241 Share on other sites More sharing options...
Kzisor Posted December 8, 2015 Share Posted December 8, 2015 @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. Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-694802 Share on other sites More sharing options...
Epicycle Posted December 8, 2015 Author Share Posted December 8, 2015 thats what i meant when i said i really dont want to redeclare them if they dont exist or pass the raw values, but i guess for now i'll have to stick with one or the other Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-694849 Share on other sites More sharing options...
Kzisor Posted December 8, 2015 Share Posted December 8, 2015 (edited) @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 December 9, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-694958 Share on other sites More sharing options...
Maris Posted December 9, 2015 Share Posted December 9, 2015 Omg. game_type should be the last parameter for for backward compatibility. Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-695016 Share on other sites More sharing options...
Arkathorn Posted December 9, 2015 Share Posted December 9, 2015 Omg. game_type should be the last parameter for for backward compatibility.It's Lua, anything is compatible if you try hard enough. Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-695201 Share on other sites More sharing options...
Epicycle Posted December 9, 2015 Author Share Posted December 9, 2015 (edited) 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 listbut there is still hope until its released 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 December 9, 2015 by Epicycle Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-695218 Share on other sites More sharing options...
Epicycle Posted December 9, 2015 Author Share Posted December 9, 2015 It's Lua, anything is compatible if you try hard enough.i think there is a difference between "being compatible" and "can be made compatible" but in general i guess you are right Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-695229 Share on other sites More sharing options...
Maris Posted December 9, 2015 Share Posted December 9, 2015 It's Lua, anything is compatible if you try hard enough.I meant compatibility with mods that won't be updated anymore. Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-695380 Share on other sites More sharing options...
Maris Posted February 28, 2016 Share Posted February 28, 2016 (edited) 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 February 28, 2016 by Maris Link to comment https://forums.kleientertainment.com/forums/topic/60309-recipe-api-changes-in-shipwrecked/#findComment-728117 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now