-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci skip] Refactors cassettes and the cassette player
- Loading branch information
Showing
9 changed files
with
473 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 70 additions & 59 deletions
129
monkestation/code/modules/cassettes/cassette_db/cassette_datum.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,72 @@ | ||
/datum/cassette_data | ||
var/cassette_name | ||
var/cassette_author | ||
var/cassette_desc | ||
var/cassette_author_ckey | ||
|
||
var/cassette_design_front | ||
var/cassette_design_back | ||
|
||
var/list/songs | ||
|
||
var/list/song_names | ||
|
||
var/cassette_id | ||
var/approved | ||
var/file_name | ||
|
||
|
||
/datum/cassette_data/proc/populate_data(file_id) | ||
var/file = file("data/cassette_storage/[file_id].json") | ||
if(!fexists(file)) | ||
return FALSE | ||
var/list/data = json_decode(file2text(file)) | ||
|
||
cassette_name = data["name"] | ||
cassette_desc = data["desc"] | ||
|
||
cassette_design_front = data["side1_icon"] | ||
cassette_design_back = data["side2_icon"] | ||
|
||
songs = data["songs"] | ||
|
||
song_names = data["song_names"] | ||
|
||
cassette_author = data["author_name"] | ||
cassette_author_ckey = data["author_ckey"] | ||
|
||
cassette_id = file_id | ||
|
||
/datum/cassette | ||
/// The name of the cassette. | ||
var/name | ||
/// The description of the cassette. | ||
var/desc | ||
/// The unique ID of the cassette. | ||
var/id | ||
/// If the cassette is approved or not. | ||
var/approved = FALSE | ||
/// Information about the author of this cassette. | ||
var/datum/cassette_author/author | ||
|
||
/// The front side of the cassette. | ||
var/datum/cassette_side/front | ||
/// The back side of the cassette. | ||
var/datum/cassette_side/back | ||
|
||
/datum/cassette/New() | ||
. = ..() | ||
author = new | ||
front = new | ||
back = new | ||
|
||
/// Imports cassette date from the old format. | ||
/datum/cassette/proc/import_old_format(list/data) | ||
name = data["name"] | ||
desc = data["desc"] | ||
approved = data["approved"] | ||
|
||
file_name = "data/cassette_storage/[file_id].json" | ||
|
||
return TRUE | ||
|
||
/datum/cassette_data/proc/generate_cassette(turf/location) | ||
if(!location) | ||
return | ||
var/obj/item/device/cassette_tape/new_tape = new(location) | ||
new_tape.name = cassette_name | ||
new_tape.cassette_desc_string = cassette_desc | ||
new_tape.icon_state = cassette_design_front | ||
new_tape.side1_icon = cassette_design_front | ||
new_tape.side2_icon = cassette_design_back | ||
new_tape.songs = songs | ||
new_tape.song_names = song_names | ||
new_tape.author_name = cassette_author | ||
new_tape.ckey_author = cassette_author_ckey | ||
new_tape.approved_tape = approved | ||
|
||
new_tape.update_appearance() | ||
author.name = data["author_name"] | ||
author.ckey = ckey(data["author_ckey"]) | ||
|
||
for(var/i in 1 to 2) | ||
var/datum/cassette_side/side = get_side(i % 2) // side2 = 0, side1 = 1 | ||
var/side_name = "side[i]" | ||
var/list/song_urls = data["songs"][side_name] | ||
var/list/song_names = data["song_names"][side_name] | ||
if(length(song_urls) != length(song_names)) | ||
stack_trace("amount of song urls for [side_name] ([length(song_urls)]) did not match amount of song names for [side_name] ([length(song_names)])") | ||
continue | ||
side.design = data["[side_name]_icon"] | ||
for(var/idx in 1 to length(song_urls)) | ||
side.songs += new /datum/cassette_song(song_names[idx], song_urls[idx]) | ||
|
||
/// Simple helper to get a side of the cassette. | ||
/// TRUE is front side, FALSE is back side. | ||
/datum/cassette/proc/get_side(front_side = TRUE) as /datum/cassette_side | ||
RETURN_TYPE(/datum/cassette_side) | ||
return front_side ? front : back | ||
|
||
/datum/cassette_author | ||
/// The character name of the cassette author. | ||
var/name | ||
/// The ckey of the cassette author. | ||
var/ckey | ||
|
||
/datum/cassette_side | ||
/// The design of this side of the cassette. | ||
var/design = "cassette_flip" | ||
/// The songs on this side of the cassette. | ||
var/list/datum/cassette_song/songs = list() | ||
|
||
/datum/cassette_song | ||
/// The name of the song. | ||
var/name | ||
/// The URL of the song. | ||
var/url | ||
|
||
/datum/cassette_song/New(name, url) | ||
. = ..() | ||
src.name = name | ||
src.url = url |
Oops, something went wrong.