diff --git a/aurorastation.dme b/aurorastation.dme index 08cbf4bff67..484288f4378 100644 --- a/aurorastation.dme +++ b/aurorastation.dme @@ -340,7 +340,6 @@ #include "code\controllers\subsystems\dbcore.dm" #include "code\controllers\subsystems\dcs.dm" #include "code\controllers\subsystems\discord.dm" -#include "code\controllers\subsystems\documents.dm" #include "code\controllers\subsystems\economy.dm" #include "code\controllers\subsystems\effects.dm" #include "code\controllers\subsystems\evac.dm" diff --git a/code/controllers/subsystems/documents.dm b/code/controllers/subsystems/documents.dm deleted file mode 100644 index 18892849291..00000000000 --- a/code/controllers/subsystems/documents.dm +++ /dev/null @@ -1,230 +0,0 @@ -SUBSYSTEM_DEF(docs) - name = "Documents" - wait = 30 SECONDS - flags = SS_NO_FIRE - init_order = INIT_ORDER_MISC_FIRST - - var/total_docs = 0 - var/list/docs = list() - var/list/docs_by_tags = list() - var/list/total_by_tags = list() - -/datum/controller/subsystem/docs/Recover() - src.docs = SSdocs.docs - src.docs_by_tags = SSdocs.docs_by_tags - -/datum/controller/subsystem/docs/Initialize(timeofday) - //Load in the docs config - if(GLOB.config.docs_load_docs_from == "sql") - log_subsystem_documents("Attempting to Load from SQL") - load_from_sql() - else if(GLOB.config.docs_load_docs_from == "json") - log_subsystem_documents("Attempting to Load from JSON") - load_from_json() - else - log_config("SSdocs: invalid load option specified in config") - log_subsystem_documents("invalid load option specified in config") - - return SS_INIT_SUCCESS - -/* - Fetching Data -*/ -//A rewritten version of pickweight. -/datum/controller/subsystem/docs/proc/pick_document() - var/subtotal = rand() * src.total_docs - for (var/doc in docs) - var/datum/docs_document/dd = doc - subtotal -= dd.chance - if (subtotal <= 0) - return dd - return null - -//Pick a document by one tag -/datum/controller/subsystem/docs/proc/pick_document_by_tag(var/tag) - if(!docs_by_tags[tag]) - return null - var/subtotal = rand() * src.total_by_tags[tag] - for (var/doc in docs_by_tags[tag]) - var/datum/docs_document/dd = doc - subtotal -= dd.chance - if (subtotal <= 0) - return dd - return null - -//Pick a document by any tag from a list of tags. Weighted. -/datum/controller/subsystem/docs/proc/pick_document_by_any_tag(var/list/tags) - if(!istype(tags) || !tags.len) - return null - var/total_chance = 0 - var/tag_sublist = list() - for(var/t in tags) - if(!total_by_tags[t]) - return null - total_chance += total_by_tags[t] - tag_sublist += docs_by_tags[t] - var/subtotal = total_chance * rand() - for(var/doc in tag_sublist) - var/datum/docs_document/dd = doc - subtotal -= dd.chance - if(subtotal <= 0) - return dd - return null - -//Pick a document by multiple tags that it must have. -/datum/controller/subsystem/docs/proc/pick_document_by_tags(var/list/tags) - if(!istype(tags) || !tags.len) - return null - var/list/tag_sublist = docs_by_tags[pick(tags)] // the list cannot start off as empty - for(var/t in tags) - if(!docs_by_tags[t]) - return null - tag_sublist &= docs_by_tags[t] - log_subsystem_documents("Tag sublist has length [tag_sublist.len].") - var/subtotal = 0 - for(var/doc in tag_sublist) - var/datum/docs_document/dd = doc - subtotal += dd.chance - subtotal *= rand() - for (var/doc in tag_sublist) - var/datum/docs_document/dd = doc - subtotal -= dd.chance - if (subtotal <= 0) - return tag_sublist[dd] - return null -/* - Loading Data -*/ -//Reset docs to prep for loading in new items -/datum/controller/subsystem/docs/proc/reset_docs() - docs = list() - docs_by_tags = list() - total_docs = 0 - total_by_tags = list() - -//Load the document data from SQL -/datum/controller/subsystem/docs/proc/load_from_sql() - if(!establish_db_connection(GLOB.dbcon)) - log_subsystem_documents("SQL ERROR - Failed to connect. - Falling back to JSON") - return load_from_json() - else - //Reset the currently loaded data - reset_docs() - - //Load the categories - var/DBQuery/document_query = GLOB.dbcon.NewQuery("SELECT name, title, chance, content, tags FROM ss13_documents WHERE deleted_at IS NULL") - document_query.Execute() - while(document_query.NextRow()) - CHECK_TICK - try - add_document( - document_query.item[1], - document_query.item[2], - text2num(document_query.item[3]), - document_query.item[4], - json_decode(document_query.item[5])) - catch(var/exception/ec) - log_subsystem_documents("Error when loading document: [ec]") - return 1 - -//Loads the document data from JSON -/datum/controller/subsystem/docs/proc/load_from_json() - var/list/docsconfig = list() - - if(isfile("config/docs.json")) - docsconfig = json_decode(return_file_text("config/docs.json")) - else - log_subsystem_documents("Warning: Could not load config, as docs.json is missing") - return 0 - - //Reset the currently loaded data - reset_docs() - - //Load the documents - for (var/document in docsconfig) - CHECK_TICK - try - add_document( - docsconfig[document]["name"], - docsconfig[document]["title"], - docsconfig[document]["chance"], - docsconfig[document]["content"], - docsconfig[document]["tags"]) - catch(var/exception/ec) - log_subsystem_documents("Error when loading document: [ec]") - return 1 - -/datum/controller/subsystem/docs/proc/add_document(var/name,var/title,var/chance,var/content,var/tags) - var/datum/docs_document/dd = new() - dd.name = name - dd.title = title - dd.chance = chance - dd.content = content - if(istext(tags)) - tags = splittext(tags, ";") - dd.tags = tags - - //Adds the document to the docs, sorted by tags - for(var/t in tags) - if(!(docs_by_tags[t])) - docs_by_tags[t] = list() - total_by_tags[t] = 0 - docs_by_tags[t][dd.name] += dd - total_by_tags[t] += dd.chance - - //Add the document to the docs list - docs[dd.name] = dd - total_docs += dd.chance - return dd - -/datum/docs_document - var/name = "document" // internal name of the document - var/title = "paper" // player-facing title of the document - var/chance = 0 - var/content = "" // Can contain html, but pencode is not processed. - var/list/tags = list() // A list of tags that apply to the document. - -/obj/random/document - name = "random document" - desc = "This is a random text document." - icon = 'icons/obj/bureaucracy.dmi' - icon_state = "paper" - has_postspawn = 1 - var/tags = list() // for use by mappers, typically - -/obj/random/document/item_to_spawn() - return /obj/item/paper - -/obj/random/document/post_spawn(var/obj/item/paper/spawned) - if(!istype(spawned)) - return - var/list/total_tags = tags | list(SSDOCS_MEDIUM_PAPER) - var/datum/docs_document/doc - if (total_tags.len == 1) - doc = SSdocs.pick_document_by_tag(total_tags[1]) - else - doc = SSdocs.pick_document_by_tags(total_tags) - - if (!istype(doc)) - log_subsystem_documents("Null paper acquired in post_spawn!") - return null - - log_subsystem_documents("Document [doc.name] successfully spawned!") - var/obj/item/paper/P = spawned - P.set_content(doc.title, doc.content) - -/obj/random/document/junk/post_spawn(var/obj/item/spawned) - ..() - if(istype(spawned, /obj/item/paper) && prob(80)) // 1 in 5 junk-spawned documents will be perfectly readable - var/obj/item/paper/P = spawned - P.info = stars(P.info, 85) // 85% readable, preserves tags - P.icon_state = "scrap" - -/datum/controller/subsystem/docs/proc/create_file(var/datum/docs_document/file) - var/datum/computer_file/data/F = new/datum/computer_file/data() - F.filename = file.title - F.filetype = "TXT" - log_subsystem_documents("Digital file created: [file.title].TXT") - F.stored_data = file.content - F.calculate_size() - return F diff --git a/code/modules/modular_computers/hardware/hard_drive.dm b/code/modules/modular_computers/hardware/hard_drive.dm index 214e4364d91..87686e8c370 100644 --- a/code/modules/modular_computers/hardware/hard_drive.dm +++ b/code/modules/modular_computers/hardware/hard_drive.dm @@ -159,17 +159,6 @@ QDEL_LIST(stored_files) return ..() -/obj/item/computer_hardware/hard_drive/Initialize(mapload) - . = ..() - install_default_programs() - if(mapload && prob(5)) - var/datum/docs_document/file = SSdocs.pick_document_by_tag(SSDOCS_MEDIUM_FILE) - if(!istype(file)) - log_subsystem_documents("pick_document_by_tag returned null file!") - else - var/datum/computer_file/data/F = SSdocs.create_file(file) - store_file(F) - /obj/item/computer_hardware/hard_drive/proc/reset_drive() for(var/datum/computer_file/F in stored_files) remove_file(F) diff --git a/html/changelogs/arrow768-dbcore-ssdocs.yml b/html/changelogs/arrow768-dbcore-ssdocs.yml new file mode 100644 index 00000000000..68769fb996b --- /dev/null +++ b/html/changelogs/arrow768-dbcore-ssdocs.yml @@ -0,0 +1,58 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: arrow768 + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - rscdel: "Gets rid of SSdocs as its unused."