@@ -59,13 +59,17 @@ SUBSYSTEM_DEF(codex)
59
59
string = replacetextEx(string, linkRegex. match, replacement)
60
60
return string
61
61
62
+ // / Returns a codex entry for the given query. May return a list if multiple are found, or null if none.
62
63
/ datum / controller/ subsystem/ codex/ proc / get_codex_entry(entry)
63
64
if (isatom(entry))
64
65
var /atom /entity = entry
65
66
. = entity. get_specific_codex_entry()
66
67
if (. )
67
68
return
68
69
return entries_by_path[entity. type] || get_entry_by_string(entity. name)
70
+
71
+ if (isdatum(entry))
72
+ entry = entry: type
69
73
if (ispath(entry))
70
74
return entries_by_path[entry]
71
75
if (istext(entry))
@@ -74,13 +78,40 @@ SUBSYSTEM_DEF(codex)
74
78
/ datum / controller/ subsystem/ codex/ proc / get_entry_by_string(string)
75
79
return entries_by_string[codex_sanitize(string)]
76
80
81
+ // / Presents a codex entry to a mob. If it receives a list of entries, it will prompt them to choose one.
77
82
/ datum / controller/ subsystem/ codex/ proc / present_codex_entry( mob / presenting_to, datum / codex_entry/ entry)
78
- if (entry && istype(presenting_to) && presenting_to. client)
79
- var /datum /browser/popup = new (presenting_to, " codex" , " Codex" , nheight= 425 ) // "codex\ref[entry]"
80
- var /entry_data = entry. get_codex_body(presenting_to)
81
- popup. set_content(parse_links(jointext(entry_data, null ), presenting_to))
82
- popup. open()
83
-
83
+ if (! entry || ! istype(presenting_to) || ! presenting_to. client)
84
+ return
85
+
86
+ if (islist(entry))
87
+ present_codex_search (presenting_to, entry)
88
+ return
89
+
90
+ var /datum /browser/popup = new (presenting_to, " codex" , " Codex" , nheight= 425 ) // "codex\ref[entry]"
91
+ var /entry_data = entry. get_codex_body(presenting_to)
92
+ popup. set_content(parse_links(jointext(entry_data, null ), presenting_to))
93
+ popup. open()
94
+
95
+ #define CODEX_ENTRY_LIMIT 10
96
+ // / Presents a list of codex entries to a mob.
97
+ / datum / controller/ subsystem/ codex/ proc / present_codex_search( mob / presenting_to, list / entries, search_query)
98
+ var /list /codex_data = list ()
99
+ codex_data += " <h3><b>[ entries. len] matches</b> [ search_query ? " for '[ search_query] '" : " " ] :</h3>"
100
+
101
+ if (LAZYLEN (entries) > CODEX_ENTRY_LIMIT )
102
+ codex_data += " Showing first <b>[ CODEX_ENTRY_LIMIT ] </b> entries. <b> [ entries. len - 5 ] result \s </b> omitted.</br>"
103
+ codex_data += " <table width = 100%>"
104
+
105
+ for (var /i = 1 to min (entries. len, CODEX_ENTRY_LIMIT ))
106
+ var /datum /codex_entry/entry = entries[i]
107
+ codex_data += " <tr><td>[ entry. name] </td><td><a href='?src= \ref [ SScodex] ;show_examined_info= \ref [ entry] ;show_to= \ref [ presenting_to] '>View</a></td></tr>"
108
+ codex_data += " </table>"
109
+
110
+ var /datum /browser/popup = new (presenting_to, " codex-search" , " Codex Search" ) // "codex-search"
111
+ popup. set_content(codex_data. Join())
112
+ popup. open()
113
+
114
+ #undef CODEX_ENTRY_LIMIT
84
115
/ datum / controller/ subsystem/ codex/ proc / get_guide(category)
85
116
var /datum /codex_category/cat = codex_categories[category]
86
117
. = cat?. guide_html
@@ -91,25 +122,36 @@ SUBSYSTEM_DEF(codex)
91
122
return list ()
92
123
93
124
searching = codex_sanitize(searching)
125
+
94
126
if (! searching)
95
127
return list ()
96
- if (! search_cache[searching])
97
- var /list /results
98
- if (entries_by_string[searching])
99
- results = list (entries_by_string[searching])
100
- else
101
- results = list ()
102
- for (var /entry_title in entries_by_string)
103
- var /datum /codex_entry/entry = entries_by_string[entry_title]
104
- if (findtext(entry. name, searching) || findtext(entry. lore_text, searching) || findtext(entry. mechanics_text, searching) || findtext(entry. antag_text, searching))
105
- results |= entry
106
- search_cache[searching] = sortTim(results, GLOBAL_PROC_REF (cmp_name_asc))
107
- return search_cache[searching]
128
+
129
+ . = search_cache[searching]
130
+ if (. )
131
+ return .
132
+
133
+ var /list /results = list ()
134
+ var /list /priority_results = list ()
135
+ if (entries_by_string[searching])
136
+ results = entries_by_string[searching]
137
+ else
138
+ for (var /datum /codex_entry/entry as anything in all_entries)
139
+ if (findtext(entry. name, searching))
140
+ priority_results += entry
141
+
142
+ else if (findtext(entry. lore_text, searching) || findtext(entry. mechanics_text, searching) || findtext(entry. antag_text, searching))
143
+ results += entry
144
+
145
+ sortTim (priority_results, GLOBAL_PROC_REF (cmp_name_asc))
146
+ sortTim (results, GLOBAL_PROC_REF (cmp_name_asc))
147
+ priority_results += results
148
+ search_cache[searching] = priority_results
149
+ . = search_cache[searching]
108
150
109
151
/ datum / controller/ subsystem/ codex/ Topic(href, href_list)
110
152
. = .. ()
111
153
if (!. && href_list[" show_examined_info" ] && href_list[" show_to" ])
112
- var /mob /showing_mob = locate (href_list[" show_to" ])
154
+ var /mob /showing_mob = locate (href_list[" show_to" ])
113
155
if (! istype(showing_mob))
114
156
return
115
157
var /atom /showing_atom = locate (href_list[" show_examined_info" ])
0 commit comments