mirror of
https://github.com/Yawn-Wider/YWPolarisVore.git
synced 2026-08-26 06:26:41 +01:00
PoIs can be rotated in increments of 90 degrees
This commit is contained in:
@@ -35,7 +35,7 @@ var/global/use_preloader = FALSE
|
||||
* 2) Read the map line by line, parsing the result (using parse_grid)
|
||||
*
|
||||
*/
|
||||
/dmm_suite/load_map(dmm_file as file, x_offset as num, y_offset as num, z_offset as num, cropMap as num, measureOnly as num, no_changeturf as num)
|
||||
/dmm_suite/load_map(dmm_file as file, x_offset as num, y_offset as num, z_offset as num, cropMap as num, measureOnly as num, no_changeturf as num, orientation as num)
|
||||
//How I wish for RAII
|
||||
if(!measureOnly)
|
||||
Master.StartLoadingMap()
|
||||
@@ -43,7 +43,7 @@ var/global/use_preloader = FALSE
|
||||
#ifdef TESTING
|
||||
turfsSkipped = 0
|
||||
#endif
|
||||
. = load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf)
|
||||
. = load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf, orientation)
|
||||
#ifdef TESTING
|
||||
if(turfsSkipped)
|
||||
testing("Skipped loading [turfsSkipped] default turfs")
|
||||
@@ -51,7 +51,7 @@ var/global/use_preloader = FALSE
|
||||
if(!measureOnly)
|
||||
Master.StopLoadingMap()
|
||||
|
||||
/dmm_suite/proc/load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf)
|
||||
/dmm_suite/proc/load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf, orientation)
|
||||
var/tfile = dmm_file//the map file we're creating
|
||||
if(isfile(tfile))
|
||||
tfile = file2text(tfile)
|
||||
@@ -63,6 +63,10 @@ var/global/use_preloader = FALSE
|
||||
if(!z_offset)
|
||||
z_offset = world.maxz + 1
|
||||
|
||||
// If it's not a single dir, default to north (Default orientation)
|
||||
if(!orientation in cardinal)
|
||||
orientation = SOUTH
|
||||
|
||||
var/list/bounds = list(1.#INF, 1.#INF, 1.#INF, -1.#INF, -1.#INF, -1.#INF)
|
||||
var/list/grid_models = list()
|
||||
var/key_len = 0
|
||||
@@ -95,6 +99,11 @@ var/global/use_preloader = FALSE
|
||||
var/ycrd = text2num(dmmRegex.group[4]) + y_offset - 1
|
||||
var/zcrd = text2num(dmmRegex.group[5]) + z_offset - 1
|
||||
|
||||
if(orientation & (EAST | WEST))
|
||||
xcrd = ycrd // temp variable
|
||||
ycrd = xcrdStart
|
||||
xcrdStart = xcrd
|
||||
|
||||
var/zexpansion = zcrd > world.maxz
|
||||
if(zexpansion && !measureOnly)
|
||||
if(cropMap)
|
||||
@@ -132,14 +141,73 @@ var/global/use_preloader = FALSE
|
||||
bounds[MAP_MAXY] = max(bounds[MAP_MAXY], min(ycrd, world.maxy))
|
||||
|
||||
var/maxx = xcrdStart
|
||||
|
||||
// Assemble the grid of keys
|
||||
var/list/key_list = list()
|
||||
for(var/line in gridLines)
|
||||
var/list/line_keys = list()
|
||||
xcrd = 1
|
||||
for(var/tpos = 1 to length(line) - key_len + 1 step key_len)
|
||||
if(xcrd > world.maxx)
|
||||
if(cropMap)
|
||||
break
|
||||
else
|
||||
world.maxx = xcrd
|
||||
|
||||
if(xcrd >= 1)
|
||||
var/model_key = copytext(line, tpos, tpos + key_len)
|
||||
if(!grid_models[model_key])
|
||||
throw EXCEPTION("Undefined model key in DMM: [dmm_file], [model_key].")
|
||||
line_keys[++line_keys.len] = model_key
|
||||
#ifdef TESTING
|
||||
else
|
||||
++turfsSkipped
|
||||
#endif
|
||||
CHECK_TICK
|
||||
maxx = max(maxx, ++xcrd)
|
||||
key_list[++key_list.len] = line_keys
|
||||
|
||||
// Rotate the list according to orientation
|
||||
if(orientation != SOUTH)
|
||||
var/num_cols = key_list[1].len
|
||||
var/num_rows = key_list.len
|
||||
var/list/new_key_list = list()
|
||||
// If it's rotated 180 degrees, the dimensions are the same
|
||||
if(orientation == NORTH)
|
||||
new_key_list.len = num_rows
|
||||
for(var/i in 1 to new_key_list.len)
|
||||
new_key_list[i] = list()
|
||||
new_key_list[i].len = num_cols
|
||||
// Else, the dimensions are swapped
|
||||
else
|
||||
new_key_list.len = num_cols
|
||||
for(var/i in 1 to new_key_list.len)
|
||||
new_key_list[i] = list()
|
||||
new_key_list[i].len = num_rows
|
||||
|
||||
num_rows++ // Buffering against the base index of 1
|
||||
num_cols++
|
||||
// Populate the new list
|
||||
for(var/i in 1 to key_list.len)
|
||||
for(var/j in 1 to key_list[i].len)
|
||||
switch(orientation)
|
||||
if(NORTH)
|
||||
new_key_list[i][j] = key_list[num_rows - i][num_cols - j]
|
||||
if(EAST)
|
||||
new_key_list[i][j] = key_list[num_cols - i][j]
|
||||
if(WEST)
|
||||
new_key_list[i][j] = key_list[j][num_rows - i]
|
||||
|
||||
key_list = new_key_list
|
||||
|
||||
if(measureOnly)
|
||||
for(var/line in gridLines)
|
||||
maxx = max(maxx, xcrdStart + length(line) / key_len - 1)
|
||||
for(var/list/line in key_list)
|
||||
maxx = max(maxx, line.len)
|
||||
else
|
||||
for(var/line in gridLines)
|
||||
for(var/i in 1 to key_list.len)
|
||||
if(ycrd <= world.maxy && ycrd >= 1)
|
||||
xcrd = xcrdStart
|
||||
for(var/tpos = 1 to length(line) - key_len + 1 step key_len)
|
||||
for(var/j = 1 to key_list.len)
|
||||
if(xcrd > world.maxx)
|
||||
if(cropMap)
|
||||
break
|
||||
@@ -147,12 +215,11 @@ var/global/use_preloader = FALSE
|
||||
world.maxx = xcrd
|
||||
|
||||
if(xcrd >= 1)
|
||||
var/model_key = copytext(line, tpos, tpos + key_len)
|
||||
var/no_afterchange = no_changeturf || zexpansion
|
||||
if(!no_afterchange || (model_key != space_key))
|
||||
if(!grid_models[model_key])
|
||||
if(!no_afterchange || (key_list[i][j] != space_key))
|
||||
if(!grid_models[key_list[i][j]])
|
||||
throw EXCEPTION("Undefined model key in DMM.")
|
||||
parse_grid(grid_models[model_key], model_key, xcrd, ycrd, zcrd, no_changeturf || zexpansion)
|
||||
parse_grid(grid_models[key_list[i][j]], key_list[i][j], xcrd, ycrd, zcrd, no_afterchange, orientation)
|
||||
#ifdef TESTING
|
||||
else
|
||||
++turfsSkipped
|
||||
@@ -194,7 +261,7 @@ var/global/use_preloader = FALSE
|
||||
* 4) Instanciates the atom with its variables
|
||||
*
|
||||
*/
|
||||
/dmm_suite/proc/parse_grid(model as text, model_key as text, xcrd as num,ycrd as num,zcrd as num, no_changeturf as num)
|
||||
/dmm_suite/proc/parse_grid(model as text, model_key as text, xcrd as num,ycrd as num,zcrd as num, no_changeturf as num, orientation as num)
|
||||
/*Method parse_grid()
|
||||
- Accepts a text string containing a comma separated list of type paths of the
|
||||
same construction as those contained in a .dmm file, and instantiates them.
|
||||
@@ -236,6 +303,7 @@ var/global/use_preloader = FALSE
|
||||
|
||||
//transform the variables in text format into a list (e.g {var1="derp"; var2; var3=7} => list(var1="derp", var2, var3=7))
|
||||
var/list/fields = list()
|
||||
var/dir_found = FALSE // If dir isn't mapped, then we'll need to add an attribute entry to rotate it according to orientation
|
||||
|
||||
if(variables_start)//if there's any variable
|
||||
full_def = copytext(full_def,variables_start+1,length(full_def))//removing the last '}'
|
||||
@@ -248,6 +316,16 @@ var/global/use_preloader = FALSE
|
||||
if(istext(value))
|
||||
fields[I] = apply_text_macros(value)
|
||||
|
||||
// Rotate dir if orientation isn't south (default)
|
||||
if(orientation != SOUTH && findtext(splittext(fields[I], "="), " dir ")) // Spaces are necessary, or we might catch other vars
|
||||
var/list/L = splittext(fields[I], " ")
|
||||
L[L.len] = turn(text2num(L.len), dir2angle(orientation) + 180) // South is 0 here, dir2angle assumes north is 0
|
||||
fields[I] = jointext(L, " ")
|
||||
dir_found = TRUE
|
||||
|
||||
if(!dir_found)
|
||||
fields[++fields.len] = "dir = [num2text(orientation)]"
|
||||
|
||||
//then fill the members_attributes list with the corresponding variables
|
||||
members_attributes.len++
|
||||
members_attributes[index++] = fields
|
||||
|
||||
Reference in New Issue
Block a user