Fixed bug with front door placement
This commit is contained in:
@@ -9,11 +9,12 @@ const BITLEFT = (1 << 2)
|
||||
const BITRIGHT = (1 << 3)
|
||||
var exits = []
|
||||
var windows = []
|
||||
var outside_doors = []
|
||||
|
||||
var door = preload("res://scenes/maps/door.tscn")
|
||||
var jail_door = preload("res://scenes/maps/jail-door.tscn")
|
||||
var window = preload("res://scenes/maps/window.tscn")
|
||||
var outside_door = preload("res://scenes/maps/window.tscn")
|
||||
var outside_door = preload("res://scenes/maps/door-outside.tscn")
|
||||
var stairs = preload("res://scenes/maps/stairs.tscn")
|
||||
var outside_door_placed = false
|
||||
var tw2d
|
||||
@@ -127,31 +128,46 @@ func _ready():
|
||||
te2d = $c_modular/e2d.transform
|
||||
tn2d = $c_modular/n2d.transform
|
||||
ts2d = $c_modular/s2d.transform
|
||||
var open_paths = {
|
||||
OPEN_UP: {
|
||||
"rm_walls": ["n2d", "iw4d"],
|
||||
"rm": ["fc4"],
|
||||
"bit": BITUP
|
||||
},
|
||||
OPEN_DOWN: {
|
||||
"rm_walls": ["s2d", "iw11d"],
|
||||
"rm": ["fc5"],
|
||||
"bit": BITDOWN
|
||||
},
|
||||
OPEN_LEFT: {
|
||||
"rm_walls": ["w2d", "iw17d"],
|
||||
"rm": ["fc2"],
|
||||
"bit": BITLEFT
|
||||
},
|
||||
OPEN_RIGHT: {
|
||||
"rm_walls": ["e2d", "iw22d"],
|
||||
"rm": ["fc3"],
|
||||
"bit": BITRIGHT
|
||||
},
|
||||
}
|
||||
func open_path(flag):
|
||||
if flag == OPEN_UP:
|
||||
$c_modular/n2d.queue_free()
|
||||
$c_modular/iw4d.queue_free()
|
||||
$fc4.queue_free()
|
||||
bitflags |= BITUP
|
||||
elif flag == OPEN_DOWN:
|
||||
$c_modular/s2d.queue_free()
|
||||
$c_modular/iw11d.queue_free()
|
||||
$fc5.queue_free()
|
||||
bitflags |= BITDOWN
|
||||
elif flag == OPEN_LEFT:
|
||||
$c_modular/w2d.queue_free()
|
||||
$c_modular/iw17d.queue_free()
|
||||
$fc2.queue_free()
|
||||
bitflags |= BITLEFT
|
||||
elif flag == OPEN_RIGHT:
|
||||
$c_modular/e2d.queue_free()
|
||||
$c_modular/iw22d.queue_free()
|
||||
$fc3.queue_free()
|
||||
bitflags |= BITRIGHT
|
||||
if !flag in exits:
|
||||
if exits.size() == 1 && !has_meta("master_room"):
|
||||
$fc1.queue_free()
|
||||
var kf = open_paths[flag]
|
||||
bitflags |= kf.bit
|
||||
exits.push_back(flag)
|
||||
for e in kf.rm:
|
||||
if get_node(e):
|
||||
get_node(e).queue_free()
|
||||
func create_paths():
|
||||
for flag in exits:
|
||||
var kf = open_paths[flag]
|
||||
for e in kf.rm_walls:
|
||||
$c_modular.get_node(e).queue_free()
|
||||
for e in kf.rm:
|
||||
if get_node(e):
|
||||
get_node(e).queue_free()
|
||||
if exits.size() == 1 && !has_meta("master_room"):
|
||||
$fc1.queue_free()
|
||||
func open_window(flag):
|
||||
if !flag in windows:
|
||||
windows.push_back(flag)
|
||||
@@ -202,51 +218,85 @@ func master_room():
|
||||
func wall2door(n):
|
||||
var door_xform = n.transform
|
||||
var door_i
|
||||
for e in get_tree().get_nodes_in_group("door"):
|
||||
var xpos = e.global_transform.origin
|
||||
var ypos = n.global_transform.origin
|
||||
if xpos.distance_to(ypos) < 1.3:
|
||||
n.queue_free()
|
||||
return
|
||||
if has_meta("jail_room"):
|
||||
door_i = jail_door.instance()
|
||||
else:
|
||||
door_i = door.instance()
|
||||
add_child(door_i)
|
||||
door_i.transform = door_xform
|
||||
door_i.add_to_group("door")
|
||||
n.queue_free()
|
||||
func exit_door(n):
|
||||
var xn = n.name
|
||||
var exit_door_xform = n.transform
|
||||
var xdoor_i = outside_door.instance()
|
||||
add_child(xdoor_i)
|
||||
xdoor_i.transform = exit_door_xform
|
||||
xdoor_i.name = xn
|
||||
n.queue_free()
|
||||
xdoor_i.add_to_group("exit_door")
|
||||
func wall2window(n):
|
||||
var window_xform = n.transform
|
||||
var xn = n.name
|
||||
var window_i
|
||||
# if has_meta("jail_room"):
|
||||
# window_i = jail_window.instance()
|
||||
# else:
|
||||
# window_i = door.instance()
|
||||
if has_meta("exit_room") && !outside_door_placed:
|
||||
print("exit room place door")
|
||||
window_i = outside_door.instance()
|
||||
outside_door_placed = true
|
||||
global.exit_door = window_i
|
||||
else:
|
||||
window_i = window.instance()
|
||||
window_i = window.instance()
|
||||
add_child(window_i)
|
||||
window_i.name = xn
|
||||
window_i.transform = window_xform
|
||||
n.queue_free()
|
||||
|
||||
var bitdata = {
|
||||
BITLEFT: {
|
||||
"doors": ["iw17d"],
|
||||
"path_remove": ["path_west"],
|
||||
"nodes_remove": ["iw1", "iw2d", "iw3", "iw8", "iw9d", "iw10"]
|
||||
},
|
||||
BITRIGHT: {
|
||||
"doors": ["iw22d"],
|
||||
"path_remove": ["path_east"],
|
||||
"nodes_remove": ["iw5", "iw6d", "iw7", "iw12", "iw13d", "iw14"]
|
||||
},
|
||||
BITUP: {
|
||||
"doors": [],
|
||||
"path_remove": ["path_north"],
|
||||
"nodes_remove": ["iw15", "iw16d", "iw23d", "iw24"]
|
||||
},
|
||||
BITDOWN: {
|
||||
"doors": [],
|
||||
"path_remove": ["path_south"],
|
||||
"nodes_remove": ["iw18d", "iw19", "iw20", "iw21d"]
|
||||
}
|
||||
}
|
||||
|
||||
var master_metas = ["master_room", "kitchen_room", "exit_room", "stairs"]
|
||||
func create_rooms():
|
||||
assert(exits.size() > 0)
|
||||
if has_meta("master_room"):
|
||||
create_paths()
|
||||
var is_master_room = false
|
||||
for m in master_metas:
|
||||
if has_meta(m):
|
||||
is_master_room = true
|
||||
if is_master_room:
|
||||
master_room()
|
||||
elif has_meta("kitchen_room"):
|
||||
master_room()
|
||||
elif has_meta("exit_room"):
|
||||
assert(windows.size() > 0)
|
||||
master_room()
|
||||
for e in get_children():
|
||||
if e.is_in_group("furniture"):
|
||||
e.queue_free()
|
||||
elif has_meta("stairs"):
|
||||
master_room()
|
||||
var stairs_i = stairs.instance()
|
||||
add_child(stairs_i)
|
||||
for e in get_children():
|
||||
if e.is_in_group("furniture"):
|
||||
e.queue_free()
|
||||
if get_meta("stairs") > 0:
|
||||
$c_modular/floor.queue_free()
|
||||
if has_meta("exit_room"):
|
||||
assert(windows.size() > 0)
|
||||
for e in get_children():
|
||||
if e.is_in_group("furniture"):
|
||||
e.queue_free()
|
||||
if has_meta("stairs"):
|
||||
var stairs_i = stairs.instance()
|
||||
add_child(stairs_i)
|
||||
for e in get_children():
|
||||
if e.is_in_group("furniture"):
|
||||
e.queue_free()
|
||||
if get_meta("stairs") > 0:
|
||||
$c_modular/floor.queue_free()
|
||||
elif exits.size() == 1:
|
||||
personal_room()
|
||||
elif exits.size() == 4:
|
||||
@@ -255,49 +305,26 @@ func create_rooms():
|
||||
wall2door($c_modular/iw9d)
|
||||
wall2door($c_modular/iw13d)
|
||||
else:
|
||||
if bitflags & BITLEFT == 0:
|
||||
$c_modular/iw1.queue_free()
|
||||
$c_modular/iw2d.queue_free()
|
||||
$c_modular/iw3.queue_free()
|
||||
$c_modular/iw8.queue_free()
|
||||
$c_modular/iw9d.queue_free()
|
||||
$c_modular/iw10.queue_free()
|
||||
wall2door($c_modular/iw17d)
|
||||
$path_west.queue_free()
|
||||
if bitflags & BITRIGHT == 0:
|
||||
$c_modular/iw5.queue_free()
|
||||
$c_modular/iw6d.queue_free()
|
||||
$c_modular/iw7.queue_free()
|
||||
$c_modular/iw12.queue_free()
|
||||
$c_modular/iw13d.queue_free()
|
||||
$c_modular/iw14.queue_free()
|
||||
wall2door($c_modular/iw22d)
|
||||
$path_east.queue_free()
|
||||
if bitflags & BITUP == 0:
|
||||
$c_modular/iw15.queue_free()
|
||||
$c_modular/iw16d.queue_free()
|
||||
$c_modular/iw23d.queue_free()
|
||||
$c_modular/iw24.queue_free()
|
||||
$path_north.queue_free()
|
||||
if bitflags & BITDOWN == 0:
|
||||
$c_modular/iw18d.queue_free()
|
||||
$c_modular/iw19.queue_free()
|
||||
$c_modular/iw20.queue_free()
|
||||
$c_modular/iw21d.queue_free()
|
||||
$path_south.queue_free()
|
||||
if OPEN_LEFT in windows:
|
||||
wall2window($c_modular/w1)
|
||||
wall2window($c_modular/w2d)
|
||||
wall2window($c_modular/w3)
|
||||
if OPEN_DOWN in windows:
|
||||
wall2window($c_modular/s1)
|
||||
wall2window($c_modular/s2d)
|
||||
wall2window($c_modular/s3)
|
||||
if OPEN_RIGHT in windows:
|
||||
wall2window($c_modular/e1)
|
||||
wall2window($c_modular/e2d)
|
||||
wall2window($c_modular/e3)
|
||||
if OPEN_UP in windows:
|
||||
wall2window($c_modular/n1)
|
||||
wall2window($c_modular/n2d)
|
||||
wall2window($c_modular/n3)
|
||||
for e in [BITLEFT, BITRIGHT, BITUP, BITDOWN]:
|
||||
if bitflags & e == 0:
|
||||
for g in bitdata[e].doors:
|
||||
wall2door($c_modular.get_node(g))
|
||||
for g in bitdata[e].path_remove:
|
||||
get_node(g).queue_free()
|
||||
for g in bitdata[e].nodes_remove:
|
||||
$c_modular.get_node(g).queue_free()
|
||||
var external = {
|
||||
OPEN_LEFT: ["w1", "w2d", "w3"],
|
||||
OPEN_DOWN: ["s1", "s2d", "s3"],
|
||||
OPEN_RIGHT: ["e1", "e2d", "e3"],
|
||||
OPEN_UP: ["n1", "n2d", "n3"]
|
||||
}
|
||||
for p in windows:
|
||||
for q in external[p]:
|
||||
var n = $c_modular.get_node(q)
|
||||
if !p in outside_doors:
|
||||
wall2window(n)
|
||||
for p in outside_doors:
|
||||
var q = external[p][1]
|
||||
var n = $c_modular.get_node(q)
|
||||
exit_door(n)
|
||||
|
||||
Reference in New Issue
Block a user