tgui reagent guidebook & tgui updates (#6161)

Co-authored-by: silicons <no@you.cat>
This commit is contained in:
silicons
2023-12-06 21:35:54 +01:00
committed by GitHub
co-authored by silicons
parent 344e6a0f42
commit db95e39df3
119 changed files with 5534 additions and 2321 deletions
+70
View File
@@ -0,0 +1,70 @@
//* This file is explicitly licensed under the MIT license. *//
//* Copyright (c) 2023 Citadel Station developers. *//
GLOBAL_DATUM_INIT(guidebook, /datum/guidebook, new)
/**
* A standalone version of the guidebook system.
*
* Open when you want a detached reference, like for chemical dispensers to hook into.
*/
/datum/guidebook
/// open instances mapped to list of ids
var/list/opened = list()
/datum/guidebook/ui_state(mob/user, datum/tgui_module/module)
return GLOB.always_state
/datum/guidebook/ui_close(mob/user, datum/tgui_module/module)
opened -= user
return ..()
/datum/guidebook/on_ui_transfer(mob/old_mob, mob/new_mob, datum/tgui/ui)
opened[new_mob] = opened[old_mob]
opened -= old_mob
return ..()
/**
* @params
* * user - person viewing
* * sections - list of section instances, ids, or paths
*/
/datum/guidebook/proc/open(mob/user, list/datum/prototype/guidebook_section/sections)
// build
var/list/built = list()
var/list/hash = list()
var/list/fetched = list()
var/list/lookup = list()
// preprocess sections & inject
for(var/datum/prototype/guidebook_section/section as anything in sections)
if(!istype(section))
section = RCguidebook.fetch(section)
if(!istype(section))
CRASH("invalid section, aborting")
fetched += section
hash += section.id
// hash
hash = jointext(hash, "-")
// check if we need to re-open
if(opened[user] == hash)
return
opened[user] = hash
// inject
for(var/datum/prototype/guidebook_section/section as anything in fetched)
built[section.id] = section.interface_data()
lookup[section.id] = section.title
// open
var/datum/tgui/ui = SStgui.try_update_ui(user, src)
if(isnull(ui))
ui = new(user, src, "TGUIGuidebook")
ui.set_autoupdate(FALSE)
ui.open(data = list("sections" = lookup), modules = built)
else
push_ui_modules(user, updates = built)
push_ui_data(user, data = list("sections" = lookup))
/client/verb/access_guidebook()
set name = "Access Guidebook"
set category = "OOC"
GLOB.guidebook.ui_interact(src)
@@ -0,0 +1,27 @@
//* This file is explicitly licensed under the MIT license. *//
//* Copyright (c) 2023 Citadel Station developers. *//
/datum/prototype/guidebook_section
abstract_type = /datum/prototype/guidebook_section
/// section title
var/title = "Unknown"
/// tgui guidebook module to load
var/tgui_module
/**
* data to be sent to module - static
*
* this is the only one, for now
*
* todo: add dynamic data support???
*/
/datum/prototype/guidebook_section/proc/section_data()
. = list()
/datum/prototype/guidebook_section/proc/interface_data()
return list(
"$tgui" = tgui_module,
"$src" = REF(src),
"title" = title,
) | section_data()
@@ -0,0 +1,19 @@
//* This file is explicitly licensed under the MIT license. *//
//* Copyright (c) 2023 Citadel Station developers. *//
/datum/prototype/guidebook_section/reagents
title = "Reagents"
id = "reagents"
tgui_module = "TGUIGuidebookReagents"
/datum/prototype/guidebook_section/reagents/section_data()
. = ..()
var/list/reagents = list()
var/list/reactions = list()
for(var/id in SSchemistry.reagent_lookup)
var/datum/reagent/reagent = SSchemistry.reagent_lookup[id]
reagents[id] = reagent.tgui_guidebook_data()
for(var/datum/chemical_reaction/reaction as anything in SSchemistry.chemical_reactions)
reactions[reaction.id || "[reaction.name]" || "[reaction.type]"] = reaction.tgui_guidebook_data()
.["reagents"] = reagents
.["reactions"] = reactions