Skip to content

Commit

Permalink
Refactors most spans into span procs (tgstation#59645)
Browse files Browse the repository at this point in the history
Converts most spans into span procs. Mostly used regex for this and sorted out any compile time errors afterwards so there could be some bugs.
Was initially going to do defines, but ninja said to make it into a proc, and if there's any overhead, they can easily be changed to defines.

Makes it easier to control the formatting and prevents typos when creating spans as it'll runtime if you misspell instead of silently failing.
Reduces the code you need to write when writing spans, as you don't need to close the span as that's automatically handled by the proc.

(Note from Lemon: This should be converted to defines once we update the minimum version to 514. Didn't do it now because byond pain and such)
  • Loading branch information
Watermelon914 authored Jun 14, 2021
1 parent b9982f6 commit 375a20e
Show file tree
Hide file tree
Showing 1,676 changed files with 15,455 additions and 15,226 deletions.
2 changes: 1 addition & 1 deletion code/__DEFINES/tgs.config.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define TGS_DEFINE_AND_SET_GLOBAL(Name, Value) GLOBAL_VAR_INIT(##Name, ##Value); GLOBAL_PROTECT(##Name)
#define TGS_READ_GLOBAL(Name) GLOB.##Name
#define TGS_WRITE_GLOBAL(Name, Value) GLOB.##Name = ##Value
#define TGS_WORLD_ANNOUNCE(message) to_chat(world, "<span class='boldannounce'>[html_encode(##message)]</span>")
#define TGS_WORLD_ANNOUNCE(message) to_chat(world, span_boldannounce("[html_encode(##message)]"))
#define TGS_INFO_LOG(message) log_world("TGS Info: [##message]")
#define TGS_WARNING_LOG(message) log_world("TGS Warn: [##message]")
#define TGS_ERROR_LOG(message) log_world("TGS Error: [##message]")
Expand Down
10 changes: 5 additions & 5 deletions code/__HELPERS/areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ GLOBAL_LIST_INIT(typecache_powerfailure_safe_areas, typecacheof(/area/engineerin
))
var/list/turfs = detect_room(get_turf(creator), area_or_turf_fail_types, BP_MAX_ROOM_SIZE*2)
if(!turfs)
to_chat(creator, "<span class='warning'>The new area must be completely airtight and not a part of a shuttle.</span>")
to_chat(creator, span_warning("The new area must be completely airtight and not a part of a shuttle."))
return
if(turfs.len > BP_MAX_ROOM_SIZE)
to_chat(creator, "<span class='warning'>The room you're in is too big. It is [turfs.len >= BP_MAX_ROOM_SIZE *2 ? "more than 100" : ((turfs.len / BP_MAX_ROOM_SIZE)-1)*100]% larger than allowed.</span>")
to_chat(creator, span_warning("The room you're in is too big. It is [turfs.len >= BP_MAX_ROOM_SIZE *2 ? "more than 100" : ((turfs.len / BP_MAX_ROOM_SIZE)-1)*100]% larger than allowed."))
return
var/list/areas = list("New Area" = /area)
for(var/i in 1 to turfs.len)
Expand All @@ -69,7 +69,7 @@ GLOBAL_LIST_INIT(typecache_powerfailure_safe_areas, typecacheof(/area/engineerin
area_choice = areas[area_choice]

if(!area_choice)
to_chat(creator, "<span class='warning'>No choice selected. The area remains undefined.</span>")
to_chat(creator, span_warning("No choice selected. The area remains undefined."))
return
var/area/newA
var/area/oldA = get_area(get_turf(creator))
Expand All @@ -78,7 +78,7 @@ GLOBAL_LIST_INIT(typecache_powerfailure_safe_areas, typecacheof(/area/engineerin
if(!str || !length(str)) //cancel
return
if(length(str) > 50)
to_chat(creator, "<span class='warning'>The given name is too long. The area remains undefined.</span>")
to_chat(creator, span_warning("The given name is too long. The area remains undefined."))
return
newA = new area_choice
newA.setup(str)
Expand All @@ -100,7 +100,7 @@ GLOBAL_LIST_INIT(typecache_powerfailure_safe_areas, typecacheof(/area/engineerin
var/obj/machinery/door/firedoor/FD = door
FD.CalculateAffectingAreas()

to_chat(creator, "<span class='notice'>You have created a new area, named [newA.name]. It is now weather proof, and constructing an APC will allow it to be powered.</span>")
to_chat(creator, span_notice("You have created a new area, named [newA.name]. It is now weather proof, and constructing an APC will allow it to be powered."))
return TRUE

#undef BP_MAX_ROOM_SIZE
8 changes: 4 additions & 4 deletions code/__HELPERS/game.dm
Original file line number Diff line number Diff line change
Expand Up @@ -394,22 +394,22 @@
var/list/answers = ignore_category ? list("Yes", "No", "Never for this round") : list("Yes", "No")
switch(tgui_alert(M, Question, "A limited-time offer!", answers, timeout=poll_time))
if("Yes")
to_chat(M, "<span class='notice'>Choice registered: Yes.</span>")
to_chat(M, span_notice("Choice registered: Yes."))
if(time_passed + poll_time <= world.time)
to_chat(M, "<span class='danger'>Sorry, you answered too late to be considered!</span>")
to_chat(M, span_danger("Sorry, you answered too late to be considered!"))
SEND_SOUND(M, 'sound/machines/buzz-sigh.ogg')
candidates -= M
else
candidates += M
if("No")
to_chat(M, "<span class='danger'>Choice registered: No.</span>")
to_chat(M, span_danger("Choice registered: No."))
candidates -= M
if("Never for this round")
var/list/L = GLOB.poll_ignore[ignore_category]
if(!L)
GLOB.poll_ignore[ignore_category] = list()
GLOB.poll_ignore[ignore_category] += M.ckey
to_chat(M, "<span class='danger'>Choice registered: Never for this round.</span>")
to_chat(M, span_danger("Choice registered: Never for this round."))
candidates -= M
else
candidates -= M
Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/hearted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
/mob/proc/nominate_heart(mob/heart_recepient, duration = 24 HOURS, instant = FALSE)
if(!mind || !client || !heart_recepient?.client)
return
to_chat(src, "<span class='nicegreen'>Commendation sent!</span>")
to_chat(src, span_nicegreen("Commendation sent!"))
message_admins("[key_name(src)] commended [key_name(heart_recepient)] [instant ? "" : "(roundend)"]")
log_admin("[key_name(src)] commended [key_name(heart_recepient)] [instant ? "" : "(roundend)"]")
if(instant || SSticker.current_state == GAME_STATE_FINISHED)
Expand Down
6 changes: 3 additions & 3 deletions code/__HELPERS/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ GLOBAL_LIST_EMPTY(species_list)
if(interaction_key)
var/current_interaction_count = LAZYACCESS(user.do_afters, interaction_key) || 0
if(current_interaction_count >= max_interact_count) //We are at our peak
to_chat(user, "<span class='warning'>You can't do this at the moment!</span>")
to_chat(user, span_warning("You can't do this at the moment!"))
return
LAZYSET(user.do_afters, interaction_key, current_interaction_count + 1)

Expand Down Expand Up @@ -465,7 +465,7 @@ GLOBAL_LIST_EMPTY(species_list)
// Displays a message in deadchat, sent by source. source is not linkified, message is, to avoid stuff like character names to be linkified.
// Automatically gives the class deadsay to the whole message (message + source)
/proc/deadchat_broadcast(message, source=null, mob/follow_target=null, turf/turf_target=null, speaker_key=null, message_type=DEADCHAT_REGULAR, admin_only=FALSE)
message = "<span class='deadsay'>[source]<span class='linkify'>[message]</span></span>"
message = span_deadsay("[source]<span class='linkify'>[message]</span>")

for(var/mob/M in GLOB.player_list)
var/chat_toggles = TOGGLES_DEFAULT_CHAT
Expand All @@ -480,7 +480,7 @@ GLOBAL_LIST_EMPTY(species_list)
if (!M.client.holder)
return
else
message += "<span class='deadsay'> (This is viewable to admins only).</span>"
message += span_deadsay(" (This is viewable to admins only).")
var/override = FALSE
if(M.client.holder && (chat_toggles & CHAT_DEAD))
override = TRUE
Expand Down
6 changes: 3 additions & 3 deletions code/__HELPERS/priority_announce.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if(SSstation.announcer.custom_alert_message && !has_important_message)
announcement += SSstation.announcer.custom_alert_message
else
announcement += "<br><span class='alert'>[html_encode(text)]</span><br>"
announcement += "<br>[span_alert("[html_encode(text)]")]<br>"
announcement += "<br>"

var/s = sound(sound)
Expand All @@ -56,7 +56,7 @@
var/meeting_sound = sound('sound/misc/emergency_meeting.ogg')
var/announcement
announcement += "<h1 class='alert'>Captain Alert</h1>"
announcement += "<br><span class='alert'>[user] has called an Emergency Meeting!</span><br><br>"
announcement += "<br>[span_alert("[user] has called an Emergency Meeting!")]<br><br>"

for(var/mob/mob_to_teleport in GLOB.player_list) //gotta make sure the whole crew's here!
if(isnewplayer(mob_to_teleport) || iscameramob(mob_to_teleport))
Expand Down Expand Up @@ -99,7 +99,7 @@

for(var/mob/M in GLOB.player_list)
if(!isnewplayer(M) && M.can_hear())
to_chat(M, "<span class='minorannounce'><font color = red>[title]</font color><BR>[message]</span><BR>")
to_chat(M, "[span_minorannounce("<font color = red>[title]</font color><BR>[message]")]<BR>")
if(M.client.prefs.toggles & SOUND_ANNOUNCEMENTS)
if(alert)
SEND_SOUND(M, sound('sound/misc/notice1.ogg'))
Expand Down
34 changes: 17 additions & 17 deletions code/__HELPERS/roundend.dm
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
CHECK_TICK

handle_hearts()
set_observer_default_invisibility(0, "<span class='warning'>The round is over! You are now visible to the living.</span>")
set_observer_default_invisibility(0, span_warning("The round is over! You are now visible to the living."))

CHECK_TICK

Expand Down Expand Up @@ -328,7 +328,7 @@
var/info = statspage ? "<a href='?action=openLink&link=[url_encode(statspage)][GLOB.round_id]'>[GLOB.round_id]</a>" : GLOB.round_id
parts += "[FOURSPACES]Round ID: <b>[info]</b>"
parts += "[FOURSPACES]Shift Duration: <B>[DisplayTimeText(world.time - SSticker.round_start_time)]</B>"
parts += "[FOURSPACES]Station Integrity: <B>[GLOB.station_was_nuked ? "<span class='redtext'>Destroyed</span>" : "[popcount["station_integrity"]]%"]</B>"
parts += "[FOURSPACES]Station Integrity: <B>[GLOB.station_was_nuked ? span_redtext("Destroyed") : "[popcount["station_integrity"]]%"]</B>"
var/total_players = GLOB.joined_player_list.len
if(total_players)
parts+= "[FOURSPACES]Total Population: <B>[total_players]</B>"
Expand Down Expand Up @@ -413,14 +413,14 @@
parts += "<span class='marooned'>You managed to survive, but were marooned on [station_name()]...</span>"
else
parts += "<div class='panel greenborder'>"
parts += "<span class='greentext'>You managed to survive the events on [station_name()] as [M.real_name].</span>"
parts += span_greentext("You managed to survive the events on [station_name()] as [M.real_name].")
else
parts += "<div class='panel greenborder'>"
parts += "<span class='greentext'>You managed to survive the events on [station_name()] as [M.real_name].</span>"
parts += span_greentext("You managed to survive the events on [station_name()] as [M.real_name].")

else
parts += "<div class='panel redborder'>"
parts += "<span class='redtext'>You did not survive the events on [station_name()]...</span>"
parts += span_redtext("You did not survive the events on [station_name()]...")
else
parts += "<div class='panel stationborder'>"
parts += "<br>"
Expand All @@ -446,7 +446,7 @@
var/mob/living/silicon/ai/aiPlayer = i
var/datum/mind/aiMind = aiPlayer.deployed_shell?.mind || aiPlayer.mind
if(aiMind)
parts += "<b>[aiPlayer.name]</b> (Played by: <b>[aiMind.key]</b>)'s laws [aiPlayer.stat != DEAD ? "at the end of the round" : "when it was <span class='redtext'>deactivated</span>"] were:"
parts += "<b>[aiPlayer.name]</b> (Played by: <b>[aiMind.key]</b>)'s laws [aiPlayer.stat != DEAD ? "at the end of the round" : "when it was [span_redtext("deactivated")]"] were:"
parts += aiPlayer.laws.get_law_list(include_zeroth=TRUE)

parts += "<b>Total law changes: [aiPlayer.law_change_counter]</b>"
Expand All @@ -457,13 +457,13 @@
for(var/mob/living/silicon/robot/robo in aiPlayer.connected_robots)
borg_num--
if(robo.mind)
parts += "<b>[robo.name]</b> (Played by: <b>[robo.mind.key]</b>)[robo.stat == DEAD ? " <span class='redtext'>(Deactivated)</span>" : ""][borg_num ?", ":""]"
parts += "<b>[robo.name]</b> (Played by: <b>[robo.mind.key]</b>)[robo.stat == DEAD ? " [span_redtext("(Deactivated)")]" : ""][borg_num ?", ":""]"
if(!borg_spacer)
borg_spacer = TRUE

for (var/mob/living/silicon/robot/robo in GLOB.silicon_mobs)
if (!robo.connected_ai && robo.mind)
parts += "[borg_spacer?"<br>":""]<b>[robo.name]</b> (Played by: <b>[robo.mind.key]</b>) [(robo.stat != DEAD)? "<span class='greentext'>survived</span> as an AI-less borg!" : "was <span class='redtext'>unable to survive</span> the rigors of being a cyborg without an AI."] Its laws were:"
parts += "[borg_spacer?"<br>":""]<b>[robo.name]</b> (Played by: <b>[robo.mind.key]</b>) [(robo.stat != DEAD)? "[span_greentext("survived")] as an AI-less borg!" : "was [span_redtext("unable to survive")] the rigors of being a cyborg without an AI."] Its laws were:"

if(robo) //How the hell do we lose robo between here and the world messages directly above this?
parts += robo.laws.get_law_list(include_zeroth=TRUE)
Expand Down Expand Up @@ -513,12 +513,12 @@
log_econ("Roundend service income: [tourist_income] credits.")
switch(tourist_income)
if(0)
parts += "<span class='redtext'>Service did not earn any credits...</span><br>"
parts += "[span_redtext("Service did not earn any credits...")]<br>"
if(1 to 2000)
parts += "<span class='redtext'>Centcom is displeased. Come on service, surely you can do better than that.</span><br>"
parts += "[span_redtext("Centcom is displeased. Come on service, surely you can do better than that.")]<br>"
award_service(/datum/award/achievement/jobs/service_bad)
if(2001 to 4999)
parts += "<span class='greentext'>Centcom is satisfied with service's job today.</span><br>"
parts += "[span_greentext("Centcom is satisfied with service's job today.")]<br>"
award_service(/datum/award/achievement/jobs/service_okay)
else
parts += "<span class='reallybig greentext'>Centcom is incredibly impressed with service today! What a team!</span><br>"
Expand Down Expand Up @@ -682,17 +682,17 @@
var/text = "<b>[ply.key]</b> was <b>[ply.name]</b>[jobtext] and"
if(ply.current)
if(ply.current.stat == DEAD)
text += " <span class='redtext'>died</span>"
text += " [span_redtext("died")]"
else
text += " <span class='greentext'>survived</span>"
text += " [span_greentext("survived")]"
if(fleecheck)
var/turf/T = get_turf(ply.current)
if(!T || !is_station_level(T.z))
text += " while <span class='redtext'>fleeing the station</span>"
text += " while [span_redtext("fleeing the station")]"
if(ply.current.real_name != ply.name)
text += " as <b>[ply.current.real_name]</b>"
else
text += " <span class='redtext'>had their body destroyed</span>"
text += " [span_redtext("had their body destroyed")]"
return text

/proc/printplayerlist(list/players,fleecheck)
Expand All @@ -712,9 +712,9 @@
var/count = 1
for(var/datum/objective/objective in objectives)
if(objective.check_completion())
objective_parts += "<b>[objective.objective_name] #[count]</b>: [objective.explanation_text] <span class='greentext'>Success!</span>"
objective_parts += "<b>[objective.objective_name] #[count]</b>: [objective.explanation_text] [span_greentext("Success!")]"
else
objective_parts += "<b>[objective.objective_name] #[count]</b>: [objective.explanation_text] <span class='redtext'>Fail.</span>"
objective_parts += "<b>[objective.objective_name] #[count]</b>: [objective.explanation_text] [span_redtext("Fail.")]"
count++
return objective_parts.Join("<br>")

Expand Down
Loading

0 comments on commit 375a20e

Please sign in to comment.