Map Manager
This commit is contained in:
parent
9235bac737
commit
3f29cce686
|
@ -0,0 +1,31 @@
|
||||||
|
extends YSort
|
||||||
|
|
||||||
|
var map = null setget _set_map
|
||||||
|
|
||||||
|
func _set_map(value):
|
||||||
|
if !value == null:
|
||||||
|
if !map == null:
|
||||||
|
map.queue_free()
|
||||||
|
yield(map, "tree_exited")
|
||||||
|
var instanced_map = _map_to_node(value)
|
||||||
|
if instanced_map != null:
|
||||||
|
add_child(instanced_map)
|
||||||
|
map = instanced_map
|
||||||
|
print("Map set!")
|
||||||
|
else:
|
||||||
|
if !map == null:
|
||||||
|
map.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
# Pass either a String, a PackedScene or a Node
|
||||||
|
# directly to certainly get a Node
|
||||||
|
func _map_to_node(node_information) -> Node:
|
||||||
|
if node_information is String:
|
||||||
|
return load(node_information).instance()
|
||||||
|
elif node_information is PackedScene:
|
||||||
|
return node_information.instance()
|
||||||
|
elif node_information is Node:
|
||||||
|
return node_information
|
||||||
|
else:
|
||||||
|
push_error("No supported format was passed for the map!")
|
||||||
|
return null
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=22 format=2]
|
[gd_scene load_steps=23 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://addons/rpgh_engine/data_management/data_manager.gd" type="Script" id=1]
|
[ext_resource path="res://addons/rpgh_engine/data_management/data_manager.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://addons/rpgh_engine/system/rpgh_engine.gd" type="Script" id=2]
|
[ext_resource path="res://addons/rpgh_engine/system/rpgh_engine.gd" type="Script" id=2]
|
||||||
|
@ -9,6 +9,7 @@
|
||||||
[ext_resource path="res://game/maps/hobby_room_corrupted/ako_shocked.png" type="Texture" id=7]
|
[ext_resource path="res://game/maps/hobby_room_corrupted/ako_shocked.png" type="Texture" id=7]
|
||||||
[ext_resource path="res://addons/rpgh_engine/ui/dialog.gd" type="Script" id=8]
|
[ext_resource path="res://addons/rpgh_engine/ui/dialog.gd" type="Script" id=8]
|
||||||
[ext_resource path="res://addons/rpgh_engine/ui/pause.gd" type="Script" id=9]
|
[ext_resource path="res://addons/rpgh_engine/ui/pause.gd" type="Script" id=9]
|
||||||
|
[ext_resource path="res://addons/rpgh_engine/ingame/map_manager/map_manager.gd" type="Script" id=10]
|
||||||
|
|
||||||
[sub_resource type="ViewportTexture" id=1]
|
[sub_resource type="ViewportTexture" id=1]
|
||||||
flags = 4
|
flags = 4
|
||||||
|
@ -353,14 +354,15 @@ render_target_v_flip = true
|
||||||
position = Vector2( 16, 456 )
|
position = Vector2( 16, 456 )
|
||||||
z_index = -1
|
z_index = -1
|
||||||
|
|
||||||
[node name="MapContainer" type="YSort" parent="Ingame/Viewport"]
|
[node name="MapManager" type="YSort" parent="Ingame/Viewport"]
|
||||||
|
script = ExtResource( 10 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_editor_description_": "Test"
|
"_editor_description_": "Test"
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Player" parent="Ingame/Viewport/MapContainer" instance=ExtResource( 4 )]
|
[node name="Player" parent="Ingame/Viewport/MapManager" instance=ExtResource( 4 )]
|
||||||
|
|
||||||
[node name="Camera" type="Camera2D" parent="Ingame/Viewport/MapContainer"]
|
[node name="Camera" type="Camera2D" parent="Ingame/Viewport/MapManager"]
|
||||||
current = true
|
current = true
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,4 @@ extends Node
|
||||||
export(String, FILE, "*.tscn") var initial_map
|
export(String, FILE, "*.tscn") var initial_map
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
RPGH.map = initial_map
|
RPGH.MapManager.map = initial_map
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://addons/rpgh_engine/system/init.gd" type="Script" id=1]
|
[ext_resource path="res://addons/rpgh_engine/system/init.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[node name="Init" type="Node"]
|
[node name="Init" type="Node"]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
|
@ -2,39 +2,12 @@ extends Node
|
||||||
|
|
||||||
const DEFAULT_SCREEN_SIZE = Vector2(640, 360)
|
const DEFAULT_SCREEN_SIZE = Vector2(640, 360)
|
||||||
|
|
||||||
var map = null setget set_map
|
|
||||||
var global_data := {}
|
var global_data := {}
|
||||||
|
|
||||||
onready var DataManager = get_node("DataManager")
|
onready var DataManager = get_node("DataManager")
|
||||||
onready var MapContainer = get_node("Ingame/Viewport/MapContainer")
|
onready var MapManager = get_node("Ingame/Viewport/MapManager")
|
||||||
onready var Player = get_node("Ingame/Viewport/MapContainer/Player")
|
onready var Player = get_node("Ingame/Viewport/MapManager/Player")
|
||||||
onready var Camera = get_node("Ingame/Viewport/MapContainer/Camera")
|
onready var Camera = get_node("Ingame/Viewport/MapManager/Camera")
|
||||||
onready var Dialog = get_node("UI/Dialog")
|
onready var Dialog = get_node("UI/Dialog")
|
||||||
|
|
||||||
func set_map(value):
|
|
||||||
if !value == null:
|
|
||||||
if !map == null:
|
|
||||||
map.queue_free()
|
|
||||||
yield(map, "tree_exited")
|
|
||||||
var instanced_map = _map_to_node(value)
|
|
||||||
if instanced_map != null:
|
|
||||||
MapContainer.add_child(instanced_map)
|
|
||||||
map = instanced_map
|
|
||||||
print("Map set!")
|
|
||||||
else:
|
|
||||||
if !map == null:
|
|
||||||
map.queue_free()
|
|
||||||
|
|
||||||
|
|
||||||
# Pass either a String, a PackedScene or a Node
|
|
||||||
# directly to certainly get a Node
|
|
||||||
func _map_to_node(node_information) -> Node:
|
|
||||||
if node_information is String:
|
|
||||||
return load(node_information).instance()
|
|
||||||
elif node_information is PackedScene:
|
|
||||||
return node_information.instance()
|
|
||||||
elif node_information is Node:
|
|
||||||
return node_information
|
|
||||||
else:
|
|
||||||
push_error("No supported format was passed for the map!")
|
|
||||||
return null
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user