develop #16
@ -3,6 +3,6 @@ config_version=3
|
|||||||
|
|
||||||
name="Tiled Map Importer"
|
name="Tiled Map Importer"
|
||||||
description="Importer for TileMaps and TileSets made on Tiled Map Editor"
|
description="Importer for TileMaps and TileSets made on Tiled Map Editor"
|
||||||
version="2.3"
|
version="2.4"
|
||||||
author="George Marques"
|
author="George Marques"
|
||||||
script="vnen.tiled_importer.gd"
|
script="vnen.tiled_importer.gd"
|
||||||
|
@ -46,7 +46,7 @@ func get_priority():
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
func get_import_order():
|
func get_import_order():
|
||||||
return 100
|
return 101
|
||||||
|
|
||||||
func get_resource_type():
|
func get_resource_type():
|
||||||
return "PackedScene"
|
return "PackedScene"
|
||||||
@ -73,6 +73,10 @@ func get_import_options(preset):
|
|||||||
"name": "uv_clip",
|
"name": "uv_clip",
|
||||||
"default_value": true
|
"default_value": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "y_sort",
|
||||||
|
"default_value": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "image_flags",
|
"name": "image_flags",
|
||||||
"default_value": 0 if preset == PRESET_PIXEL_ART else Texture.FLAGS_DEFAULT,
|
"default_value": 0 if preset == PRESET_PIXEL_ART else Texture.FLAGS_DEFAULT,
|
||||||
@ -115,8 +119,6 @@ func get_option_visibility(option, options):
|
|||||||
func import(source_file, save_path, options, r_platform_variants, r_gen_files):
|
func import(source_file, save_path, options, r_platform_variants, r_gen_files):
|
||||||
var map_reader = TiledMapReader.new()
|
var map_reader = TiledMapReader.new()
|
||||||
|
|
||||||
# Offset is only optional for importing TileSets
|
|
||||||
options.apply_offset = true
|
|
||||||
var scene = map_reader.build(source_file, options)
|
var scene = map_reader.build(source_file, options)
|
||||||
|
|
||||||
if typeof(scene) != TYPE_OBJECT:
|
if typeof(scene) != TYPE_OBJECT:
|
||||||
|
@ -50,6 +50,8 @@ const whitelist_properties = [
|
|||||||
"infinite",
|
"infinite",
|
||||||
"margin",
|
"margin",
|
||||||
"name",
|
"name",
|
||||||
|
"offsetx",
|
||||||
|
"offsety",
|
||||||
"orientation",
|
"orientation",
|
||||||
"probability",
|
"probability",
|
||||||
"spacing",
|
"spacing",
|
||||||
@ -228,8 +230,7 @@ func make_layer(layer, parent, root, data):
|
|||||||
tilemap.cell_half_offset = map_offset
|
tilemap.cell_half_offset = map_offset
|
||||||
tilemap.format = 1
|
tilemap.format = 1
|
||||||
tilemap.cell_clip_uv = options.uv_clip
|
tilemap.cell_clip_uv = options.uv_clip
|
||||||
tilemap.cell_y_sort = true
|
tilemap.cell_y_sort = options.y_sort
|
||||||
tilemap.cell_tile_origin = TileMap.TILE_ORIGIN_BOTTOM_LEFT
|
|
||||||
tilemap.collision_layer = options.collision_layer
|
tilemap.collision_layer = options.collision_layer
|
||||||
tilemap.collision_mask = options.collision_mask
|
tilemap.collision_mask = options.collision_mask
|
||||||
tilemap.z_index = z_index
|
tilemap.z_index = z_index
|
||||||
@ -281,7 +282,7 @@ func make_layer(layer, parent, root, data):
|
|||||||
var gid = int_id & ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG | FLIPPED_DIAGONALLY_FLAG)
|
var gid = int_id & ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG | FLIPPED_DIAGONALLY_FLAG)
|
||||||
|
|
||||||
var cell_x = cell_offset.x + chunk.x + (count % int(chunk.width))
|
var cell_x = cell_offset.x + chunk.x + (count % int(chunk.width))
|
||||||
var cell_y = cell_offset.y + chunk.y + int(count / chunk.width) + 1
|
var cell_y = cell_offset.y + chunk.y + int(count / chunk.width)
|
||||||
tilemap.set_cell(cell_x, cell_y, gid, flipped_h, flipped_v, flipped_d)
|
tilemap.set_cell(cell_x, cell_y, gid, flipped_h, flipped_v, flipped_d)
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
@ -694,7 +695,13 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
imagesize = Vector2(int(ts.imagewidth), int(ts.imageheight))
|
imagesize = Vector2(int(ts.imagewidth), int(ts.imageheight))
|
||||||
|
|
||||||
var tilesize = Vector2(int(ts.tilewidth), int(ts.tileheight))
|
var tilesize = Vector2(int(ts.tilewidth), int(ts.tileheight))
|
||||||
var tilecount = int(ts.tilecount)
|
|
||||||
|
var tilecount
|
||||||
|
if not "tilecount" in ts:
|
||||||
|
tilecount = make_tilecount(tilesize, imagesize, margin, spacing)
|
||||||
|
else:
|
||||||
|
tilecount = int(ts.tilecount)
|
||||||
|
|
||||||
|
|
||||||
var gid = firstgid
|
var gid = firstgid
|
||||||
|
|
||||||
@ -704,6 +711,7 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
var i = 0
|
var i = 0
|
||||||
var column = 0
|
var column = 0
|
||||||
|
|
||||||
|
|
||||||
# Needed to look up textures for animations
|
# Needed to look up textures for animations
|
||||||
var tileRegions = []
|
var tileRegions = []
|
||||||
while i < tilecount:
|
while i < tilecount:
|
||||||
@ -751,8 +759,6 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
else:
|
else:
|
||||||
result.tile_set_texture(gid, image)
|
result.tile_set_texture(gid, image)
|
||||||
result.tile_set_region(gid, region)
|
result.tile_set_region(gid, region)
|
||||||
if options.apply_offset:
|
|
||||||
result.tile_set_texture_offset(gid, Vector2(0, -tilesize.y))
|
|
||||||
elif not rel_id in ts.tiles:
|
elif not rel_id in ts.tiles:
|
||||||
gid += 1
|
gid += 1
|
||||||
continue
|
continue
|
||||||
@ -777,8 +783,6 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
# Error happened
|
# Error happened
|
||||||
return image
|
return image
|
||||||
result.tile_set_texture(gid, image)
|
result.tile_set_texture(gid, image)
|
||||||
if options.apply_offset:
|
|
||||||
result.tile_set_texture_offset(gid, Vector2(0, -image.get_height()))
|
|
||||||
|
|
||||||
if "tiles" in ts and rel_id in ts.tiles and "objectgroup" in ts.tiles[rel_id] \
|
if "tiles" in ts and rel_id in ts.tiles and "objectgroup" in ts.tiles[rel_id] \
|
||||||
and "objects" in ts.tiles[rel_id].objectgroup:
|
and "objects" in ts.tiles[rel_id].objectgroup:
|
||||||
@ -791,8 +795,6 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
return shape
|
return shape
|
||||||
|
|
||||||
var offset = Vector2(float(object.x), float(object.y))
|
var offset = Vector2(float(object.x), float(object.y))
|
||||||
if options.apply_offset:
|
|
||||||
offset += result.tile_get_texture_offset(gid)
|
|
||||||
if "width" in object and "height" in object:
|
if "width" in object and "height" in object:
|
||||||
offset += Vector2(float(object.width) / 2, float(object.height) / 2)
|
offset += Vector2(float(object.width) / 2, float(object.height) / 2)
|
||||||
|
|
||||||
@ -817,6 +819,11 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
if not gid in tile_meta: tile_meta[gid] = {}
|
if not gid in tile_meta: tile_meta[gid] = {}
|
||||||
tile_meta[gid][property] = ts.tiles[rel_id][property]
|
tile_meta[gid][property] = ts.tiles[rel_id][property]
|
||||||
|
|
||||||
|
# If tile has a custom property called 'name', set the tile's name
|
||||||
|
if property == "name":
|
||||||
|
result.tile_set_name(gid, ts.tiles[rel_id].properties.name)
|
||||||
|
|
||||||
|
|
||||||
gid += 1
|
gid += 1
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
@ -875,11 +882,12 @@ func load_image(rel_path, source_path, options):
|
|||||||
|
|
||||||
var image = null
|
var image = null
|
||||||
if embed:
|
if embed:
|
||||||
|
var img = Image.new()
|
||||||
|
img.load(total_path)
|
||||||
image = ImageTexture.new()
|
image = ImageTexture.new()
|
||||||
image.load(total_path)
|
image.create_from_image(img, flags)
|
||||||
else:
|
else:
|
||||||
image = ResourceLoader.load(total_path, "ImageTexture")
|
image = ResourceLoader.load(total_path, "ImageTexture")
|
||||||
|
|
||||||
if image != null:
|
if image != null:
|
||||||
image.set_flags(flags)
|
image.set_flags(flags)
|
||||||
|
|
||||||
@ -1127,6 +1135,17 @@ func object_sorter(first, second):
|
|||||||
return first.id < second.id
|
return first.id < second.id
|
||||||
return first.y < second.y
|
return first.y < second.y
|
||||||
|
|
||||||
|
# Create the tilecount for the TileSet if not present.
|
||||||
|
# Based on the image and tile dimensions.
|
||||||
|
func make_tilecount(tilesize, imagesize, margin, spacing):
|
||||||
|
var horizontal_tile_size = int(tilesize.x + margin * 2 + spacing)
|
||||||
|
var vertical_tile_size = int(tilesize.y + margin * 2 + spacing)
|
||||||
|
|
||||||
|
var horizontal_tile_count = int(imagesize.x) / horizontal_tile_size;
|
||||||
|
var vertical_tile_count = int(imagesize.y) / vertical_tile_size;
|
||||||
|
|
||||||
|
return horizontal_tile_count * vertical_tile_count
|
||||||
|
|
||||||
# Validates the map dictionary content for missing or invalid keys
|
# Validates the map dictionary content for missing or invalid keys
|
||||||
# Returns an error code
|
# Returns an error code
|
||||||
func validate_map(map):
|
func validate_map(map):
|
||||||
@ -1169,9 +1188,6 @@ func validate_tileset(tileset):
|
|||||||
elif not "tileheight" in tileset or not str(tileset.tileheight).is_valid_integer():
|
elif not "tileheight" in tileset or not str(tileset.tileheight).is_valid_integer():
|
||||||
print_error("Missing or invalid tileheight tileset property.")
|
print_error("Missing or invalid tileheight tileset property.")
|
||||||
return ERR_INVALID_DATA
|
return ERR_INVALID_DATA
|
||||||
elif not "tilecount" in tileset or not str(tileset.tilecount).is_valid_integer():
|
|
||||||
print_error("Missing or invalid tilecount tileset property.")
|
|
||||||
return ERR_INVALID_DATA
|
|
||||||
if not "image" in tileset:
|
if not "image" in tileset:
|
||||||
for tile in tileset.tiles:
|
for tile in tileset.tiles:
|
||||||
if not "image" in tileset.tiles[tile]:
|
if not "image" in tileset.tiles[tile]:
|
||||||
|
@ -42,6 +42,9 @@ func get_recognized_extensions():
|
|||||||
func get_save_extension():
|
func get_save_extension():
|
||||||
return "res"
|
return "res"
|
||||||
|
|
||||||
|
func get_import_order():
|
||||||
|
return 100
|
||||||
|
|
||||||
func get_resource_type():
|
func get_resource_type():
|
||||||
return "TileSet"
|
return "TileSet"
|
||||||
|
|
||||||
@ -77,10 +80,6 @@ func get_import_options(preset):
|
|||||||
"name": "save_tiled_properties",
|
"name": "save_tiled_properties",
|
||||||
"default_value": false
|
"default_value": false
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "apply_offset",
|
|
||||||
"default_value": false
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "post_import_script",
|
"name": "post_import_script",
|
||||||
"default_value": "",
|
"default_value": "",
|
||||||
|
@ -14,6 +14,7 @@ dest_files=[ "res://.import/Level2.tmx-357d8ae9edfbc85f5abb1db3655640e1.scn" ]
|
|||||||
custom_properties=true
|
custom_properties=true
|
||||||
tile_metadata=false
|
tile_metadata=false
|
||||||
uv_clip=true
|
uv_clip=true
|
||||||
|
y_sort=false
|
||||||
image_flags=7
|
image_flags=7
|
||||||
collision_layer=2
|
collision_layer=2
|
||||||
collision_mask=0
|
collision_mask=0
|
||||||
|
@ -14,6 +14,7 @@ dest_files=[ "res://.import/Prototype.tmx-1674122a110386791b767b1f6628b68b.scn"
|
|||||||
custom_properties=true
|
custom_properties=true
|
||||||
tile_metadata=false
|
tile_metadata=false
|
||||||
uv_clip=true
|
uv_clip=true
|
||||||
|
y_sort=false
|
||||||
image_flags=7
|
image_flags=7
|
||||||
collision_layer=2
|
collision_layer=2
|
||||||
collision_mask=0
|
collision_mask=0
|
||||||
|
@ -90,6 +90,11 @@ right={
|
|||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Send={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ void CameraLimit::_ready()
|
|||||||
if (middle_ground != NULL)
|
if (middle_ground != NULL)
|
||||||
{
|
{
|
||||||
auto used_rect = middle_ground->get_used_rect();
|
auto used_rect = middle_ground->get_used_rect();
|
||||||
auto bounds = Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y - 1);
|
auto bounds = Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y);
|
||||||
node = get_tree()->get_root()->find_node("Camera2D", true, false);
|
node = get_tree()->get_root()->find_node("Camera2D", true, false);
|
||||||
auto camera = cast_to<Camera2D>(node);
|
auto camera = cast_to<Camera2D>(node);
|
||||||
if (camera != NULL)
|
if (camera != NULL)
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
|
|
||||||
namespace godot
|
namespace godot
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @brief This class limits the camera's position.
|
||||||
|
*
|
||||||
|
* @details The camera will be limited based on the used width and height of the Middleground tilemap.
|
||||||
|
*/
|
||||||
class CameraLimit: public Node2D
|
class CameraLimit: public Node2D
|
||||||
{
|
{
|
||||||
GODOT_CLASS(CameraLimit, Node2D)
|
GODOT_CLASS(CameraLimit, Node2D)
|
||||||
|
@ -8,11 +8,6 @@
|
|||||||
#include <SpriteFrames.hpp>
|
#include <SpriteFrames.hpp>
|
||||||
#include <ResourceLoader.hpp>
|
#include <ResourceLoader.hpp>
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This is the godot namespace for all the code included in the library.
|
|
||||||
*
|
|
||||||
* @details This namespace is used a prefix when the Godot engine looks for classes, methods, and properties.
|
|
||||||
*/
|
|
||||||
namespace godot
|
namespace godot
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -7,17 +7,12 @@
|
|||||||
#include <Input.hpp>
|
#include <Input.hpp>
|
||||||
#include <AnimatedSprite.hpp>
|
#include <AnimatedSprite.hpp>
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This is the godot namespace for all the code included in the library.
|
|
||||||
*
|
|
||||||
* @details This namespace is used a prefix when the Godot engine looks for classes, methods, and properties.
|
|
||||||
*/
|
|
||||||
namespace godot
|
namespace godot
|
||||||
{
|
{
|
||||||
namespace player
|
namespace player
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the player is in a falling state.
|
* @brief This class controls what happens when the Player is in a falling state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class PlayerFall : public State
|
class PlayerFall : public State
|
||||||
@ -32,7 +27,7 @@ namespace godot
|
|||||||
Input *_input;
|
Input *_input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite connected to the player.
|
* @brief The animated sprite connected to the Player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
AnimatedSprite *animated_sprite;
|
||||||
|
@ -13,7 +13,7 @@ namespace godot
|
|||||||
namespace player
|
namespace player
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the player is in the idle state.
|
* @brief This class controls what happens when the Player is in the idle state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class PlayerIdle : public State
|
class PlayerIdle : public State
|
||||||
@ -27,7 +27,7 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
Input *_input;
|
Input *_input;
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the player.
|
* @brief The animated sprite of the Player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
AnimatedSprite *animated_sprite;
|
||||||
|
@ -12,7 +12,7 @@ namespace godot
|
|||||||
namespace player
|
namespace player
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class control what happens when the player is in the jump state.
|
* @brief This class control what happens when the Player is in the jump state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class PlayerJump : public State
|
class PlayerJump : public State
|
||||||
@ -26,7 +26,7 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
Input *_input;
|
Input *_input;
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite connected to the player.
|
* @brief The animated sprite connected to the Player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
AnimatedSprite *animated_sprite;
|
||||||
|
@ -12,7 +12,7 @@ namespace godot
|
|||||||
namespace player
|
namespace player
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the player is in the move state.
|
* @brief This class controls what happens when the Player is in the move state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class PlayerMove : public State
|
class PlayerMove : public State
|
||||||
@ -26,7 +26,7 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
Input *_input;
|
Input *_input;
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the player.
|
* @brief The animated sprite of the Player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
AnimatedSprite *animated_sprite;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef JUEGO_STATE_H
|
#ifndef JUEGO_STATE_H
|
||||||
#define JUEGO_STATE_H
|
#define JUEGO_STATE_H
|
||||||
|
|
||||||
#include "StateMachine.h"
|
#include "state_machine/StateMachine.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <Node.hpp>
|
#include <Node.hpp>
|
||||||
|
Loading…
Reference in New Issue
Block a user