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
b3abccbf
Commit
b3abccbf
authored
10 years ago
by
Matthew Hall
Browse files
Options
Downloads
Patches
Plain Diff
Update to use new io
parent
d902510c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/main.rs
+2
-3
2 additions, 3 deletions
examples/main.rs
src/lib.rs
+11
-11
11 additions, 11 deletions
src/lib.rs
tests/lib.rs
+2
-3
2 additions, 3 deletions
tests/lib.rs
with
15 additions
and
17 deletions
examples/main.rs
+
2
−
3
View file @
b3abccbf
extern
crate
serialize
;
extern
crate
serialize
;
extern
crate
tiled
;
extern
crate
tiled
;
use
std
::
old_io
::
{
File
,
BufferedReader
}
;
use
std
::
fs
::
File
;
use
tiled
::
parse
;
use
tiled
::
parse
;
fn
main
()
{
fn
main
()
{
let
file
=
File
::
open
(
&
Path
::
new
(
"assets/tiled_base64_zlib.tmx"
))
.unwrap
();
let
file
=
File
::
open
(
&
Path
::
new
(
"assets/tiled_base64_zlib.tmx"
))
.unwrap
();
println!
(
"Opened file"
);
println!
(
"Opened file"
);
let
reader
=
BufferedReader
::
new
(
file
);
let
map
=
parse
(
file
)
.unwrap
();
let
map
=
parse
(
reader
)
.unwrap
();
println!
(
"{:?}"
,
map
);
println!
(
"{:?}"
,
map
);
println!
(
"{:?}"
,
map
.get_tileset_by_gid
(
22
));
println!
(
"{:?}"
,
map
.get_tileset_by_gid
(
22
));
}
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
11
−
11
View file @
b3abccbf
...
@@ -134,7 +134,7 @@ impl fmt::Display for TiledError {
...
@@ -134,7 +134,7 @@ impl fmt::Display for TiledError {
pub
type
Properties
=
HashMap
<
String
,
String
>
;
pub
type
Properties
=
HashMap
<
String
,
String
>
;
fn
parse_properties
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
)
->
Result
<
Properties
,
TiledError
>
{
fn
parse_properties
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
)
->
Result
<
Properties
,
TiledError
>
{
let
mut
p
=
HashMap
::
new
();
let
mut
p
=
HashMap
::
new
();
parse_tag!
(
parser
,
"properties"
,
parse_tag!
(
parser
,
"properties"
,
"property"
=>
|
attrs
:
Vec
<
OwnedAttribute
>
|
{
"property"
=>
|
attrs
:
Vec
<
OwnedAttribute
>
|
{
...
@@ -167,7 +167,7 @@ pub struct Map {
...
@@ -167,7 +167,7 @@ pub struct Map {
}
}
impl
Map
{
impl
Map
{
fn
new
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
Map
,
TiledError
>
{
fn
new
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
Map
,
TiledError
>
{
let
(
c
,
(
v
,
o
,
w
,
h
,
tw
,
th
))
=
get_attrs!
(
let
(
c
,
(
v
,
o
,
w
,
h
,
tw
,
th
))
=
get_attrs!
(
attrs
,
attrs
,
optionals
:
[(
"backgroundcolor"
,
colour
,
|
v
:
String
|
v
.parse
()
.ok
())],
optionals
:
[(
"backgroundcolor"
,
colour
,
|
v
:
String
|
v
.parse
()
.ok
())],
...
@@ -258,7 +258,7 @@ pub struct Tileset {
...
@@ -258,7 +258,7 @@ pub struct Tileset {
}
}
impl
Tileset
{
impl
Tileset
{
fn
new
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
Tileset
,
TiledError
>
{
fn
new
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
Tileset
,
TiledError
>
{
let
((
s
,
m
),
(
g
,
n
,
w
,
h
))
=
get_attrs!
(
let
((
s
,
m
),
(
g
,
n
,
w
,
h
))
=
get_attrs!
(
attrs
,
attrs
,
optionals
:
[(
"spacing"
,
spacing
,
|
v
:
String
|
v
.parse
()
.ok
()),
optionals
:
[(
"spacing"
,
spacing
,
|
v
:
String
|
v
.parse
()
.ok
()),
...
@@ -294,7 +294,7 @@ pub struct Image {
...
@@ -294,7 +294,7 @@ pub struct Image {
}
}
impl
Image
{
impl
Image
{
fn
new
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
Image
,
TiledError
>
{
fn
new
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
Image
,
TiledError
>
{
let
(
c
,
(
s
,
w
,
h
))
=
get_attrs!
(
let
(
c
,
(
s
,
w
,
h
))
=
get_attrs!
(
attrs
,
attrs
,
optionals
:
[(
"trans"
,
trans
,
|
v
:
String
|
v
.parse
()
.ok
())],
optionals
:
[(
"trans"
,
trans
,
|
v
:
String
|
v
.parse
()
.ok
())],
...
@@ -320,7 +320,7 @@ pub struct Layer {
...
@@ -320,7 +320,7 @@ pub struct Layer {
}
}
impl
Layer
{
impl
Layer
{
fn
new
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
,
attrs
:
Vec
<
OwnedAttribute
>
,
width
:
u32
)
->
Result
<
Layer
,
TiledError
>
{
fn
new
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
,
attrs
:
Vec
<
OwnedAttribute
>
,
width
:
u32
)
->
Result
<
Layer
,
TiledError
>
{
let
((
o
,
v
),
n
)
=
get_attrs!
(
let
((
o
,
v
),
n
)
=
get_attrs!
(
attrs
,
attrs
,
optionals
:
[(
"opacity"
,
opacity
,
|
v
:
String
|
v
.parse
()
.ok
()),
optionals
:
[(
"opacity"
,
opacity
,
|
v
:
String
|
v
.parse
()
.ok
()),
...
@@ -353,7 +353,7 @@ pub struct ObjectGroup {
...
@@ -353,7 +353,7 @@ pub struct ObjectGroup {
}
}
impl
ObjectGroup
{
impl
ObjectGroup
{
fn
new
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
ObjectGroup
,
TiledError
>
{
fn
new
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
ObjectGroup
,
TiledError
>
{
let
((
o
,
v
,
c
),
n
)
=
get_attrs!
(
let
((
o
,
v
,
c
),
n
)
=
get_attrs!
(
attrs
,
attrs
,
optionals
:
[(
"opacity"
,
opacity
,
|
v
:
String
|
v
.parse
()
.ok
()),
optionals
:
[(
"opacity"
,
opacity
,
|
v
:
String
|
v
.parse
()
.ok
()),
...
@@ -383,7 +383,7 @@ pub enum Object {
...
@@ -383,7 +383,7 @@ pub enum Object {
}
}
impl
Object
{
impl
Object
{
fn
new
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
Object
,
TiledError
>
{
fn
new
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
,
attrs
:
Vec
<
OwnedAttribute
>
)
->
Result
<
Object
,
TiledError
>
{
let
((
w
,
h
,
v
),
(
x
,
y
))
=
get_attrs!
(
let
((
w
,
h
,
v
),
(
x
,
y
))
=
get_attrs!
(
attrs
,
attrs
,
optionals
:
[(
"width"
,
width
,
|
v
:
String
|
v
.parse
()
.ok
()),
optionals
:
[(
"width"
,
width
,
|
v
:
String
|
v
.parse
()
.ok
()),
...
@@ -462,7 +462,7 @@ impl Object {
...
@@ -462,7 +462,7 @@ impl Object {
}
}
}
}
fn
parse_data
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
,
attrs
:
Vec
<
OwnedAttribute
>
,
width
:
u32
)
->
Result
<
Vec
<
Vec
<
u32
>>
,
TiledError
>
{
fn
parse_data
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
,
attrs
:
Vec
<
OwnedAttribute
>
,
width
:
u32
)
->
Result
<
Vec
<
Vec
<
u32
>>
,
TiledError
>
{
let
((
e
,
c
),
())
=
get_attrs!
(
let
((
e
,
c
),
())
=
get_attrs!
(
attrs
,
attrs
,
optionals
:
[(
"encoding"
,
encoding
,
|
v
|
Some
(
v
)),
optionals
:
[(
"encoding"
,
encoding
,
|
v
|
Some
(
v
)),
...
@@ -488,7 +488,7 @@ fn parse_data<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>
...
@@ -488,7 +488,7 @@ fn parse_data<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>
};
};
}
}
fn
parse_base64
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
)
->
Result
<
Vec
<
u8
>
,
TiledError
>
{
fn
parse_base64
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
)
->
Result
<
Vec
<
u8
>
,
TiledError
>
{
loop
{
loop
{
match
parser
.next
()
{
match
parser
.next
()
{
Characters
(
s
)
=>
return
s
.trim
()
Characters
(
s
)
=>
return
s
.trim
()
...
@@ -527,7 +527,7 @@ fn decode_gzip(data: Vec<u8>) -> Result<Vec<u8>, TiledError> {
...
@@ -527,7 +527,7 @@ fn decode_gzip(data: Vec<u8>) -> Result<Vec<u8>, TiledError> {
Ok
(
data
)
Ok
(
data
)
}
}
fn
decode_csv
<
B
:
Buffer
>
(
parser
:
&
mut
EventReader
<
B
>
)
->
Result
<
Vec
<
Vec
<
u32
>>
,
TiledError
>
{
fn
decode_csv
<
R
:
Read
>
(
parser
:
&
mut
EventReader
<
R
>
)
->
Result
<
Vec
<
Vec
<
u32
>>
,
TiledError
>
{
loop
{
loop
{
match
parser
.next
()
{
match
parser
.next
()
{
Characters
(
s
)
=>
{
Characters
(
s
)
=>
{
...
@@ -569,7 +569,7 @@ fn convert_to_u32(all: &Vec<u8>, width: u32) -> Vec<Vec<u32>> {
...
@@ -569,7 +569,7 @@ fn convert_to_u32(all: &Vec<u8>, width: u32) -> Vec<Vec<u32>> {
/// Parse a buffer hopefully containing the contents of a Tiled file and try to
/// Parse a buffer hopefully containing the contents of a Tiled file and try to
/// parse it.
/// parse it.
pub
fn
parse
<
B
:
Buffer
>
(
reader
:
B
)
->
Result
<
Map
,
TiledError
>
{
pub
fn
parse
<
R
:
Read
>
(
reader
:
R
)
->
Result
<
Map
,
TiledError
>
{
let
mut
parser
=
EventReader
::
new
(
reader
);
let
mut
parser
=
EventReader
::
new
(
reader
);
loop
{
loop
{
match
parser
.next
()
{
match
parser
.next
()
{
...
...
This diff is collapsed.
Click to expand it.
tests/lib.rs
+
2
−
3
View file @
b3abccbf
extern
crate
tiled
;
extern
crate
tiled
;
use
std
::
old_io
::
{
File
,
BufferedReader
}
;
use
std
::
fs
::
File
;
use
tiled
::{
Map
,
TiledError
,
parse
};
use
tiled
::{
Map
,
TiledError
,
parse
};
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
();
let
reader
=
BufferedReader
::
new
(
file
);
return
parse
(
file
);
return
parse
(
reader
);
}
}
#[test]
#[test]
...
...
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