Skip to content

Commit

Permalink
Changes relatives paths into absolute paths and makes some if()'s better
Browse files Browse the repository at this point in the history
  • Loading branch information
Firecage committed Jan 16, 2016
1 parent e5a6113 commit 754491c
Show file tree
Hide file tree
Showing 69 changed files with 1,305 additions and 868 deletions.
164 changes: 83 additions & 81 deletions code/__HELPERS/bygex/bygex.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,41 @@
#define LIBREGEX_LIBRARY "bin/bygex"
#endif

/proc
regEx_compare(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regEx_compare")(str, exp))
/proc/regEx_compare(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regEx_compare")(str, exp))

regex_compare(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regex_compare")(str, exp))
/proc/regex_compare(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regex_compare")(str, exp))

regEx_find(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regEx_find")(str, exp))
/proc/regEx_find(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regEx_find")(str, exp))

regex_find(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regex_find")(str, exp))
/proc/regex_find(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regex_find")(str, exp))

regEx_replaceall(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regEx_replaceall")(str, exp, fmt)
/proc/regEx_replaceall(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regEx_replaceall")(str, exp, fmt)

regex_replaceall(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regex_replaceall")(str, exp, fmt)
/proc/regex_replaceall(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regex_replaceall")(str, exp, fmt)

replacetextEx(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regEx_replaceallliteral")(str, exp, fmt)
/proc/replacetextEx(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regEx_replaceallliteral")(str, exp, fmt)

replacetext(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regex_replaceallliteral")(str, exp, fmt)
/proc/replacetext(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regex_replaceallliteral")(str, exp, fmt)

regEx_replace(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regEx_replace")(str, exp, fmt)
/proc/regEx_replace(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regEx_replace")(str, exp, fmt)

regex_replace(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regex_replace")(str, exp, fmt)
/proc/regex_replace(str, exp, fmt)
return call(LIBREGEX_LIBRARY, "regex_replace")(str, exp, fmt)

regEx_findall(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regEx_findall")(str, exp))
/proc/regEx_findall(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regEx_findall")(str, exp))

regex_findall(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regex_findall")(str, exp))
/proc/regex_findall(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regex_findall")(str, exp))


//upon calling a regex match or search, a /datum/regex object is created with str(haystack) and exp(needle) variables set
Expand All @@ -79,66 +78,69 @@
var/anchors = 0
var/list/matches = list()

New(str, exp, results)
src.str = str
src.exp = exp

if(findtext(results, "$Err$", 1, 6)) //error message
src.error = results
else
var/list/L = params2list(results)
var/list/M
var{i;j}
for(i in L)
M = L[i]
for(j=2, j<=M.len, j+=2)
matches += new /datum/match(text2num(M[j-1]),text2num(M[j]))
anchors = (j-2)/2
return matches

proc
str(i)
if(!i) return str
var/datum/match/M = matches[i]
if(i < 1 || i > matches.len)
throw EXCEPTION("str(): out of bounds")
return copytext(str, M.pos, M.pos+M.len)

pos(i)
if(!i) return 1
if(i < 1 || i > matches.len)
throw EXCEPTION("pos(): out of bounds")
var/datum/match/M = matches[i]
return M.pos

len(i)
if(!i) return length(str)
if(i < 1 || i > matches.len)
throw EXCEPTION("len(): out of bounds")
var/datum/match/M = matches[i]
return M.len

end(i)
if(!i) return length(str)
if(i < 1 || i > matches.len)
throw EXCEPTION("end() out of bounds")
var/datum/match/M = matches[i]
return M.pos + M.len

report() //debug tool
. = ":: RESULTS ::\n:: str :: [html_encode(str)]\n:: exp :: [html_encode(exp)]\n:: anchors :: [anchors]"
if(error)
. += "\n<font color='red'>[error]</font>"
return
for(var/i=1, i<=matches.len, ++i)
. += "\nMatch[i]\n\t[html_encode(str(i))]\n\tpos=[pos(i)] len=[len(i)]"
/datum/regex/New(str, exp, results)
src.str = str
src.exp = exp

if(findtext(results, "$Err$", 1, 6)) //error message
src.error = results
else
var/list/L = params2list(results)
var/list/M
var{i;j}
for(i in L)
M = L[i]
for(j=2, j<=M.len, j+=2)
matches += new /datum/match(text2num(M[j-1]),text2num(M[j]))
anchors = (j-2)/2
return matches

/datum/regex/proc/str(i)
if(!i)
return str
var/datum/match/M = matches[i]
if(i < 1 || i > matches.len)
throw EXCEPTION("str(): out of bounds")
return copytext(str, M.pos, M.pos+M.len)

/datum/regex/proc/pos(i)
if(!i)
return 1
if(i < 1 || i > matches.len)
throw EXCEPTION("pos(): out of bounds")
var/datum/match/M = matches[i]
return M.pos

/datum/regex/proc/len(i)
if(!i)
return length(str)
if(i < 1 || i > matches.len)
throw EXCEPTION("len(): out of bounds")
var/datum/match/M = matches[i]
return M.len

/datum/regex/proc/end(i)
if(!i)
return length(str)
if(i < 1 || i > matches.len)
throw EXCEPTION("end() out of bounds")
var/datum/match/M = matches[i]
return M.pos + M.len

/datum/regex/proc/report() //debug tool
. = ":: RESULTS ::\n:: str :: [html_encode(str)]\n:: exp :: [html_encode(exp)]\n:: anchors :: [anchors]"
if(error)
. += "\n<font color='red'>[error]</font>"
return
for(var/i=1, i<=matches.len, ++i)
. += "\nMatch[i]\n\t[html_encode(str(i))]\n\tpos=[pos(i)] len=[len(i)]"

/datum/match
var/pos
var/len

New(pos, len)
src.pos = pos
src.len = len
/datum/match/New(pos, len)
src.pos = pos
src.len = len

#endif
95 changes: 47 additions & 48 deletions code/__HELPERS/bygex/demo.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,50 @@

var/datum/regex/results

verb
set_expression()
var/t = input(usr,"Input Expression","title",expression) as text|null
if(t != null)
expression = t
usr << "Expression set to:\t[html_encode(t)]"

set_format()
var/t = input(usr,"Input Formatter","title",format) as text|null
if(t != null)
format = t
usr << "Format set to:\t[html_encode(t)]"

compare_casesensitive(t as text)
results = regEx_compare(t, expression)
world << results.report()

compare(t as text)
results = regex_compare(t, expression)
world << results.report()

find_casesensitive(t as text)
results = regEx_find(t, expression)
world << results.report()

find(t as text)
results = regex_find(t, expression)
world << results.report()

replaceall_casesensitive(t as text)
usr << regEx_replaceall(t, expression, format)

replaceall(t as text)
usr << regex_replaceall(t, expression, format)

replace_casesensitive(t as text)
usr << html_encode(regEx_replace(t, expression, format))

replace(t as text)
usr << regex_replace(t, expression, format)

findall(t as text)
results = regex_findall(t, expression)
world << results.report()

findall_casesensitive(t as text)
results = regEx_findall(t, expression)
world << results.report()
/mob/verb/set_expression()
var/t = input(usr,"Input Expression","title",expression) as text|null
if(t != null)
expression = t
usr << "Expression set to:\t[html_encode(t)]"

/mob/verb/set_format()
var/t = input(usr,"Input Formatter","title",format) as text|null
if(t != null)
format = t
usr << "Format set to:\t[html_encode(t)]"

/mob/verb/compare_casesensitive(t as text)
results = regEx_compare(t, expression)
world << results.report()

/mob/verb/compare(t as text)
results = regex_compare(t, expression)
world << results.report()

/mob/verb/find_casesensitive(t as text)
results = regEx_find(t, expression)
world << results.report()

/mob/verb/find(t as text)
results = regex_find(t, expression)
world << results.report()

/mob/verb/replaceall_casesensitive(t as text)
usr << regEx_replaceall(t, expression, format)

/mob/verb/replaceall(t as text)
usr << regex_replaceall(t, expression, format)

/mob/verb/replace_casesensitive(t as text)
usr << html_encode(regEx_replace(t, expression, format))

/mob/verb/replace(t as text)
usr << regex_replace(t, expression, format)

/mob/verb/findall(t as text)
results = regex_findall(t, expression)
world << results.report()

/mob/verb/findall_casesensitive(t as text)
results = regEx_findall(t, expression)
world << results.report()
12 changes: 8 additions & 4 deletions code/__HELPERS/game.dm
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,19 @@
return candidates

/proc/ScreenText(obj/O, maptext="", screen_loc="CENTER-7,CENTER-7", maptext_height=480, maptext_width=480)
if(!isobj(O)) O = new /obj/screen/text()
if(!isobj(O))
O = new /obj/screen/text()
O.maptext = maptext
O.maptext_height = maptext_height
O.maptext_width = maptext_width
O.screen_loc = screen_loc
return O

/proc/Show2Group4Delay(obj/O, list/group, delay=0)
if(!isobj(O)) return
if(!group) group = clients
if(!isobj(O))
return
if(!group)
group = clients
for(var/client/C in group)
C.screen += O
if(delay)
Expand Down Expand Up @@ -409,7 +412,8 @@
return candidates

/proc/makeBody(mob/dead/observer/G_found) // Uses stripped down and bastardized code from respawn character
if(!G_found || !G_found.key) return
if(!G_found || !G_found.key)
return

//First we spawn a dude.
var/mob/living/carbon/human/new_character = new(pick(latejoin))//The mob being spawned.
Expand Down
3 changes: 2 additions & 1 deletion code/__HELPERS/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
//creates every subtype of prototype (excluding prototype) and adds it to list L.
//if no list/L is provided, one is created.
/proc/init_subtypes(prototype, list/L)
if(!istype(L)) L = list()
if(!istype(L))
L = list()
for(var/path in subtypesof(prototype))
L += new path()
return L
Expand Down
21 changes: 13 additions & 8 deletions code/__HELPERS/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ The _flatIcons list is a cache for generated icon files.
/proc/getIconMask(atom/A)//By yours truly. Creates a dynamic mask for a mob/whatever. /N
var/icon/alpha_mask = new(A.icon,A.icon_state)//So we want the default icon and icon state of A.
for(var/I in A.overlays)//For every image in overlays. var/image/I will not work, don't try it.
if(I:layer>A.layer) continue//If layer is greater than what we need, skip it.
if(I:layer>A.layer)
continue//If layer is greater than what we need, skip it.
var/icon/image_overlay = new(I:icon,I:icon_state)//Blend only works with icon objects.
//Also, icons cannot directly set icon_state. Slower than changing variables but whatever.
alpha_mask.Blend(image_overlay,ICON_OR)//OR so they are lumped together in a nice overlay.
Expand All @@ -799,10 +800,14 @@ The _flatIcons list is a cache for generated icon files.
for(var/i=0,i<5,i++)//And now we add it as overlays. It's faster than creating an icon and then merging it.
var/image/I = image("icon" = opacity_icon, "icon_state" = A.icon_state, "layer" = layer+0.8)//So it's above other stuff but below weapons and the like.
switch(i)//Now to determine offset so the result is somewhat blurred.
if(1) I.pixel_x--
if(2) I.pixel_x++
if(3) I.pixel_y--
if(4) I.pixel_y++
if(1)
I.pixel_x--
if(2)
I.pixel_x++
if(3)
I.pixel_y--
if(4)
I.pixel_y++
overlays += I//And finally add the overlay.

/proc/getHologramIcon(icon/A, safety=1)//If safety is on, a new icon is not created.
Expand Down Expand Up @@ -920,12 +925,12 @@ var/global/list/humanoid_icon_cache = list()
/proc/get_flat_human_icon(var/icon_id,var/outfit,var/datum/preferences/prefs)
if(!icon_id || !humanoid_icon_cache[icon_id])
var/mob/living/carbon/human/dummy/body = new()

if(prefs)
prefs.copy_to(body)
if(outfit)
body.equipOutfit(outfit, TRUE)

var/icon/out_icon = icon('icons/effects/effects.dmi', "nothing")

body.dir = NORTH
Expand All @@ -945,7 +950,7 @@ var/global/list/humanoid_icon_cache = list()
out_icon.Insert(partial,dir=EAST)

qdel(body)

humanoid_icon_cache[icon_id] = out_icon
return out_icon
else
Expand Down
Loading

0 comments on commit 754491c

Please sign in to comment.