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
2f6d637f
Commit
2f6d637f
authored
3 years ago
by
SiegeLord
Browse files
Options
Downloads
Patches
Plain Diff
Support object properties.
Fixes #72
parent
fd15cb4c
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
assets/tiled_object_property.tmx
+21
-0
21 additions, 0 deletions
assets/tiled_object_property.tmx
src/properties.rs
+6
-0
6 additions, 0 deletions
src/properties.rs
tests/lib.rs
+13
-0
13 additions, 0 deletions
tests/lib.rs
with
40 additions
and
0 deletions
assets/tiled_object_property.tmx
0 → 100644
+
21
−
0
View file @
2f6d637f
<?xml version="1.0" encoding="UTF-8"?>
<map
version=
"1.5"
tiledversion=
"1.7.2"
orientation=
"orthogonal"
renderorder=
"right-down"
width=
"2"
height=
"2"
tilewidth=
"32"
tileheight=
"32"
infinite=
"0"
nextlayerid=
"3"
nextobjectid=
"4"
>
<layer
id=
"1"
name=
"Tile Layer 1"
width=
"2"
height=
"2"
>
<data
encoding=
"csv"
>
0,0,
0,0
</data>
</layer>
<objectgroup
id=
"2"
name=
"Object Layer 1"
>
<object
id=
"2"
x=
"0"
y=
"0"
width=
"32"
height=
"32"
>
<properties>
<property
name=
"object property"
type=
"object"
value=
"3"
/>
</properties>
</object>
<object
id=
"3"
x=
"32"
y=
"32"
width=
"32"
height=
"32"
>
<properties>
<property
name=
"object property"
type=
"object"
value=
"0"
/>
</properties>
</object>
</objectgroup>
</map>
This diff is collapsed.
Click to expand it.
src/properties.rs
+
6
−
0
View file @
2f6d637f
...
...
@@ -45,6 +45,8 @@ pub enum PropertyValue {
StringValue
(
String
),
/// Holds the path relative to the map or tileset
FileValue
(
String
),
/// Holds the id of a referenced object, or 0 if unset
ObjectValue
(
u32
),
}
impl
PropertyValue
{
...
...
@@ -70,6 +72,10 @@ impl PropertyValue {
))),
},
"string"
=>
Ok
(
PropertyValue
::
StringValue
(
value
)),
"object"
=>
match
value
.parse
()
{
Ok
(
val
)
=>
Ok
(
PropertyValue
::
ObjectValue
(
val
)),
Err
(
err
)
=>
Err
(
TiledError
::
Other
(
err
.to_string
())),
},
"file"
=>
Ok
(
PropertyValue
::
FileValue
(
value
)),
_
=>
Err
(
TiledError
::
Other
(
format!
(
"Unknown property type
\"
{}
\"
"
,
...
...
This diff is collapsed.
Click to expand it.
tests/lib.rs
+
13
−
0
View file @
2f6d637f
...
...
@@ -190,3 +190,16 @@ fn test_ldk_export() {
assert!
(
false
,
"It is wrongly recognised as an infinite map"
);
}
}
#[test]
fn
test_object_property
()
{
let
r
=
read_from_file
(
&
Path
::
new
(
"assets/tiled_object_property.tmx"
))
.unwrap
();
let
prop_value
=
if
let
Some
(
PropertyValue
::
ObjectValue
(
v
))
=
r
.object_groups
[
0
]
.objects
[
0
]
.properties
.get
(
"object property"
)
{
*
v
}
else
{
0
};
assert_eq!
(
3
,
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