diff --git a/code/__HELPERS/cmp.dm b/code/__HELPERS/cmp.dm index 31308ac5812f..5b7fc2c03ead 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(A, 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..8a8ec08bed49 100644 --- a/code/modules/autowiki/pages/guns.dm +++ b/code/modules/autowiki/pages/guns.dm @@ -1,8 +1,9 @@ /datum/autowiki/guns + generate_multiple = TRUE page = "Template:Autowiki/Content/GunData" -/datum/autowiki/guns/generate() +/datum/autowiki/guns/generate_multiple() var/output = "" var/list/gun_to_ammo = list() @@ -12,7 +13,14 @@ 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/typepath 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[typepath.name] = typepath + + for(var/typepath in unique_typepaths) 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) @@ -108,7 +116,8 @@ upload_icon(generated_icon, filename) gun_data["icon"] = filename - output += include_template("Autowiki/Gun", gun_data) + var/page_name = replacetext(strip_improper(generating_gun.name), " ", "_") + output += list(title = "Autowiki/Gun/[page_name]", text = include_template("Autowiki/Gun", gun_data)) qdel(generating_gun)