mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
Implementing RoundIDs (#7740)
This commit is contained in:
@@ -1,102 +1,106 @@
|
||||
/*!
|
||||
* Copyright (c) 2020 Aleksej Komarov
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* tgui_panel datum
|
||||
* Hosts tgchat and other nice features.
|
||||
*/
|
||||
/datum/tgui_panel
|
||||
var/client/client
|
||||
var/datum/tgui_window/window
|
||||
var/broken = FALSE
|
||||
var/initialized_at
|
||||
var/oldchat = FALSE
|
||||
|
||||
/datum/tgui_panel/New(client/client, id)
|
||||
src.client = client
|
||||
window = new(client, id)
|
||||
window.subscribe(src, PROC_REF(on_message))
|
||||
|
||||
/datum/tgui_panel/Del()
|
||||
window.unsubscribe(src)
|
||||
window.close()
|
||||
return ..()
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* TRUE if panel is initialized and ready to receive messages.
|
||||
*/
|
||||
/datum/tgui_panel/proc/is_ready()
|
||||
return !broken && window.is_ready()
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Initializes tgui panel.
|
||||
*/
|
||||
/datum/tgui_panel/proc/initialize(force = FALSE)
|
||||
set waitfor = FALSE
|
||||
// Minimal sleep to defer initialization to after client constructor
|
||||
sleep(1 TICKS)
|
||||
initialized_at = world.time
|
||||
// Perform a clean initialization
|
||||
window.initialize(
|
||||
strict_mode = TRUE,
|
||||
assets = list(
|
||||
get_asset_datum(/datum/asset/simple/tgui_panel),
|
||||
))
|
||||
window.send_asset(get_asset_datum(/datum/asset/simple/fontawesome))
|
||||
window.send_asset(get_asset_datum(/datum/asset/simple/tgfont))
|
||||
window.send_asset(get_asset_datum(/datum/asset/spritesheet/chat))
|
||||
// Other setup
|
||||
request_telemetry()
|
||||
addtimer(CALLBACK(src, PROC_REF(on_initialize_timed_out)), 5 SECONDS)
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Called when initialization has timed out.
|
||||
*/
|
||||
/datum/tgui_panel/proc/on_initialize_timed_out()
|
||||
// Currently does nothing but sending a message to old chat.
|
||||
// SEND_TEXT(client, "<span class=\"userdanger\">Failed to load fancy chat, click <a href='?src=[REF(src)];reload_tguipanel=1'>HERE</a> to attempt to reload it.</span>")
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Callback for handling incoming tgui messages.
|
||||
*/
|
||||
/datum/tgui_panel/proc/on_message(type, payload)
|
||||
if(type == "ready")
|
||||
broken = FALSE
|
||||
window.send_message("update", list(
|
||||
"config" = list(
|
||||
"client" = list(
|
||||
"ckey" = client.ckey,
|
||||
"address" = client.address,
|
||||
"computer_id" = client.computer_id,
|
||||
),
|
||||
"window" = list(
|
||||
"fancy" = FALSE,
|
||||
"locked" = FALSE,
|
||||
),
|
||||
),
|
||||
))
|
||||
return TRUE
|
||||
if(type == "audio/setAdminMusicVolume")
|
||||
client.admin_music_volume = payload["volume"]
|
||||
return TRUE
|
||||
if(type == "telemetry")
|
||||
analyze_telemetry(payload)
|
||||
return TRUE
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Sends a round restart notification.
|
||||
*/
|
||||
/datum/tgui_panel/proc/send_roundrestart()
|
||||
window.send_message("roundrestart")
|
||||
/*!
|
||||
* Copyright (c) 2020 Aleksej Komarov
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* tgui_panel datum
|
||||
* Hosts tgchat and other nice features.
|
||||
*/
|
||||
/datum/tgui_panel
|
||||
var/client/client
|
||||
var/datum/tgui_window/window
|
||||
var/broken = FALSE
|
||||
var/initialized_at
|
||||
var/oldchat = FALSE
|
||||
|
||||
/datum/tgui_panel/New(client/client, id)
|
||||
src.client = client
|
||||
window = new(client, id)
|
||||
window.subscribe(src, PROC_REF(on_message))
|
||||
|
||||
/datum/tgui_panel/Del()
|
||||
window.unsubscribe(src)
|
||||
window.close()
|
||||
return ..()
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* TRUE if panel is initialized and ready to receive messages.
|
||||
*/
|
||||
/datum/tgui_panel/proc/is_ready()
|
||||
return !broken && window.is_ready()
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Initializes tgui panel.
|
||||
*/
|
||||
/datum/tgui_panel/proc/initialize(force = FALSE)
|
||||
set waitfor = FALSE
|
||||
// Minimal sleep to defer initialization to after client constructor
|
||||
sleep(1 TICKS)
|
||||
initialized_at = world.time
|
||||
// Perform a clean initialization
|
||||
window.initialize(
|
||||
strict_mode = TRUE,
|
||||
assets = list(
|
||||
get_asset_datum(/datum/asset/simple/tgui_panel),
|
||||
))
|
||||
window.send_asset(get_asset_datum(/datum/asset/simple/fontawesome))
|
||||
window.send_asset(get_asset_datum(/datum/asset/simple/tgfont))
|
||||
window.send_asset(get_asset_datum(/datum/asset/spritesheet/chat))
|
||||
// Other setup
|
||||
request_telemetry()
|
||||
addtimer(CALLBACK(src, PROC_REF(on_initialize_timed_out)), 5 SECONDS)
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Called when initialization has timed out.
|
||||
*/
|
||||
/datum/tgui_panel/proc/on_initialize_timed_out()
|
||||
// Currently does nothing but sending a message to old chat.
|
||||
// SEND_TEXT(client, "<span class=\"userdanger\">Failed to load fancy chat, click <a href='?src=[REF(src)];reload_tguipanel=1'>HERE</a> to attempt to reload it.</span>")
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Callback for handling incoming tgui messages.
|
||||
*/
|
||||
/datum/tgui_panel/proc/on_message(type, payload)
|
||||
if(type == "ready")
|
||||
broken = FALSE
|
||||
window.send_message("update", list(
|
||||
"config" = list(
|
||||
"client" = list(
|
||||
"ckey" = client.ckey,
|
||||
"address" = client.address,
|
||||
"computer_id" = client.computer_id,
|
||||
),
|
||||
// CHOMPEdit - "server" section
|
||||
"server" = list(
|
||||
"round_id" = GLOB.round_id,
|
||||
),
|
||||
"window" = list(
|
||||
"fancy" = FALSE,
|
||||
"locked" = FALSE,
|
||||
),
|
||||
),
|
||||
))
|
||||
return TRUE
|
||||
if(type == "audio/setAdminMusicVolume")
|
||||
client.admin_music_volume = payload["volume"]
|
||||
return TRUE
|
||||
if(type == "telemetry")
|
||||
analyze_telemetry(payload)
|
||||
return TRUE
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Sends a round restart notification.
|
||||
*/
|
||||
/datum/tgui_panel/proc/send_roundrestart()
|
||||
window.send_message("roundrestart")
|
||||
|
||||
Reference in New Issue
Block a user