proto3 initial commit
This commit is contained in:
288
proto3/godot/scenes/maps/interior2.gd
Normal file
288
proto3/godot/scenes/maps/interior2.gd
Normal file
@@ -0,0 +1,288 @@
|
||||
extends Spatial
|
||||
|
||||
enum {OPEN_UP, OPEN_DOWN, OPEN_LEFT, OPEN_RIGHT}
|
||||
|
||||
var bitflags = 0
|
||||
const BITUP = (1 << 0)
|
||||
const BITDOWN = (1 << 1)
|
||||
const BITLEFT = (1 << 2)
|
||||
const BITRIGHT = (1 << 3)
|
||||
var exits = []
|
||||
var windows = []
|
||||
|
||||
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_placed = false
|
||||
var tw2d
|
||||
var te2d
|
||||
var tn2d
|
||||
var ts2d
|
||||
|
||||
var furniture_data = {}
|
||||
var save_data = {
|
||||
"personal_room": false,
|
||||
"kitchen_room": false,
|
||||
"master_room": false,
|
||||
"edit_room": false,
|
||||
"jail_room": false,
|
||||
"remove_iws": false,
|
||||
'stairs': -1
|
||||
}
|
||||
|
||||
func v2s(v: Vector3):
|
||||
return str(v.x) + " " + str(v.y) + " " + str(v.z)
|
||||
func xform2s(xform: Transform):
|
||||
var v1 = xform.origin
|
||||
var v2 = xform.basis[0]
|
||||
var v3 = xform.basis[1]
|
||||
var v4 = xform.basis[2]
|
||||
var ret = ""
|
||||
for v in [v1, v2, v3, v4]:
|
||||
ret += v2s(v)
|
||||
if v != v4:
|
||||
ret += " "
|
||||
return ret
|
||||
func s2xform(s: String):
|
||||
var vs = s.split(" ")
|
||||
var fvs = []
|
||||
for v in vs:
|
||||
fvs.push_back(float(v))
|
||||
var ret: = Transform()
|
||||
ret.origin = Vector3(fvs[0], fvs[1], fvs[2])
|
||||
ret.basis[0] = Vector3(fvs[3], fvs[4], fvs[5])
|
||||
ret.basis[1] = Vector3(fvs[6], fvs[7], fvs[8])
|
||||
ret.basis[2] = Vector3(fvs[9], fvs[10], fvs[11])
|
||||
return ret
|
||||
|
||||
func save_furniture():
|
||||
for k in get_children():
|
||||
var save_data = []
|
||||
for e in ["fc", "fwb"]:
|
||||
if k.name.begins_with(e):
|
||||
for l in k.get_children():
|
||||
if l.has_meta("save_path"):
|
||||
save_data.push_back({"path": l.get_meta("save_path"), "xform": xform2s(l.transform)})
|
||||
furniture_data[k.name] = save_data
|
||||
func save():
|
||||
save_data.exits = exits
|
||||
save_data.windows = windows
|
||||
if has_meta("master_room"):
|
||||
save_data.master_room = true
|
||||
if has_meta("kitchen_room"):
|
||||
save_data.kitchen_room = true
|
||||
if has_meta("jail_room"):
|
||||
save_data.jail_room = true
|
||||
if has_meta("exit_room"):
|
||||
save_data.exit_room = true
|
||||
if has_meta("stairs"):
|
||||
save_data.stairs = get_meta("stairs")
|
||||
save_furniture()
|
||||
save_data.furniture = furniture_data
|
||||
var spawns = {}
|
||||
for k in get_children():
|
||||
var e: Spatial = k
|
||||
if e.is_in_group("spawn"):
|
||||
var stats = []
|
||||
if e.has_meta("stats"):
|
||||
stats = e.get_meta("stats")
|
||||
spawns[e.name] = {"groups": e.get_groups(), "xform": xform2s(e.transform), "stats": stats}
|
||||
save_data.spawns = spawns
|
||||
|
||||
func restore_furniture():
|
||||
for k in furniture_data.keys():
|
||||
var ch = get_node(k)
|
||||
for d in furniture_data[k]:
|
||||
var f = load(d.path).instance()
|
||||
ch.add_child(f)
|
||||
f.transform = s2xform(d.xform)
|
||||
func restore():
|
||||
for k in save_data.exits:
|
||||
open_path(k)
|
||||
for k in save_data.windows:
|
||||
open_window(k)
|
||||
if save_data.master_room:
|
||||
set_meta("master_room", true)
|
||||
if save_data.kitchen_room:
|
||||
set_meta("kitchen_room", true)
|
||||
if save_data.jail_room:
|
||||
set_meta("jail_room", true)
|
||||
if save_data.stairs >= 0:
|
||||
set_meta("stairs", save_data.stairs)
|
||||
create_rooms()
|
||||
furniture_data = save_data.furniture
|
||||
restore_furniture()
|
||||
var spawns = save_data.spawns
|
||||
for k in spawns.keys():
|
||||
var e = Spatial.new()
|
||||
for g in spawns[k].groups:
|
||||
e.add_to_group(g)
|
||||
e.transform = s2xform(spawns[k].xform)
|
||||
add_child(e)
|
||||
e.name = k
|
||||
func _ready():
|
||||
tw2d = $c_modular/w2d.transform
|
||||
te2d = $c_modular/e2d.transform
|
||||
tn2d = $c_modular/n2d.transform
|
||||
ts2d = $c_modular/s2d.transform
|
||||
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()
|
||||
exits.push_back(flag)
|
||||
func open_window(flag):
|
||||
if !flag in windows:
|
||||
windows.push_back(flag)
|
||||
func remove_iws():
|
||||
for k in $c_modular.get_children():
|
||||
if k.name.begins_with("iw"):
|
||||
k.queue_free()
|
||||
save_data.remove_iws = true
|
||||
func personal_room():
|
||||
var door_xform
|
||||
remove_iws()
|
||||
assert(exits.size() == 1)
|
||||
match(int(exits[0])):
|
||||
OPEN_UP:
|
||||
door_xform = tn2d
|
||||
OPEN_DOWN:
|
||||
door_xform = ts2d
|
||||
OPEN_LEFT:
|
||||
door_xform = tw2d
|
||||
OPEN_RIGHT:
|
||||
door_xform = te2d
|
||||
_:
|
||||
print(exits)
|
||||
assert(false)
|
||||
var door_i = door.instance()
|
||||
add_child(door_i)
|
||||
door_i.transform = door_xform
|
||||
save_data.personal_room = true
|
||||
func master_room():
|
||||
remove_iws()
|
||||
for k in exits:
|
||||
var door_xform: Transform
|
||||
match(int(k)):
|
||||
OPEN_UP:
|
||||
door_xform = tn2d
|
||||
OPEN_DOWN:
|
||||
door_xform = ts2d
|
||||
OPEN_LEFT:
|
||||
door_xform = tw2d
|
||||
OPEN_RIGHT:
|
||||
door_xform = te2d
|
||||
_:
|
||||
print(exits)
|
||||
assert(false)
|
||||
var door_i = door.instance()
|
||||
add_child(door_i)
|
||||
door_i.transform = door_xform
|
||||
func wall2door(n):
|
||||
var door_xform = n.transform
|
||||
var door_i
|
||||
if has_meta("jail_room"):
|
||||
door_i = jail_door.instance()
|
||||
else:
|
||||
door_i = door.instance()
|
||||
add_child(door_i)
|
||||
door_i.transform = door_xform
|
||||
n.queue_free()
|
||||
func wall2window(n):
|
||||
var window_xform = n.transform
|
||||
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:
|
||||
window_i = outside_door.instance()
|
||||
outside_door_placed = true
|
||||
else:
|
||||
window_i = window.instance()
|
||||
add_child(window_i)
|
||||
window_i.transform = window_xform
|
||||
n.queue_free()
|
||||
func create_rooms():
|
||||
if has_meta("master_room"):
|
||||
master_room()
|
||||
elif has_meta("kitchen_room"):
|
||||
master_room()
|
||||
elif has_meta("stairs"):
|
||||
master_room()
|
||||
if get_meta("stairs") > 0:
|
||||
$c_modular/floor.queue_free()
|
||||
elif exits.size() == 1:
|
||||
personal_room()
|
||||
elif exits.size() == 4:
|
||||
wall2door($c_modular/iw2d)
|
||||
wall2door($c_modular/iw6d)
|
||||
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)
|
||||
Reference in New Issue
Block a user