Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autowiki 2: generates individual pages for guns #6825

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions code/__HELPERS/cmp.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions code/modules/autowiki/autowiki.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions code/modules/autowiki/pages/_page.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 17 additions & 6 deletions code/modules/autowiki/pages/guns.dm
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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)

Expand Down
Loading