-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathantags.dm
150 lines (104 loc) · 4.19 KB
/
antags.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/datum/preference_middleware/antags
action_delegations = list(
"set_antags" = PROC_REF(set_antags),
)
/datum/preference_middleware/antags/get_ui_static_data(mob/user)
if (preferences.current_window != PREFERENCE_TAB_CHARACTER_PREFERENCES)
return list()
var/list/data = list()
var/list/selected_antags = list()
for (var/antag in preferences.be_special)
selected_antags += serialize_antag_name(antag)
data["selected_antags"] = selected_antags
var/list/antag_bans = get_antag_bans()
if (antag_bans.len)
data["antag_bans"] = antag_bans
var/list/antag_days_left = get_antag_days_left()
if (antag_days_left?.len)
data["antag_days_left"] = antag_days_left
return data
/datum/preference_middleware/antags/get_ui_assets()
return list(
get_asset_datum(/datum/asset/spritesheet/antagonists),
)
/datum/preference_middleware/antags/proc/set_antags(list/params, mob/user)
SHOULD_NOT_SLEEP(TRUE)
var/sent_antags = params["antags"]
var/toggled = params["toggled"]
var/antags = list()
var/serialized_antags = get_serialized_antags()
for (var/sent_antag in sent_antags)
var/special_role = serialized_antags[sent_antag]
if (!special_role)
continue
antags += special_role
if (toggled)
preferences.be_special |= antags
else
preferences.be_special -= antags
// This is predicted on the client
return FALSE
/datum/preference_middleware/antags/proc/get_antag_bans()
var/list/antag_bans = list()
for(var/datum/round_event_control/antagonist/solo/event as anything in subtypesof(/datum/round_event_control/antagonist/solo))
var/antag_flag = initial(event.antag_flag)
if (isnull(antag_flag))
continue
if (is_banned_from(preferences.parent.ckey, list(antag_flag, ROLE_ANTAG)))
antag_bans += serialize_antag_name(antag_flag)
return antag_bans
/datum/preference_middleware/antags/proc/get_antag_days_left()
if (!CONFIG_GET(flag/use_age_restriction_for_jobs))
return
var/list/antag_days_left = list()
for(var/datum/round_event_control/antagonist/solo/event as anything in subtypesof(/datum/round_event_control/antagonist/solo))
var/antag_flag = initial(event.antag_flag)
if (isnull(antag_flag))
continue
var/days_needed = 0
if (days_needed > 0)
antag_days_left[serialize_antag_name(antag_flag)] = days_needed
return antag_days_left
/datum/preference_middleware/antags/proc/get_serialized_antags()
var/list/serialized_antags
if (isnull(serialized_antags))
serialized_antags = list()
for (var/special_role in GLOB.special_roles)
serialized_antags[serialize_antag_name(special_role)] = special_role
return serialized_antags
/// Sprites generated for the antagonists panel
/datum/asset/spritesheet/antagonists
name = "antagonists"
early = TRUE
cross_round_cachable = TRUE
/datum/asset/spritesheet/antagonists/create_spritesheets()
// Antagonists that don't have a dynamic ruleset, but do have a preference
var/static/list/non_ruleset_antagonists = list(
ROLE_LONE_OPERATIVE = /datum/antagonist/nukeop/lone,
)
var/list/antagonists = GLOB.special_roles.Copy()
var/list/generated_icons = list()
var/list/to_insert = list()
for (var/antag_flag in antagonists)
var/datum/antagonist/antagonist_type = antagonists[antag_flag]
// antag_flag is guaranteed to be unique by unit tests.
var/spritesheet_key = serialize_antag_name(antag_flag)
if (!isnull(generated_icons[antagonist_type]))
to_insert[spritesheet_key] = generated_icons[antagonist_type]
continue
var/datum/antagonist/antagonist = new antagonist_type
var/icon/preview_icon = antagonist.get_preview_icon()
if (isnull(preview_icon))
continue
qdel(antagonist)
// preview_icons are not scaled at this stage INTENTIONALLY.
// If an icon is not prepared to be scaled to that size, it looks really ugly, and this
// makes it harder to figure out what size it *actually* is.
generated_icons[antagonist_type] = preview_icon
to_insert[spritesheet_key] = preview_icon
for (var/spritesheet_key in to_insert)
Insert(spritesheet_key, to_insert[spritesheet_key])
/// Serializes an antag name to be used for preferences UI
/proc/serialize_antag_name(antag_name)
// These are sent through CSS, so they need to be safe to use as class names.
return lowertext(sanitize_css_class_name(antag_name))