Skip to content

Commit

Permalink
Refactors cassettes and the cassette player
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Dec 16, 2024
1 parent e3f8b3e commit 32b17c8
Show file tree
Hide file tree
Showing 30 changed files with 857 additions and 508 deletions.
17 changes: 17 additions & 0 deletions SQL/tgstation_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,23 @@ CREATE TABLE `subsystem_metrics` (
PRIMARY KEY (`id`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Table structure for table `cassettes`
--
DROP TABLE IF EXISTS `cassettes`;
CREATE TABLE `cassettes` (
`id` VARCHAR(255) NOT NULL PRIMARY KEY,
`name` VARCHAR(42) NOT NULL,
`desc` VARCHAR(144) NOT NULL,
`status` TINYINT UNSIGNED NOT NULL,
`author_name` VARCHAR(42) NOT NULL,
`author_ckey` VARCHAR(30) NOT NULL,
`front` TEXT NOT NULL DEFAULT '{}',
`back` TEXT NOT NULL DEFAULT '{}',
CONSTRAINT `front` CHECK (json_valid(`front`)),
CONSTRAINT `back` CHECK (json_valid(`back`))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
Expand Down
2 changes: 1 addition & 1 deletion _maps/map_files/BoxStation/BoxStation.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -21346,7 +21346,7 @@
pixel_y = -32
},
/obj/structure/table/wood,
/obj/item/device/cassette_tape/friday{
/obj/item/cassette_tape/friday{
pixel_y = 2;
pixel_x = 9
},
Expand Down
6 changes: 3 additions & 3 deletions _maps/map_files/MetaStation/MetaStation.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -51163,15 +51163,15 @@
pixel_y = 4;
pixel_x = -6
},
/obj/item/device/cassette_tape/blank{
/obj/item/cassette_tape/blank{
pixel_y = 3;
pixel_x = 5
},
/obj/item/device/cassette_tape/blank{
/obj/item/cassette_tape/blank{
pixel_y = 3;
pixel_x = 5
},
/obj/item/device/cassette_tape/blank{
/obj/item/cassette_tape/blank{
pixel_y = 3;
pixel_x = 5
},
Expand Down
2 changes: 1 addition & 1 deletion _maps/map_files/Voidraptor/VoidRaptor.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -10015,7 +10015,7 @@
/obj/item/radio/radio_mic{
pixel_y = 7
},
/obj/item/device/cassette_tape/friday{
/obj/item/cassette_tape/friday{
pixel_y = -6;
pixel_x = -8
},
Expand Down
1 change: 1 addition & 0 deletions code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
#define INIT_ORDER_OUTPUTS 35
#define INIT_ORDER_RESTAURANT 34
#define INIT_ORDER_POLLUTION 32
#define INIT_ORDER_CASSETTES 31 // monkestation addition: cassettes initialize before atoms, so that cassette stuff can be used in Initialize()
#define INIT_ORDER_ATOMS 30
#define INIT_ORDER_ARMAMENTS 27
#define INIT_ORDER_LANGUAGE 25
Expand Down
13 changes: 13 additions & 0 deletions code/__DEFINES/~monkestation/cassettes.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Path to the base directory for cassette stuff
#define CASSETTE_BASE_DIR "data/cassette_storage/"
/// Path to the file containing a list of cassette IDs.
#define CASSETTE_ID_FILE (CASSETTE_BASE_DIR + "ids.json")
/// Path to the data for the cassette of the given ID.
#define CASSETTE_FILE(id) (CASSETTE_BASE_DIR + "[id].json")

/// This cassette is unapproved, and has not been submitted for review.
#define CASSETTE_STATUS_UNAPPROVED 0
/// This cassette is under review.
#define CASSETTE_STATUS_REVIEWING 1
/// This cassette has been approved.
#define CASSETTE_STATUS_APPROVED 2
6 changes: 6 additions & 0 deletions code/__HELPERS/~monkestation-helpers/text.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// Checks to see if a string starts with http:// or https://
/proc/is_http_protocol(text)
var/static/regex/http_regex
if(isnull(http_regex))
http_regex = new("^https?://")
return findtext(text, http_regex)
3 changes: 0 additions & 3 deletions code/_globalvars/_regexes.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//These are a bunch of regex datums for use /((any|every|no|some|head|foot)where(wolf)?\sand\s)+(\.[\.\s]+\s?where\?)?/i
GLOBAL_DATUM_INIT(is_http_protocol, /regex, regex("^https?://"))
GLOBAL_DATUM_INIT(is_http_protocol_non_secure, /regex, regex("^http?://"))


GLOBAL_DATUM_INIT(is_website, /regex, regex("http|www.|\[a-z0-9_-]+.(com|org|net|mil|edu)+", "i"))
GLOBAL_DATUM_INIT(is_email, /regex, regex("\[a-z0-9_-]+@\[a-z0-9_-]+.\[a-z0-9_-]+", "i"))
Expand Down
2 changes: 2 additions & 0 deletions code/controllers/configuration/entries/monkestation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@
. = ..()
if(.)
config_entry_value *= 600 // documented as minutes

/datum/config_entry/flag/cassettes_in_db
4 changes: 2 additions & 2 deletions code/modules/admin/verbs/playsound.dm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
message_admins("[key_name(user)] stopped web sounds.")
web_sound_url = null
stop_web_sounds = TRUE
if(web_sound_url && !findtext(web_sound_url, GLOB.is_http_protocol))
if(web_sound_url && !is_http_protocol(web_sound_url))
tgui_alert(user, "The media provider returned a content URL that isn't using the HTTP or HTTPS protocol. This is a security risk and the sound will not be played.", "Security Risk", list("OK"))
to_chat(user, span_boldwarning("BLOCKED: Content URL not using HTTP(S) Protocol!"), confidential = TRUE)

Expand Down Expand Up @@ -183,7 +183,7 @@

if(length(web_sound_input))
web_sound_input = trim(web_sound_input)
if(findtext(web_sound_input, ":") && !findtext(web_sound_input, GLOB.is_http_protocol))
if(findtext(web_sound_input, ":") && !is_http_protocol(web_sound_input))
to_chat(src, span_boldwarning("Non-http(s) URIs are not allowed."), confidential = TRUE)
to_chat(src, span_warning("For youtube-dl shortcuts like ytsearch: please use the appropriate full URL from the website."), confidential = TRUE)
return
Expand Down
2 changes: 1 addition & 1 deletion code/modules/requests/request_manager.dm
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ GLOBAL_DATUM_INIT(requests, /datum/request_manager, new)
if(request.req_type != REQUEST_INTERNET_SOUND)
to_chat(usr, "Request doesn't have a sound to play.", confidential = TRUE)
return TRUE
if(findtext(request.message, ":") && !findtext(request.message, GLOB.is_http_protocol))
if(findtext(request.message, ":") && !is_http_protocol(request.message))
to_chat(usr, "Request is not a valid URL.", confidential = TRUE)
return TRUE

Expand Down
4 changes: 2 additions & 2 deletions code/modules/unit_tests/unit_test.dm
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ GLOBAL_VAR_INIT(focused_tests, focused_tests())
///we generate mobs in these and create destroy does this in null space
ignore += typesof(/obj/item/loot_table_maker)
///we need to use json_decode to run randoms properly
ignore += typesof(/obj/item/device/cassette_tape)
ignore += typesof(/datum/cassette/cassette_tape)
ignore += typesof(/obj/item/cassette_tape)
ignore += typesof(/datum/cassette)
///we also dont want weathers or weather events as they will hold refs to alot of stuff as they shouldn't be deleted
ignore += typesof(/datum/weather_event)
ignore += typesof(/datum/particle_weather)
Expand Down
2 changes: 2 additions & 0 deletions config/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,5 @@ CONFIG_ERRORS_RUNTIME
## The age in days if minimum account age is on
#MINIMUM_AGE

## If enabled, cassette tapes will be stored in the database, rather than JSON files on-disk.
#CASSETTES_IN_DB
2 changes: 1 addition & 1 deletion monkestation/code/modules/admin/verbs/spawn_mixtape.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
switch(action)
if("spawn")
if (params["id"])
new/obj/item/device/cassette_tape(usr.loc, params["id"])
new/obj/item/cassette_tape(usr.loc, params["id"])
SSblackbox.record_feedback("tally", "admin_verb", 1, "Spawn Mixtape")
log_admin("[key_name(usr)] created mixtape [params["id"]] at [usr.loc].")
4 changes: 2 additions & 2 deletions monkestation/code/modules/cargo/crates/goodies.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
name = "Cassette Mini-Pack"
desc = "Alright, we'll admit it, 10 cassettes are too much for the majority of our users. Contains 3 Approved Cassettes."
cost = PAYCHECK_CREW * 5
contains = list(/obj/item/device/cassette_tape/random = 3)
contains = list(/obj/item/cassette_tape/random = 3)

/datum/supply_pack/goody/blankcassette
name = "Blank Cassette Mini-Pack"
desc = "NO! We wont admit defeat! You will march yourself down to the Service section and purchase the 10 Blank Cassette pack instead of this Weak 3 Blank Cassette Pack!"
cost = PAYCHECK_CREW * 3
contains = list(/obj/item/device/cassette_tape/blank = 3)
contains = list(/obj/item/cassette_tape/blank = 3)
4 changes: 2 additions & 2 deletions monkestation/code/modules/cargo/crates/service.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@

/datum/supply_pack/service/cassettes/fill(obj/structure/closet/crate/our_crate)
for(var/id in unique_random_tapes(10))
new /obj/item/device/cassette_tape(our_crate, id)
new /obj/item/cassette_tape(our_crate, id)

/datum/supply_pack/service/blankcassettes
name = "Blank Cassettes Crate"
desc = "in the VERY unlikely event you have run out of blank cassettes, you can get 10 blank ones here. Contains 10 blank cassettes for use in Walkmans."
cost = CARGO_CRATE_VALUE * 2
contains = list(/obj/item/device/cassette_tape/blank = 10)
contains = list(/obj/item/cassette_tape/blank = 10)
crate_name = "cassette crate"

/datum/supply_pack/service/walkmen
Expand Down
30 changes: 7 additions & 23 deletions monkestation/code/modules/cassettes/cassette.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/obj/item/device/cassette_tape
/obj/item/cassette_tape
name = "Debug Cassette Tape"
desc = "You shouldn't be seeing this!"
icon = 'monkestation/code/modules/cassettes/icons/walkman.dmi'
Expand Down Expand Up @@ -28,7 +28,7 @@
var/random = FALSE
var/cassette_desc_string = "Generic Desc"

/obj/item/device/cassette_tape/Initialize(mapload, spawned_id)
/obj/item/cassette_tape/Initialize(mapload, spawned_id)
. = ..()
if(!length(GLOB.approved_ids))
GLOB.approved_ids = initialize_approved_ids()
Expand Down Expand Up @@ -57,13 +57,13 @@

update_appearance()

/obj/item/device/cassette_tape/attack_self(mob/user)
/obj/item/cassette_tape/attack_self(mob/user)
..()
icon_state = flipped ? side1_icon : side2_icon
flipped = !flipped
to_chat(user, span_notice("You flip [src]."))

/obj/item/device/cassette_tape/update_desc(updates)
/obj/item/cassette_tape/update_desc(updates)
. = ..()
desc = cassette_desc_string
desc += "\n"
Expand All @@ -72,7 +72,7 @@
if(author_name)
desc += span_notice("Mixed by [author_name]\n")

/obj/item/device/cassette_tape/attackby(obj/item/item, mob/living/user)
/obj/item/cassette_tape/attackby(obj/item/item, mob/living/user)
if(!istype(item, /obj/item/pen))
return ..()
var/choice = tgui_input_list(usr, "What would you like to change?", items = list("Cassette Name", "Cassette Description", "Cancel"))
Expand Down Expand Up @@ -106,24 +106,8 @@
else
return

/datum/cassette/cassette_tape
var/name = "Broken Cassette"
var/desc = "You shouldn't be seeing this! Make an issue about it"
var/icon_state = "cassette_flip"
var/side1_icon = "cassette_flip"
var/side2_icon = "cassette_flip"
var/id = "blank"
var/creator_ckey = "Dwasint"
var/creator_name = "Collects-The-Candy"
var/approved = TRUE
var/list/song_names = list("side1" = list(),
"side2" = list())

var/list/songs = list("side1" = list(),
"side2" = list())

/obj/item/device/cassette_tape/blank
/obj/item/cassette_tape/blank
id = "blank"

/obj/item/device/cassette_tape/friday
/obj/item/cassette_tape/friday
id = "friday"
6 changes: 3 additions & 3 deletions monkestation/code/modules/cassettes/cassette_approval.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GLOBAL_LIST_INIT(cassette_reviews, list())

#define ADMIN_OPEN_REVIEW(id) "(<A href='?_src_=holder;[HrefToken(forceGlobal = TRUE)];open_music_review=[id]'>Open Review</a>)"
/proc/submit_cassette_for_review(obj/item/device/cassette_tape/submitted, mob/user)
/proc/submit_cassette_for_review(obj/item/cassette_tape/submitted, mob/user)
if(!user.client)
return
var/datum/cassette_review/new_review = new
Expand All @@ -25,7 +25,7 @@ GLOBAL_LIST_INIT(cassette_reviews, list())
has requested a review on their cassette."))]")
to_chat(user, span_notice("Your Cassette has been sent to the Space Board of Music for review, you will be notified when an outcome has been made."))

/obj/item/device/cassette_tape/proc/generate_cassette_json()
/obj/item/cassette_tape/proc/generate_cassette_json()
if(approved_tape)
return
if(!length(GLOB.approved_ids))
Expand Down Expand Up @@ -70,7 +70,7 @@ GLOBAL_LIST_INIT(cassette_reviews, list())
"song_url" = list()
)
)
var/obj/item/device/cassette_tape/submitted_tape
var/obj/item/cassette_tape/submitted_tape

var/action_taken = FALSE

Expand Down
Loading

0 comments on commit 32b17c8

Please sign in to comment.