Skip to content

Commit

Permalink
Remove automatic dir pattern testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JtotheThree committed Dec 18, 2024
1 parent 505d6ad commit 427dcb8
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: cargo build --lib --verbose

- name: Run tests
run: cargo test --verbose
run: cargo test --verbose --all-features

rustfmt:
runs-on: ubuntu-24.04
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.14.0]
### Added
- Added a new crate feature `world` to enable support for parsing `World` files.

## [0.13.0]
### Added
- Added a `source` member to `Tileset`, `Map` and `Template`, which stores the resource path they have been loaded from. (#303)
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tiled"
version = "0.13.0"
version = "0.14.0"
description = "A rust crate for loading maps created by the Tiled editor"
categories = ["game-development"]
keywords = ["gamedev", "tiled", "tmx", "map"]
Expand All @@ -14,6 +14,7 @@ include = ["src/**/*.rs", "README.md", "LICENSE", "CHANGELOG.md"]
[features]
default = ["zstd"]
wasm = ["zstd/wasm"]
world = ["serde", "serde_json", "regex"]

[lib]
name = "tiled"
Expand All @@ -36,9 +37,9 @@ base64 = "0.22.1"
xml-rs = "0.8.4"
zstd = { version = "0.13.1", optional = true, default-features = false }
flate2 = "1.0.28"
serde = "1.0.215"
serde_json = "1.0.133"
regex = "1.11.1"
serde = { version = "1.0.216", optional = true }
serde_json = { version = "1.0.133", optional = true }
regex = { version = "1.11.1", optional = true }

[dev-dependencies.sfml]
version = "0.21.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let mut loader = Loader::with_reader(
// Doing this embedding is useful for places where the OS filesystem is not available (e.g. WASM applications).
|path: &std::path::Path| -> std::io::Result<_> {
if path == std::path::Path::new("/my-map.tmx") {
Ok(std::io::Cursor::new(include_bytes!("../assets/tiled_csv.tmx")))
Ok(std::io::Cursor::new(include_bytes!("assets/tiled_csv.tmx")))
} else {
Err(std::io::ErrorKind::NotFound.into())
}
Expand Down Expand Up @@ -86,7 +86,7 @@ impl tiled::ResourceReader for MyReader {
// really dumb example implementation that just keeps resources in memory
fn read_from(&mut self, path: &std::path::Path) -> std::result::Result<Self::Resource, Self::Error> {
if path == std::path::Path::new("my_map.tmx") {
Ok(Cursor::new(include_bytes!("../assets/tiled_xml.tmx")))
Ok(Cursor::new(include_bytes!("assets/tiled_xml.tmx")))
} else {
Err(std::io::Error::new(std::io::ErrorKind::NotFound, "file not found"))
}
Expand Down
1 change: 0 additions & 1 deletion assets/world/map-x00-y00-empty.tmx

This file was deleted.

1 change: 0 additions & 1 deletion assets/world/map-x01-y01-empty.tmx

This file was deleted.

14 changes: 14 additions & 0 deletions assets/world/world_pattern.world
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
"multiplierY": 480,
"offsetX": 240,
"offsetY": -240
},
{
"regexp": "overworld-x0*(\\d+)-y0*(\\d+).tmx",
"multiplierX": 640,
"multiplierY": 480,
"offsetX": 4192,
"offsetY": 4192
},
{
"regexp": "OVERFLOW-x0*(\\d+)-y0*(\\d+).tmx",
"multiplierX": 50000000,
"multiplierY": 50000000,
"offsetX": 4192,
"offsetY": 4192
}
],
"type": "world"
Expand Down
12 changes: 0 additions & 12 deletions assets/world/world_pattern_bad.world

This file was deleted.

7 changes: 7 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ pub enum Error {
CsvDecodingError(CsvDecodingError),
/// An error occurred when parsing an XML file, such as a TMX or TSX file.
XmlDecodingError(xml::reader::Error),
#[cfg(feature = "world")]
/// An error occurred when attempting to deserialize a JSON file.
JsonDecodingError(serde_json::Error),
#[cfg(feature = "world")]
/// No regex captures were found.
CapturesNotFound,
/// The XML stream ended before the document was fully parsed.
PrematureEnd(String),
/// The path given is invalid because it isn't contained in any folder.
Expand Down Expand Up @@ -122,7 +126,10 @@ impl fmt::Display for Error {
Error::Base64DecodingError(e) => write!(fmt, "{}", e),
Error::CsvDecodingError(e) => write!(fmt, "{}", e),
Error::XmlDecodingError(e) => write!(fmt, "{}", e),
#[cfg(feature = "world")]
Error::JsonDecodingError(e) => write!(fmt, "{}", e),
#[cfg(feature = "world")]
Error::CapturesNotFound => write!(fmt, "No captures found in pattern"),
Error::PrematureEnd(e) => write!(fmt, "{}", e),
Error::PathIsNotFile => {
write!(
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod template;
mod tile;
mod tileset;
mod util;
#[cfg(feature = "world")]
mod world;

pub use animation::*;
Expand All @@ -35,4 +36,5 @@ pub use reader::*;
pub use template::*;
pub use tile::*;
pub use tileset::*;
#[cfg(feature = "world")]
pub use world::*;
11 changes: 8 additions & 3 deletions src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::path::Path;

use crate::{
DefaultResourceCache, FilesystemResourceReader, Map, ResourceCache, ResourceReader, Result, Tileset, World
DefaultResourceCache, FilesystemResourceReader, Map, ResourceCache, ResourceReader, Result, Tileset
};

#[cfg(feature = "world")]
use crate::World;

/// A type used for loading [`Map`]s and [`Tileset`]s.
///
/// Internally, it holds a [`ResourceCache`] that, as its name implies, caches intermediate loading
Expand Down Expand Up @@ -181,9 +184,11 @@ impl<Cache: ResourceCache, Reader: ResourceReader> Loader<Cache, Reader> {
crate::parse::xml::parse_tileset(path.as_ref(), &mut self.reader, &mut self.cache)
}

/// Parses a file hopefully containing a Tiled world and tries to parse it.
/// Parses a file hopefully containing a Tiled world and tries to parse it. All external files
/// will be loaded relative to the path given.
#[cfg(feature = "world")]
pub fn load_world(&mut self, path: impl AsRef<Path>) -> Result<World> {
crate::world::parse_world(path.as_ref(), &mut self.reader, &mut self.cache)
crate::world::parse_world(path.as_ref(), &mut self.reader)
}

/// Returns a reference to the loader's internal [`ResourceCache`].
Expand Down
Loading

0 comments on commit 427dcb8

Please sign in to comment.