diff --git a/code/__HELPERS/cmp.dm b/code/__HELPERS/cmp.dm index 31308ac5812f..e27add2c9601 100644 --- a/code/__HELPERS/cmp.dm +++ b/code/__HELPERS/cmp.dm @@ -57,6 +57,9 @@ GLOBAL_LIST_INIT(cmp_field, "name") /proc/cmp_typepaths_asc(A, B) return sorttext("[B]","[A]") +/proc/cmp_typepaths_name_asc(atom/A, atom/B) + return sorttext(initial(A.name), initial(B.name)) + /// Compares mobs based on their timeofdeath value in ascending order /proc/cmp_mob_deathtime_asc(mob/A, mob/B) return A.timeofdeath - B.timeofdeath diff --git a/code/modules/autowiki/autowiki.dm b/code/modules/autowiki/autowiki.dm index 8b38ec76706b..128fbf64d100 100644 --- a/code/modules/autowiki/autowiki.dm +++ b/code/modules/autowiki/autowiki.dm @@ -23,6 +23,26 @@ for (var/datum/autowiki/autowiki_type as anything in subtypesof(/datum/autowiki)) var/datum/autowiki/autowiki = new autowiki_type + + if(autowiki.generate_multiple) + var/output = autowiki.generate_multiple() + + if (!islist(output)) + CRASH("[autowiki_type] does not generate a proper output when generate_multiple is set!") + + for(var/list in output) + total_output += json_encode(list) + + if(!autowiki.page) + continue + + var/list/all_page_names = list() + for(var/list in output) + all_page_names += autowiki.include_template(list["title"]) + + total_output += json_encode(list("title" = autowiki.page, "text" = all_page_names)) + continue + var/output = autowiki.generate() if (!istext(output)) diff --git a/code/modules/autowiki/pages/_page.dm b/code/modules/autowiki/pages/_page.dm index 8e745ace61c2..0e4091d0ccc5 100644 --- a/code/modules/autowiki/pages/_page.dm +++ b/code/modules/autowiki/pages/_page.dm @@ -6,12 +6,20 @@ /// For example: "Template:Autowiki/CircuitInfo". var/page + /// If the generation of this autowiki should call /generate_multiple(), + /// which should return a list of list(title = "Page Title", contents) + /// allowing for the generation of multiple pages in the same autowiki + var/generate_multiple = FALSE + /// Override and return the new text of the page. /// This proc can be impure, usually to call `upload_file`. /datum/autowiki/proc/generate() SHOULD_CALL_PARENT(FALSE) CRASH("[type] does not implement generate()!") +/datum/autowiki/proc/generate_multiple() + SHOULD_CALL_PARENT(FALSE) + /// Generates an auto formatted template user. /// Your autowiki should ideally be a *lot* of these. /// It lets wiki editors edit it much easier later, without having to enter repo. diff --git a/code/modules/autowiki/pages/guns.dm b/code/modules/autowiki/pages/guns.dm index 7f63602d56f0..2de4d5c23598 100644 --- a/code/modules/autowiki/pages/guns.dm +++ b/code/modules/autowiki/pages/guns.dm @@ -1,9 +1,10 @@ /datum/autowiki/guns + generate_multiple = TRUE page = "Template:Autowiki/Content/GunData" -/datum/autowiki/guns/generate() - var/output = "" +/datum/autowiki/guns/generate_multiple() + var/output = list() var/list/gun_to_ammo = list() @@ -12,12 +13,20 @@ continue // Skip mags with no icon_state (e.g. base types) LAZYADD(gun_to_ammo[initial(typepath.gun_type)], typepath) - for(var/typepath in sort_list(subtypesof(/obj/item/weapon/gun), GLOBAL_PROC_REF(cmp_typepaths_asc))) + var/list/unique_typepaths = list() + for(var/obj/item/weapon/gun/typepath as anything in sort_list(subtypesof(/obj/item/weapon/gun), GLOBAL_PROC_REF(cmp_typepaths_name_asc))) + if(initial(typepath.name) in unique_typepaths) + continue + + unique_typepaths[initial(typepath.name)] = typepath + + for(var/name in unique_typepaths) + var/typepath = unique_typepaths[name] + var/obj/item/weapon/gun/generating_gun = typepath if(isnull(initial(generating_gun.icon_state))) continue // Skip guns with no icon_state (e.g. base types) - - generating_gun = new typepath() + generating_gun = new typepath var/filename = SANITIZE_FILENAME(escape_value(format_text(generating_gun.name))) var/list/gun_data = generating_gun.ui_data() @@ -108,7 +117,9 @@ upload_icon(generated_icon, filename) gun_data["icon"] = filename - output += include_template("Autowiki/Gun", gun_data) + var/page_name = SANITIZE_FILENAME(replacetext(strip_improper(generating_gun.name), " ", "_")) + var/to_add = list(title = "Autowiki/Content/Gun/[page_name]", text = include_template("Autowiki/Gun", gun_data)) + output += list(to_add) qdel(generating_gun)