Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
rs-tiled
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
rs-tiled
Commits
0895c585
Commit
0895c585
authored
8 years ago
by
Matthew Hall
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #27 from guodman/master
Load in properties from the tiles
parents
2ec9c563
d0bfbfb8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib.rs
+13
-7
13 additions, 7 deletions
src/lib.rs
tests/lib.rs
+12
-1
12 additions, 1 deletion
tests/lib.rs
with
25 additions
and
8 deletions
src/lib.rs
+
13
−
7
View file @
0895c585
...
@@ -307,7 +307,7 @@ impl FromStr for Orientation {
...
@@ -307,7 +307,7 @@ impl FromStr for Orientation {
}
}
/// A tileset, usually the tilesheet image.
/// A tileset, usually the tilesheet image.
#[derive(Debug,
PartialEq
,
Eq
)]
#[derive(Debug,
PartialEq)]
pub
struct
Tileset
{
pub
struct
Tileset
{
/// The GID of the first tile stored
/// The GID of the first tile stored
pub
first_gid
:
u32
,
pub
first_gid
:
u32
,
...
@@ -420,10 +420,11 @@ impl Tileset {
...
@@ -420,10 +420,11 @@ impl Tileset {
}
}
}
}
#[derive(Debug,
PartialEq
,
Eq
)]
#[derive(Debug,
PartialEq)]
pub
struct
Tile
{
pub
struct
Tile
{
pub
id
:
u32
,
pub
id
:
u32
,
pub
images
:
Vec
<
Image
>
pub
images
:
Vec
<
Image
>
,
pub
properties
:
Properties
,
}
}
impl
Tile
{
impl
Tile
{
...
@@ -435,12 +436,17 @@ impl Tile {
...
@@ -435,12 +436,17 @@ impl Tile {
TiledError
::
MalformedAttributes
(
"tile must have an id with the correct type"
.to_string
()));
TiledError
::
MalformedAttributes
(
"tile must have an id with the correct type"
.to_string
()));
let
mut
images
=
Vec
::
new
();
let
mut
images
=
Vec
::
new
();
let
mut
properties
=
HashMap
::
new
();
parse_tag!
(
parser
,
"tile"
,
parse_tag!
(
parser
,
"tile"
,
"image"
=>
|
attrs
|
{
"image"
=>
|
attrs
|
{
images
.push
(
try!
(
Image
::
new
(
parser
,
attrs
)));
images
.push
(
Image
::
new
(
parser
,
attrs
)
?
);
Ok
(())
Ok
(())
});
},
Ok
(
Tile
{
id
:
i
,
images
:
images
})
"properties"
=>
|
_
|
{
properties
=
parse_properties
(
parser
)
?
;
Ok
(())
});
Ok
(
Tile
{
id
:
i
,
images
:
images
,
properties
:
properties
})
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/lib.rs
+
12
−
1
View file @
0895c585
...
@@ -2,7 +2,7 @@ extern crate tiled;
...
@@ -2,7 +2,7 @@ extern crate tiled;
use
std
::
path
::
Path
;
use
std
::
path
::
Path
;
use
std
::
fs
::
File
;
use
std
::
fs
::
File
;
use
tiled
::{
Map
,
TiledError
,
parse
,
parse_file
,
parse_tileset
};
use
tiled
::{
Map
,
TiledError
,
PropertyValue
,
parse
,
parse_file
,
parse_tileset
};
fn
read_from_file
(
p
:
&
Path
)
->
Result
<
Map
,
TiledError
>
{
fn
read_from_file
(
p
:
&
Path
)
->
Result
<
Map
,
TiledError
>
{
let
file
=
File
::
open
(
p
)
.unwrap
();
let
file
=
File
::
open
(
p
)
.unwrap
();
...
@@ -37,3 +37,14 @@ fn test_just_tileset() {
...
@@ -37,3 +37,14 @@ fn test_just_tileset() {
let
t
=
parse_tileset
(
File
::
open
(
Path
::
new
(
"assets/tilesheet.tsx"
))
.unwrap
(),
1
)
.unwrap
();
let
t
=
parse_tileset
(
File
::
open
(
Path
::
new
(
"assets/tilesheet.tsx"
))
.unwrap
(),
1
)
.unwrap
();
assert_eq!
(
r
.tilesets
[
0
],
t
);
assert_eq!
(
r
.tilesets
[
0
],
t
);
}
}
#[test]
fn
test_tile_property
()
{
let
r
=
read_from_file
(
&
Path
::
new
(
"assets/tiled_base64.tmx"
))
.unwrap
();
let
prop_value
:
String
=
if
let
Some
(
&
PropertyValue
::
StringValue
(
ref
v
))
=
r
.tilesets
[
0
]
.tiles
[
0
]
.properties
.get
(
"a tile property"
)
{
v
.clone
()
}
else
{
String
::
new
()
};
assert_eq!
(
"123"
,
prop_value
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment