Skip to content

Commit

Permalink
fix: don't send all the title images on login
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaxeer committed Jan 27, 2024
1 parent 68ce905 commit ff9303e
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 112 deletions.
2 changes: 1 addition & 1 deletion modular_ss220/title_screen/_title_screen.dme
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "code/dead.dm"
#include "code/living.dm"
#include "code/asset_lobby.dm"
#include "code/mob.dm"
#include "code/title_screen_datum.dm"
#include "code/new_player.dm"
#include "code/title_screen_controls.dm"
#include "code/title_screen_subsystem.dm"
3 changes: 2 additions & 1 deletion modular_ss220/title_screen/code/_title_screen_defines.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define DEFAULT_TITLE_SCREEN_IMAGE "default.gif"
#define DEFAULT_TITLE_SCREEN_IMAGE_NAME "default.gif"
#define DEFAULT_TITLE_SCREEN_IMAGE_PATH 'modular_ss220/title_screen/icons/default.gif'

#define DEFAULT_TITLE_HTML {"
<html>
Expand Down
15 changes: 0 additions & 15 deletions modular_ss220/title_screen/code/asset_lobby.dm
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/datum/asset/group/lobby
children = list(
/datum/asset/simple/lobby_fonts,
/datum/asset/simple/lobby_title_screen_images
)

/datum/asset/simple/lobby_fonts
assets = list(
"FixedsysExcelsior3.01Regular.ttf" = 'modular_ss220/title_screen/html/browser/FixedsysExcelsior3.01Regular.ttf',
)

/datum/asset/simple/lobby_title_screen_images
assets = list(
DEFAULT_TITLE_SCREEN_IMAGE = 'modular_ss220/title_screen/icons/default.gif'
)

/datum/asset/simple/lobby_title_screen_images/register()
assets += SStitle.get_title_screens()
return ..()
39 changes: 0 additions & 39 deletions modular_ss220/title_screen/code/mob.dm

This file was deleted.

2 changes: 1 addition & 1 deletion modular_ss220/title_screen/code/new_player.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/mob/new_player/Login()
. = ..()
show_title_screen()
SStitle.show_title_screen(src)
8 changes: 5 additions & 3 deletions modular_ss220/title_screen/code/title_screen_controls.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
var/file = input(usr) as icon|null
if(!file)
return
SStitle.change_title_screen(file)

message_admins("Custom title Screen: [file]")
// SStitle.change_title_screen(file)
if("Reset")
SStitle.change_title_screen()
if("Cancel")
Expand Down Expand Up @@ -52,9 +54,9 @@
set category = "Special Verbs"

if(istype(mob, /mob/new_player))
mob.show_title_screen()
SStitle.current_title_screen.show_to(mob)
else
mob.hide_title_screen()
SStitle.current_title_screen.hide_from(mob)

/**
* An admin debug command that enables you to change the HTML on the go.
Expand Down
62 changes: 62 additions & 0 deletions modular_ss220/title_screen/code/title_screen_datum.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/datum/title_screen
/// The preamble html that includes all styling and layout.
var/title_html = DEFAULT_TITLE_HTML
/// The current notice text, or null.
var/notice
/// The current title screen being displayed, as `/datum/asset_cache_item`
var/datum/asset_cache_item/screen_image

/datum/title_screen/New(title_html, notice, screen_image_file_name, screen_image_file)
src.title_html = title_html
src.notice = notice
set_screen_image(screen_image_file_name, screen_image_file)

/datum/title_screen/proc/set_screen_image(screen_image_file_name, screen_image_file)
if(!isfile(screen_image_file))
screen_image_file = fcopy_rsc(screen_image_file)

screen_image = SSassets.transport.register_asset(screen_image_file_name, screen_image_file)

/datum/title_screen/proc/show_to(client/viewer)
if(ismob(viewer))
var/mob/viewer_mob = viewer
viewer = viewer_mob.client

if(!viewer)
return

winset(viewer, "title_browser", "is-disabled=true;is-visible=true")
winset(viewer, "status_bar", "is-visible=false")

var/datum/asset/lobby_asset = get_asset_datum(/datum/asset/simple/lobby_fonts)
lobby_asset.send(viewer)

SSassets.transport.send_assets(viewer, screen_image)

viewer << browse(get_title_html(), "window=title_browser")

/datum/title_screen/proc/hide_from(client/viewer)
if(client?.mob)
winset(client, "title_browser", "is-disabled=true;is-visible=false")
winset(client, "status_bar", "is-visible=true")

/**
* Get the HTML of title screen.
*/
/datum/title_screen/proc/get_title_html()
var/list/html = list()

var/screen_image_url = SSassets.transport.get_asset_url(asset_cache_item = screen_image)
if(screen_image_url)
html += {"<img src="[screen_image_url]" class="bg" alt="">"}

