You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
-renamed function to get object from instance id
-added function to get list of tiles used
This commit is contained in:
@@ -3,6 +3,21 @@ extends Node
|
|||||||
|
|
||||||
var current_scene = null
|
var current_scene = null
|
||||||
|
|
||||||
|
|
||||||
|
func goto_scene(path):
|
||||||
|
|
||||||
|
# This function will usually be called from a signal callback,
|
||||||
|
# or some other function from the running scene.
|
||||||
|
# Deleting the current scene at this point might be
|
||||||
|
# a bad idea, because it may be inside of a callback or function of it.
|
||||||
|
# The worst case will be a crash or unexpected behavior.
|
||||||
|
|
||||||
|
# The way around this is deferring the load to a later time, when
|
||||||
|
# it is ensured that no code from the current scene is running:
|
||||||
|
|
||||||
|
call_deferred("_deferred_goto_scene",path)
|
||||||
|
|
||||||
|
|
||||||
func _deferred_goto_scene(path):
|
func _deferred_goto_scene(path):
|
||||||
|
|
||||||
# Immediately free the current scene,
|
# Immediately free the current scene,
|
||||||
@@ -18,19 +33,6 @@ func _deferred_goto_scene(path):
|
|||||||
# Add it to the active scene, as child of root
|
# Add it to the active scene, as child of root
|
||||||
get_tree().get_root().add_child(current_scene)
|
get_tree().get_root().add_child(current_scene)
|
||||||
|
|
||||||
func goto_scene(path):
|
|
||||||
|
|
||||||
# This function will usually be called from a signal callback,
|
|
||||||
# or some other function from the running scene.
|
|
||||||
# Deleting the current scene at this point might be
|
|
||||||
# a bad idea, because it may be inside of a callback or function of it.
|
|
||||||
# The worst case will be a crash or unexpected behavior.
|
|
||||||
|
|
||||||
# The way around this is deferring the load to a later time, when
|
|
||||||
# it is ensured that no code from the current scene is running:
|
|
||||||
|
|
||||||
call_deferred("_deferred_goto_scene",path)
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Get the current scene, the first time.
|
# Get the current scene, the first time.
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ const char *GDFunctions::get_func_name(Function p_func) {
|
|||||||
"dict2inst",
|
"dict2inst",
|
||||||
"hash",
|
"hash",
|
||||||
"print_stack",
|
"print_stack",
|
||||||
"get_inst",
|
"instance_from_id",
|
||||||
};
|
};
|
||||||
|
|
||||||
return _names[p_func];
|
return _names[p_func];
|
||||||
@@ -904,7 +904,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
|
|||||||
};
|
};
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GET_INST: {
|
case INSTANCE_FROM_ID: {
|
||||||
|
|
||||||
VALIDATE_ARG_COUNT(1);
|
VALIDATE_ARG_COUNT(1);
|
||||||
if (p_args[0]->get_type()!=Variant::INT && p_args[0]->get_type()!=Variant::REAL) {
|
if (p_args[0]->get_type()!=Variant::INT && p_args[0]->get_type()!=Variant::REAL) {
|
||||||
@@ -1316,8 +1316,8 @@ MethodInfo GDFunctions::get_info(Function p_func) {
|
|||||||
return mi;
|
return mi;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GET_INST: {
|
case INSTANCE_FROM_ID: {
|
||||||
MethodInfo mi("get_info",PropertyInfo(Variant::INT,"instance_id"));
|
MethodInfo mi("instance_from_id",PropertyInfo(Variant::INT,"instance_id"));
|
||||||
mi.return_val.type=Variant::OBJECT;
|
mi.return_val.type=Variant::OBJECT;
|
||||||
return mi;
|
return mi;
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public:
|
|||||||
DICT2INST,
|
DICT2INST,
|
||||||
HASH,
|
HASH,
|
||||||
PRINT_STACK,
|
PRINT_STACK,
|
||||||
GET_INST,
|
INSTANCE_FROM_ID,
|
||||||
FUNC_MAX
|
FUNC_MAX
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1024,6 +1024,19 @@ bool TileMap::is_y_sort_mode_enabled() const {
|
|||||||
return y_sort_mode;
|
return y_sort_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array TileMap::get_used_cells() const {
|
||||||
|
|
||||||
|
Array a;
|
||||||
|
a.resize(tile_map.size());
|
||||||
|
int i=0;
|
||||||
|
for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
|
||||||
|
|
||||||
|
Vector2 p (E->key().x,E->key().y);
|
||||||
|
a[i++]=p;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
void TileMap::_bind_methods() {
|
void TileMap::_bind_methods() {
|
||||||
|
|
||||||
@@ -1080,6 +1093,8 @@ void TileMap::_bind_methods() {
|
|||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("clear"),&TileMap::clear);
|
ObjectTypeDB::bind_method(_MD("clear"),&TileMap::clear);
|
||||||
|
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_used_cells"),&TileMap::get_used_cells);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("map_to_world","mappos","ignore_half_ofs"),&TileMap::map_to_world,DEFVAL(false));
|
ObjectTypeDB::bind_method(_MD("map_to_world","mappos","ignore_half_ofs"),&TileMap::map_to_world,DEFVAL(false));
|
||||||
ObjectTypeDB::bind_method(_MD("world_to_map","worldpos"),&TileMap::world_to_map);
|
ObjectTypeDB::bind_method(_MD("world_to_map","worldpos"),&TileMap::world_to_map);
|
||||||
|
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ private:
|
|||||||
|
|
||||||
_FORCE_INLINE_ Vector2 _map_to_world(int p_x,int p_y,bool p_ignore_ofs=false) const;
|
_FORCE_INLINE_ Vector2 _map_to_world(int p_x,int p_y,bool p_ignore_ofs=false) const;
|
||||||
|
|
||||||
|
Array get_used_cells() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user