mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-19 20:15:47 +01:00
Fixes newscaster channels having a random chance of breaking upon creation of a new channel, refactors how channels are tracked in the first place (#92371)
## About The Pull Request So in a recent round I noticed the newscaster UI was acting kind of funky, where two channels seemed to overlap and weirdly pick between the two in unpredictable ways. Looking into it, it seemed that somehow the channels had managed to get their unique IDs to overlap- Oh. https://github.com/tgstation/tgstation/blob/5d3353e7af2b88ab9379d5fb567b24afd8776acd/code/game/machinery/newscaster/newscaster_data.dm#L109-L131 I see. ...I think that code speaks for itself, in how this could've gone wrong. Anyhow, in this pr we entirely ditch this system, and instead make it use an incremental and thus guaranteed to be unique ID. This fixes our issues. While we're here, we also remove the unused `channel_IDs` list, and replace it with the associative lists `network_channels_by_id` and `network_channels_by_name`. This allows us to also stop iterating over every network channel until we find the one with the right name or ID. We also rename some confusing, wrong, or non-standard vars while we're here.
This commit is contained in:
@@ -170,19 +170,32 @@ GLOBAL_LIST_EMPTY_TYPED(active_bets, /datum/active_bet)
|
||||
for(var/option in options)
|
||||
if(!length(options[option]))
|
||||
options[option] = list()
|
||||
//we'll only advertise it on the first bet of the round, as to not make this overly annoying.
|
||||
var/should_alert = FALSE
|
||||
for(var/datum/feed_channel/FC in GLOB.news_network.network_channels)
|
||||
if(FC.channel_name == NEWSCASTER_SPACE_BETTING)
|
||||
if(!length(FC.messages))
|
||||
should_alert = TRUE
|
||||
newscaster_message = GLOB.news_network.submit_article("The bet [name] has started, place your bets now!", "NtOS Space Betting App", NEWSCASTER_SPACE_BETTING, null, update_alert = should_alert)
|
||||
advertise_bet()
|
||||
|
||||
/datum/active_bet/Destroy(force)
|
||||
GLOB.active_bets -= src
|
||||
newscaster_message = null
|
||||
return ..()
|
||||
|
||||
/// Place a feed article advertising our bet.
|
||||
/datum/active_bet/proc/advertise_bet()
|
||||
var/datum/feed_channel/betting_channel = GLOB.news_network.network_channels_by_name[NEWSCASTER_SPACE_BETTING]
|
||||
if(isnull(betting_channel))
|
||||
return
|
||||
// We'll only advertise it on the first bet of the round, as to not make this overly annoying.
|
||||
var/should_alert = !length(betting_channel.messages)
|
||||
newscaster_message = GLOB.news_network.submit_article("The bet [name] has started, place your bets now!", "NtOS Space Betting App", NEWSCASTER_SPACE_BETTING, null, update_alert = should_alert)
|
||||
|
||||
/// Reply to our previously placed advertisement feed article.
|
||||
/datum/active_bet/proc/reply_to_feed(winning_option)
|
||||
if(isnull(newscaster_message))
|
||||
return
|
||||
GLOB.news_network.submit_comment(
|
||||
comment_text = "The bet [name] has ended, the winner was [winning_option]!",
|
||||
newscaster_username = "NtOS Betting Results",
|
||||
current_message = newscaster_message,
|
||||
)
|
||||
|
||||
///Returns how many bets there is per option
|
||||
/datum/active_bet/proc/get_bets(datum/bank_account/user_account)
|
||||
var/list/bets_per_option = list()
|
||||
@@ -206,11 +219,8 @@ GLOBAL_LIST_EMPTY_TYPED(active_bets, /datum/active_bet)
|
||||
var/datum/bank_account/refunded_account = existing_bets[1]
|
||||
refunded_account.adjust_money(text2num(existing_bets[2]), "Refund: [name] gamble cancelled.")
|
||||
return
|
||||
GLOB.news_network.submit_comment(
|
||||
comment_text = "The bet [name] has ended, the winner was [winning_option]!",
|
||||
newscaster_username = "NtOS Betting Results",
|
||||
current_message = newscaster_message,
|
||||
)
|
||||
|
||||
reply_to_feed(winning_option)
|
||||
var/list/winners = options[winning_option]
|
||||
if(!length(winners))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user