Skip to content

Commit

Permalink
autowiki 2
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Jul 21, 2024
1 parent ee0b038 commit c2d2f41
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
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(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
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
15 changes: 12 additions & 3 deletions code/modules/autowiki/pages/guns.dm
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c2d2f41

Please sign in to comment.