From 4f47ce2d77469d744f2ccce47576c8e2cdeef2f0 Mon Sep 17 00:00:00 2001 From: Arokha Sieyes Date: Fri, 10 Mar 2017 18:25:10 -0500 Subject: [PATCH] "Recipe Dump" admin verb The idea of updating the wiki list of recipes is daunting, especially getting all the icons and resizing them to look nice on a webpage, so fuuuuuuuuck that. I made a verb that does it. It dumps upsized (64x64) images of every food icon and a recipes.html file into your cache with a table that contains all the recipes, nicely formatted, in alphabetical order (the -burger and -kebab at the top are because those are [whatever-meat]-burger and [whatever-meat]-kebab). Then you can just throw them on a website. It will include a recipes.css file if it's in the same dir. Here's the result on our server: https://vore-station.net/infodump/recipes.html --- code/modules/admin/admin_verbs.dm | 3 +- code/modules/food/recipe_dump.dm | 129 ++++++++++++++++++++++++++++++ polaris.dme | 1 + 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 code/modules/food/recipe_dump.dm diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 91a504f421..8dbfae61ec 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -161,7 +161,8 @@ var/list/admin_verbs_server = list( /client/proc/toggle_random_events, /client/proc/check_customitem_activity, /client/proc/nanomapgen_DumpImage, - /client/proc/modify_server_news + /client/proc/modify_server_news, + /client/proc/recipe_dump ) var/list/admin_verbs_debug = list( /client/proc/getruntimelog, //allows us to access runtime logs to somebody, diff --git a/code/modules/food/recipe_dump.dm b/code/modules/food/recipe_dump.dm new file mode 100644 index 0000000000..f33be27258 --- /dev/null +++ b/code/modules/food/recipe_dump.dm @@ -0,0 +1,129 @@ +/client/proc/recipe_dump() + set name = "Generate Recipe Dump" + set category = "Server" + set desc = "Dumps food recipe info and images for wiki or other use." + + if(!holder) + return + + var/list/recipe_paths = typesof(/datum/recipe) - /datum/recipe + //Build a useful list + for(var/Rp in recipe_paths) + //Lists don't work with datum-stealing no-instance initial() so we have to. + var/datum/recipe/R = new Rp() + var/obj/res = new R.result() + + var/icon/result_icon = icon(res.icon,res.icon_state) + result_icon.Scale(64,64) + + recipe_paths[Rp] = list( + "Result" = "[res.name]", + "Reagents" = R.reagents, + "Fruit" = R.fruit, + "Ingredients" = R.items, + "Image" = result_icon + ) + + qdel(res) + qdel(R) + + //Items needs further processing into human-readability. Another use of initial. + var/working_ing_list = list() + for(var/I in recipe_paths[Rp]["Ingredients"]) + var/atom/ing = new I() + + //So now we add something like "Bread" = 3 + if(ing.name in working_ing_list) + working_ing_list[ing.name] = working_ing_list[ing.name]++ + else + working_ing_list[ing.name] = 1 + + recipe_paths[Rp]["Ingredients"] = working_ing_list + + //Reagents can be resolved to nicer names as well + for(var/rid in recipe_paths[Rp]["Reagents"]) + var/datum/reagent/Rd = chemical_reagents_list[rid] + var/R_name = Rd.name + recipe_paths[Rp]["Reagents"][R_name] += recipe_paths[Rp]["Reagents"][rid] + recipe_paths[Rp]["Reagents"] -= rid + + //Sort list by transforming into resultname+unique = path, then back in the right order + //Can't just be sorted by resultname since they are not unique and lists indexed by that will + //end up overwriting the several ways to make something with a single one + var/list/names_to_paths = list() + for(var/Rp in recipe_paths) + names_to_paths["[recipe_paths[Rp]["Result"]] [Rp]"] = Rp //Append recipe datum path to keep uniqueness + + names_to_paths = sortAssoc(names_to_paths) + + var/list/newly_sorted = list() + for(var/Rr in names_to_paths) + var/Rp = names_to_paths[Rr] + newly_sorted[Rp] = recipe_paths[Rp] + + recipe_paths = newly_sorted + + //Produce Output + var/html = "\ + \ + \ + \ + \ + Food Recipes\ + \ + " + + html += "

Recipes (as of [time2text(world.realtime,"MMM DD, YYYY")])


" + html += "" + html += "" + for(var/Rp in recipe_paths) + //Open this row + html += "" + + //Image + var/image_path = "recipe-[ckey(recipe_paths[Rp]["Result"])].png" + var/icon/icon_to_give = recipe_paths[Rp]["Image"] + html += "" + src << browse(icon_to_give, "window=picture;file=[image_path];display=0") + + //Name + html += "" + + //Ingredients + html += "" + //Close this row + html += "" + + html += "
IconNameIngredients
[recipe_paths[Rp]["Result"]]
    " + var/count //For those commas. Not sure of a great other way to do it. + //For each large ingredient + var/pretty_ing = "" + count = 0 + for(var/ing in recipe_paths[Rp]["Ingredients"]) + pretty_ing += "[count == 0 ? "" : ", "][recipe_paths[Rp]["Ingredients"][ing]]x [ing]" + count++ + if(pretty_ing != "") + html += "
  • Ingredients: [pretty_ing]
  • " + + //For each fruit + var/pretty_fru = "" + count = 0 + for(var/fru in recipe_paths[Rp]["Fruit"]) + pretty_fru += "[count == 0 ? "" : ", "][recipe_paths[Rp]["Fruit"][fru]]x [fru]" + count++ + if(pretty_fru != "") + html += "
  • Fruit: [pretty_fru]
  • " + + //For each reagent + var/pretty_rea = "" + count = 0 + for(var/rea in recipe_paths[Rp]["Reagents"]) + pretty_rea += "[count == 0 ? "" : ", "][recipe_paths[Rp]["Reagents"][rea]]u [rea]" + count++ + if(pretty_rea != "") + html += "
  • Mix in: [pretty_rea]
  • " + + //Close ingredients + html += "
" + src << browse(html, "window=recipes;file=recipes.html;display=0") + src << "In your byond cache, recipe-xxx.png files and recipes.html now exist. Place recipe-xxx.png files in a subfolder named 'imgrecipes' wherever you put them. The file will take a recipes.css file if in the same path." diff --git a/polaris.dme b/polaris.dme index ad53ed1052..28965d99ac 100644 --- a/polaris.dme +++ b/polaris.dme @@ -1351,6 +1351,7 @@ #include "code\modules\flufftext\Dreaming.dm" #include "code\modules\flufftext\Hallucination.dm" #include "code\modules\flufftext\TextFilters.dm" +#include "code\modules\food\recipe_dump.dm" #include "code\modules\food\recipes_microwave.dm" #include "code\modules\gamemaster\controller.dm" #include "code\modules\gamemaster\defines.dm"