mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2026-08-17 14:46:54 +01:00
tl;dr level collections that can easily be logically restructured/moved as necessary will eventually be used for radio and overmaps location resolution. this is the last part of https://github.com/Citadel-Station-13/Citadel-Station-13-RP/pull/4841 that has not yet been integrated. this will be a draft for a while. --------- Co-authored-by: LetterN <24603524+LetterN@users.noreply.github.com>
70 lines
2.0 KiB
Plaintext
70 lines
2.0 KiB
Plaintext
//* 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()
|
|
return GLOB.always_state
|
|
|
|
/datum/guidebook/on_ui_close(mob/user, datum/tgui/ui, embedded)
|
|
opened -= user
|
|
return ..()
|
|
|
|
/datum/guidebook/on_ui_transfer(mob/old_mob, mob/new_mob, datum/tgui/ui, embedded)
|
|
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 = RSguidebook.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), nested_data = built)
|
|
else
|
|
push_ui_data(user, data = list("sections" = lookup), nested_data = built)
|
|
|
|
/client/verb/access_guidebook()
|
|
set name = "Access Guidebook"
|
|
set category = VERB_CATEGORY_OOC
|
|
|
|
GLOB.guidebook.ui_interact(src)
|