From 3ee17095caacfc295089a541363f441ce2ded08b Mon Sep 17 00:00:00 2001 From: AlbertNanotracen Date: Thu, 13 Jun 2024 20:38:03 -0300 Subject: [PATCH] change to use new datum subsystem thing --- .../code/modules/admin/verbs/spawn_mixtape.dm | 22 ++++++++---------- .../code/modules/cassettes/cassette.dm | 13 ++++------- .../modules/cassettes/cassette_approval.dm | 6 ++--- .../cassettes/cassette_db/cassette_datum.dm | 3 +++ .../cassettes/random_cassette_selection.dm | 23 ++++++++----------- .../tgui/interfaces/MixtapeSpawner.tsx | 6 ++--- 6 files changed, 32 insertions(+), 41 deletions(-) diff --git a/monkestation/code/modules/admin/verbs/spawn_mixtape.dm b/monkestation/code/modules/admin/verbs/spawn_mixtape.dm index d0b1d37e3b40..bffca51317a0 100644 --- a/monkestation/code/modules/admin/verbs/spawn_mixtape.dm +++ b/monkestation/code/modules/admin/verbs/spawn_mixtape.dm @@ -31,21 +31,17 @@ /datum/mixtape_spawner/ui_data(mob/user) var/list/data = list() - if(!length(GLOB.approved_cassettes)) - GLOB.approved_cassettes = initialize_approved_cassettes() - if(!length(GLOB.approved_cassettes)) + if(!length(SScassette_storage.cassette_datums)) return - var/datum/cassette/cassette_tape/first = GLOB.approved_cassettes[1] - data["selected_id"] = first.id - for(var/datum/cassette/cassette_tape/cassette in GLOB.approved_cassettes) + for(var/datum/cassette_data/cassette in SScassette_storage.cassette_datums) data["approved_cassettes"] += list(list( - "name" = cassette.name, - "desc" = cassette.desc, - "icon_state" = cassette.icon_state, - "id" = cassette.id, - "creator_ckey" = cassette.creator_ckey, - "creator_name" = cassette.creator_name, - "song_names" = cassette.song_names + "name" = cassette.cassette_name, + "desc" = cassette.cassette_desc, + "cassette_design_front" = cassette.cassette_design_front, + "creator_ckey" = cassette.cassette_author_ckey, + "creator_name" = cassette.cassette_author, + "song_names" = cassette.song_names, + "id" = cassette.cassette_id )) return data diff --git a/monkestation/code/modules/cassettes/cassette.dm b/monkestation/code/modules/cassettes/cassette.dm index 99599f9f90d7..486c8f6bfa04 100644 --- a/monkestation/code/modules/cassettes/cassette.dm +++ b/monkestation/code/modules/cassettes/cassette.dm @@ -30,17 +30,14 @@ /obj/item/device/cassette_tape/Initialize(mapload, spawned_id) . = ..() - if(!length(GLOB.approved_cassettes)) - GLOB.approved_cassettes = initialize_approved_cassettes() + if(!length(GLOB.approved_ids)) + GLOB.approved_ids = initialize_approved_ids() - if(length(GLOB.approved_cassettes)) - var/list/cassette_ids = list() - for (var/datum/cassette/cassette_tape/tape in GLOB.approved_cassettes) - cassette_ids += tape.id - if(spawned_id && (spawned_id in cassette_ids)) + if(length(GLOB.approved_ids)) + if(spawned_id && (spawned_id in GLOB.approved_ids)) id = spawned_id else if(random) - id = pick(GLOB.approved_cassettes) + id = pick(GLOB.approved_ids) var/file = file("data/cassette_storage/[id].json") if(!fexists(file)) diff --git a/monkestation/code/modules/cassettes/cassette_approval.dm b/monkestation/code/modules/cassettes/cassette_approval.dm index ad848a5e1c5b..ae26e5d44849 100644 --- a/monkestation/code/modules/cassettes/cassette_approval.dm +++ b/monkestation/code/modules/cassettes/cassette_approval.dm @@ -28,8 +28,8 @@ GLOBAL_LIST_INIT(cassette_reviews, list()) /obj/item/device/cassette_tape/proc/generate_cassette_json() if(approved_tape) return - if(!length(GLOB.approved_cassettes)) - GLOB.approved_cassettes = initialize_approved_cassettes() + if(!length(GLOB.approved_ids)) + GLOB.approved_ids = json_decode(file2text("data/cassette_storage/ids.json")) var/list/data = list() data["name"] = name data["desc"] = cassette_desc_string @@ -49,7 +49,7 @@ GLOBAL_LIST_INIT(cassette_reviews, list()) var/list/names = json_decode(file2text(file("data/cassette_storage/ids.json"))) fdel(file("data/cassette_storage/ids.json")) names += json_name - GLOB.approved_cassettes += new /datum/cassette/cassette_tape(json_name) + GLOB.approved_ids += json_name WRITE_FILE(file("data/cassette_storage/ids.json"), json_encode(names)) /datum/cassette_review diff --git a/monkestation/code/modules/cassettes/cassette_db/cassette_datum.dm b/monkestation/code/modules/cassettes/cassette_db/cassette_datum.dm index 09f2ccebe043..07efe51ea95e 100644 --- a/monkestation/code/modules/cassettes/cassette_db/cassette_datum.dm +++ b/monkestation/code/modules/cassettes/cassette_db/cassette_datum.dm @@ -11,6 +11,7 @@ var/list/song_names + var/cassette_id var/approved var/file_name @@ -34,6 +35,8 @@ cassette_author = data["author_name"] cassette_author_ckey = data["author_ckey"] + cassette_id = file_id + approved = data["approved"] file_name = "data/cassette_storage/[file_id].json" diff --git a/monkestation/code/modules/cassettes/random_cassette_selection.dm b/monkestation/code/modules/cassettes/random_cassette_selection.dm index 29fbd8c7e05a..9e70e4657eee 100644 --- a/monkestation/code/modules/cassettes/random_cassette_selection.dm +++ b/monkestation/code/modules/cassettes/random_cassette_selection.dm @@ -1,26 +1,21 @@ -GLOBAL_LIST_INIT(approved_cassettes, initialize_approved_cassettes()) +GLOBAL_LIST_INIT(approved_ids, initialize_approved_ids()) /proc/unique_random_tapes(amt = 1) . = list() - if(!length(GLOB.approved_cassettes)) - GLOB.approved_cassettes = initialize_approved_cassettes() - if(!length(GLOB.approved_cassettes)) + if(!length(GLOB.approved_ids)) + GLOB.approved_ids = initialize_approved_ids() + if(!length(GLOB.approved_ids)) return - var/list/cassettes_to_choose = GLOB.approved_cassettes.Copy() - amt = min(amt, length(cassettes_to_choose)) + var/list/ids_to_choose = GLOB.approved_ids.Copy() + amt = min(amt, length(ids_to_choose)) for(var/i in 1 to amt) - var/datum/cassette/cassette_tape/cassette = pick_n_take(cassettes_to_choose) - . += cassette.id + . += pick_n_take(ids_to_choose) -/proc/initialize_approved_cassettes() +/proc/initialize_approved_ids() var/ids_exist = file("data/cassette_storage/ids.json") if(!fexists(ids_exist)) return list() - var/approved_ids = json_decode(file2text(ids_exist)) - var/list/cassettes = list() - for (var/id in approved_ids) - cassettes += new /datum/cassette/cassette_tape(id) - return cassettes + return json_decode(file2text(ids_exist)) /obj/item/device/cassette_tape/random diff --git a/tgui/packages/tgui/interfaces/MixtapeSpawner.tsx b/tgui/packages/tgui/interfaces/MixtapeSpawner.tsx index efaa4305f3fd..415b5c58757d 100644 --- a/tgui/packages/tgui/interfaces/MixtapeSpawner.tsx +++ b/tgui/packages/tgui/interfaces/MixtapeSpawner.tsx @@ -9,11 +9,11 @@ type Data = { type Cassette = { name: string; desc: string; - icon_state: string; - id: string; + cassette_design_front: string; creator_ckey: string; creator_name: string; song_names: SongNames; + id: string; }; type SongNames = { @@ -44,7 +44,7 @@ export const MixtapeSpawner = (props, context) => { color="transparent" selected={cassette.id === selected_cassette.id} onClick={() => setSelectedCassette(cassette)}> - {cassette.id} + {cassette.name} ))}