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
34c85200
Commit
34c85200
authored
10 years ago
by
Matthew Hall
Browse files
Options
Downloads
Patches
Plain Diff
Add properties to map and layer
parent
1ec10358
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
assets/tiled_base64_zlib.tmx
+9
-0
9 additions, 0 deletions
assets/tiled_base64_zlib.tmx
src/lib.rs
+37
-4
37 additions, 4 deletions
src/lib.rs
with
46 additions
and
4 deletions
assets/tiled_base64_zlib.tmx
+
9
−
0
View file @
34c85200
...
...
@@ -2,8 +2,17 @@
<map
version=
"1.0"
orientation=
"orthogonal"
width=
"100"
height=
"100"
tilewidth=
"32"
tileheight=
"32"
>
<tileset
firstgid=
"1"
name=
"tilesheet"
tilewidth=
"32"
tileheight=
"32"
>
<image
source=
"tilesheet.png"
width=
"448"
height=
"192"
/>
<tile
id=
"1"
>
<properties>
<property
name=
"a tile property"
value=
"123"
/>
</properties>
</tile>
</tileset>
<layer
name=
"Tile Layer 1"
width=
"100"
height=
"100"
>
<properties>
<property
name=
"prop1"
value=
"12"
/>
<property
name=
"prop2"
value=
"some text"
/>
</properties>
<data
encoding=
"base64"
compression=
"zlib"
>
eJzt1zEKwzAMBVBdIScIJXPS+9+uDY1BuHbpULvLeyDIkEkfIXmLiK2qW6cYb7lqv+p41r1TcpmjZFLPyamVEXOcGSzpu66SixkZb41Xz9dO7fE+O4yR+703KmdyhExGK32v+1zv+rxLZDJO7vO5G3KvSyY1eYxT31Dlrm3t9AhZzNC6a+v3RsmhNzP83qdc8ttdHuO07thWLlt4E87w7S6wM+bo7e3ef8z1KRt5/N+388N88gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIHsArPIXTA==
</data>
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
37
−
4
View file @
34c85200
...
...
@@ -5,6 +5,7 @@ extern crate serialize;
use
std
::
io
::{
BufReader
,
IoError
,
EndOfFile
};
use
std
::
from_str
::
FromStr
;
use
std
::
collections
::
HashMap
;
use
xml
::
reader
::
EventReader
;
use
xml
::
common
::
Attribute
;
use
xml
::
reader
::
events
::
*
;
...
...
@@ -57,6 +58,24 @@ macro_rules! parse_tag {
}
}
pub
type
Properties
=
HashMap
<
String
,
String
>
;
fn
parse_properties
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
)
->
Result
<
Properties
,
String
>
{
let
mut
p
=
HashMap
::
new
();
parse_tag!
(
parser
,
"properties"
,
"property"
=>
|
attrs
:
Vec
<
Attribute
>
|
{
let
((),
(
k
,
v
))
=
get_attrs!
(
attrs
,
optionals
:
[],
required
:
[(
"name"
,
key
,
String
,
|
v
|
Some
(
v
)),
(
"value"
,
value
,
String
,
|
v
|
Some
(
v
))],
"Property must have a name and a value"
.to_string
());
p
.insert
(
k
,
v
);
Ok
(())
});
Ok
(
p
)
}
#[deriving(Show)]
pub
struct
Map
{
version
:
String
,
...
...
@@ -66,7 +85,8 @@ pub struct Map {
tile_width
:
int
,
tile_height
:
int
,
tilesets
:
Vec
<
Tileset
>
,
layers
:
Vec
<
Layer
>
layers
:
Vec
<
Layer
>
,
properties
:
Properties
}
impl
Map
{
...
...
@@ -84,6 +104,7 @@ impl Map {
let
mut
tilesets
=
Vec
::
new
();
let
mut
layers
=
Vec
::
new
();
let
mut
properties
=
HashMap
::
new
();
parse_tag!
(
parser
,
"map"
,
"tileset"
=>
|
attrs
|
{
tilesets
.push
(
try!
(
Tileset
::
new
(
parser
,
attrs
)));
...
...
@@ -92,11 +113,16 @@ impl Map {
"layer"
=>
|
attrs
|
{
layers
.push
(
try!
(
Layer
::
new
(
parser
,
attrs
,
w
as
uint
)));
Ok
(())
},
"properties"
=>
|
_
|
{
properties
=
try!
(
parse_properties
(
parser
));
Ok
(())
});
Ok
(
Map
{
version
:
v
,
orientation
:
o
,
width
:
w
,
height
:
h
,
tile_width
:
tw
,
tile_height
:
th
,
tilesets
:
tilesets
,
layers
:
layers
})
tilesets
:
tilesets
,
layers
:
layers
,
properties
:
properties
})
}
}
...
...
@@ -171,7 +197,8 @@ pub struct Layer {
name
:
String
,
opacity
:
f32
,
visible
:
bool
,
tiles
:
Vec
<
Vec
<
u32
>>
tiles
:
Vec
<
Vec
<
u32
>>
,
properties
:
Properties
}
impl
Layer
{
...
...
@@ -183,12 +210,18 @@ impl Layer {
required
:
[(
"name"
,
name
,
String
,
|
v
|
Some
(
v
))],
"layer must have a name"
.to_string
());
let
mut
tiles
=
Vec
::
new
();
let
mut
properties
=
HashMap
::
new
();
parse_tag!
(
parser
,
"layer"
,
"data"
=>
|
attrs
|
{
tiles
=
try!
(
parse_data
(
parser
,
attrs
,
width
));
Ok
(())
},
"properties"
=>
|
_
|
{
properties
=
try!
(
parse_properties
(
parser
));
Ok
(())
});
Ok
(
Layer
{
name
:
n
,
opacity
:
o
.unwrap_or
(
1.0
),
visible
:
v
.unwrap_or
(
true
),
tiles
:
tiles
})
Ok
(
Layer
{
name
:
n
,
opacity
:
o
.unwrap_or
(
1.0
),
visible
:
v
.unwrap_or
(
true
),
tiles
:
tiles
,
properties
:
properties
})
}
}
...
...
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