Skip to content

Commit

Permalink
change to use new datum subsystem thing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertNanotracen committed Jun 13, 2024
1 parent 54cfc70 commit 3ee1709
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 41 deletions.
22 changes: 9 additions & 13 deletions monkestation/code/modules/admin/verbs/spawn_mixtape.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 5 additions & 8 deletions monkestation/code/modules/cassettes/cassette.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions monkestation/code/modules/cassettes/cassette_approval.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

var/list/song_names

var/cassette_id
var/approved
var/file_name

Expand All @@ -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"
Expand Down
23 changes: 9 additions & 14 deletions monkestation/code/modules/cassettes/random_cassette_selection.dm
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions tgui/packages/tgui/interfaces/MixtapeSpawner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -44,7 +44,7 @@ export const MixtapeSpawner = (props, context) => {
color="transparent"
selected={cassette.id === selected_cassette.id}
onClick={() => setSelectedCassette(cassette)}>
{cassette.id}
{cassette.name}
</Tabs.Tab>
))}
</Tabs>
Expand Down

0 comments on commit 3ee1709

Please sign in to comment.