if(notice)
html += {"
<div class="container_notice">
<p class="menu_notice">[notice]</p>
</div>
"}

html += "</body></html>"

return html.Join()
87 changes: 35 additions & 52 deletions modular_ss220/title_screen/code/title_screen_subsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,16 @@
/datum/controller/subsystem/title
flags = SS_NO_FIRE
init_order = INIT_ORDER_TITLE
/// The current title screen being displayed, as a file path text.
var/current_title_screen
/// The current notice text, or null.
var/current_notice
/// The preamble html that includes all styling and layout.
var/title_html
/// Currently set title screen
var/datum/title_screen/current_title_screen
/// The list of possible title screens to rotate through, as: title_screen_name -> title_screen_path
var/list/title_screens = list()

/datum/controller/subsystem/title/Initialize()
if(!fexists("config/title_html.txt"))
error(span_boldwarning("Unable to read title_html.txt, reverting to backup title html, please check your server config and ensure this file exists."))
title_html = DEFAULT_TITLE_HTML
else
title_html = file2text("config/title_html.txt")

load_title_screens()
change_title_screen()
setup_title_screen()

/datum/controller/subsystem/title/Recover()
current_title_screen = SStitle.current_title_screen
current_notice = SStitle.current_notice
title_html = SStitle.title_html
title_screens = SStitle.title_screens

/**
Expand All @@ -34,72 +21,68 @@
/datum/controller/subsystem/title/proc/load_title_screens()
var/list/valid_title_screens = list()
for(var/screen in flist(TITLE_SCREENS_LOCATION))
if(validate_title_screen(screen))
if(validate_title_screen_name(screen))
valid_title_screens += screen

for(var/title_screen_name in valid_title_screens)
var/file_path = "[TITLE_SCREENS_LOCATION][title_screen_name]"
ASSERT(fexists(file_path))
title_screens[title_screen_name] = fcopy_rsc(file_path)
if(fexists(file_path))
title_screens[title_screen_name] = fcopy_rsc(file_path)

/**
* Checks wheter passed title is valid
* Currently validates extension and checks whether it's special image like default title screen etc.
*/
/datum/controller/subsystem/title/proc/validate_title_screen(title_screen_to_validate)
var/static/list/title_screens_to_ignore = list("blank.png", DEFAULT_TITLE_SCREEN_IMAGE)
/datum/controller/subsystem/title/proc/validate_title_screen_name(title_screen_to_validate)
var/static/list/title_screens_to_ignore = list("blank.png", DEFAULT_TITLE_SCREEN_IMAGE_NAME)
if(title_screen_to_validate in title_screens_to_ignore)
return FALSE

var/list/name_parts = splittext(title_screen_to_validate, ".")
if(length(name_parts) < 2)
return FALSE

var/static/list/supported_extensions = list("gif", "jpg", "jpeg","png", "svg")
var/extension = name_parts[length(name_parts)]
var/extension = findlasttext_char(title_screen_to_validate, ".")
return (extension in supported_extensions)

/**
* Returns the list of all loaded title screens, if no title screens present, tries to load them.
*/
/datum/controller/subsystem/title/proc/get_title_screens()
if(!length(title_screens))
load_title_screens()

return title_screens.Copy()

/**
* Returns current title screen or if null, default one.
*/
/datum/controller/subsystem/title/proc/get_current_title_screen()
return current_title_screen || DEFAULT_TITLE_SCREEN_IMAGE

/**
* Show the title screen to all new players.
*/
/datum/controller/subsystem/title/proc/show_title_screen()
for(var/mob/new_player/new_player in GLOB.player_list)
INVOKE_ASYNC(new_player, TYPE_PROC_REF(/mob/new_player, show_title_screen))
/datum/controller/subsystem/title/proc/show_title_screen(list/viewers)
for(var/mob/new_player/viewer in viewers)
INVOKE_ASYNC(current_title_screen, TYPE_PROC_REF(/datum/title_screen, show_to), viewer)

/**
* Adds a notice to the main title screen in the form of big red text!
*/
/datum/controller/subsystem/title/proc/set_notice(new_title)
current_notice = new_title ? sanitize_text(new_title) : null
current_title_screen.notice = new_title ? sanitize_text(new_title) : null
show_title_screen()

/**
* Changes the title screen to a new image.
*/
/datum/controller/subsystem/title/proc/change_title_screen(new_screen)
if(new_screen)
current_title_screen = new_screen
/datum/controller/subsystem/title/proc/change_title_screen()
var/screen_image_file_name
var/screen_image_file
if(length(title_screens))
screen_image_file_name = pick(title_screens)
screen_image_file = title_screens[screen_image_file_name]
else
if(length(title_screens))
current_title_screen = pick(title_screens)
else
current_title_screen = DEFAULT_TITLE_SCREEN_IMAGE
screen_image_file_name = DEFAULT_TITLE_SCREEN_IMAGE_NAME
screen_image_file = DEFAULT_TITLE_SCREEN_IMAGE_PATH

if(current_title_screen)
current_title_screen.set_screen_image(screen_image_file_name, screen_image_file)
else
current_title_screen = new(screen_image_file_name = screen_image_file_name, screen_image_file = screen_image_file)

show_title_screen()

/datum/controller/subsystem/title/proc/setup_title_screen()
load_title_screens()
change_title_screen()
if(!fexists("config/title_html.txt"))
error(span_boldwarning("Unable to read title_html.txt, reverting to backup title html, please check your server config and ensure this file exists."))
current_title_screen.title_html = DEFAULT_TITLE_HTML
else
current_title_screen.title_html = file2text("config/title_html.txt")

#undef TITLE_SCREENS_LOCATION

0 comments on commit ff9303e

Please sign in to comment.