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
3614aad0
Unverified
Commit
3614aad0
authored
3 years ago
by
Thorbjørn Lindeijer
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement Deref for Tile<'tileset> (#191)
Also use the TileId alias in a few more places.
parent
377d748b
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
src/layers/tile/mod.rs
+1
-1
1 addition, 1 deletion
src/layers/tile/mod.rs
src/tile.rs
+20
-34
20 additions, 34 deletions
src/tile.rs
src/tileset.rs
+4
-4
4 additions, 4 deletions
src/tileset.rs
tests/lib.rs
+1
-1
1 addition, 1 deletion
tests/lib.rs
with
27 additions
and
41 deletions
README.md
+
1
−
1
View file @
3614aad0
...
@@ -27,7 +27,7 @@ fn main() {
...
@@ -27,7 +27,7 @@ fn main() {
)
)
.unwrap
();
.unwrap
();
println!
(
"{:?}"
,
map
);
println!
(
"{:?}"
,
map
);
println!
(
"{:?}"
,
map
.tilesets
()[
0
]
.get_tile
(
0
)
.unwrap
()
.probability
()
);
println!
(
"{:?}"
,
map
.tilesets
()[
0
]
.get_tile
(
0
)
.unwrap
()
.probability
);
}
}
```
```
...
...
This diff is collapsed.
Click to expand it.
src/layers/tile/mod.rs
+
1
−
1
View file @
3614aad0
...
@@ -46,7 +46,7 @@ impl LayerTileData {
...
@@ -46,7 +46,7 @@ impl LayerTileData {
/// Get the layer tile's local id within its parent tileset.
/// Get the layer tile's local id within its parent tileset.
#[inline]
#[inline]
pub
fn
id
(
&
self
)
->
u32
{
pub
fn
id
(
&
self
)
->
TileId
{
self
.id
self
.id
}
}
...
...
This diff is collapsed.
Click to expand it.
src/tile.rs
+
20
−
34
View file @
3614aad0
...
@@ -15,14 +15,21 @@ use crate::{
...
@@ -15,14 +15,21 @@ use crate::{
/// A tile ID, local to a tileset.
/// A tile ID, local to a tileset.
pub
type
TileId
=
u32
;
pub
type
TileId
=
u32
;
/// Raw data belonging to a tile.
#[derive(Debug,
PartialEq,
Clone,
Default)]
#[derive(Debug,
PartialEq,
Clone,
Default)]
pub
(
crate
)
struct
TileData
{
pub
struct
TileData
{
image
:
Option
<
Image
>
,
/// The image of the tile. Only set when the tile is part of an "image collection" tileset.
properties
:
Properties
,
pub
image
:
Option
<
Image
>
,
collision
:
Option
<
ObjectLayerData
>
,
/// The custom properties of this tile.
animation
:
Option
<
Vec
<
Frame
>>
,
pub
properties
:
Properties
,
tile_type
:
Option
<
String
>
,
/// The collision shapes of this tile.
probability
:
f32
,
pub
collision
:
Option
<
ObjectLayerData
>
,
/// The animation frames of this tile.
pub
animation
:
Option
<
Vec
<
Frame
>>
,
/// The type of this tile.
pub
tile_type
:
Option
<
String
>
,
/// The probability of this tile.
pub
probability
:
f32
,
}
}
/// Points to a tile belonging to a tileset.
/// Points to a tile belonging to a tileset.
...
@@ -41,35 +48,14 @@ impl<'tileset> Tile<'tileset> {
...
@@ -41,35 +48,14 @@ impl<'tileset> Tile<'tileset> {
pub
fn
tileset
(
&
self
)
->
&
'tileset
Tileset
{
pub
fn
tileset
(
&
self
)
->
&
'tileset
Tileset
{
self
.tileset
self
.tileset
}
}
}
/// Get a reference to the tile's image.
impl
<
'tileset
>
std
::
ops
::
Deref
for
Tile
<
'tileset
>
{
pub
fn
image
(
&
self
)
->
Option
<&
Image
>
{
type
Target
=
TileData
;
self
.data.image
.as_ref
()
}
/// Get a reference to the tile's properties.
pub
fn
properties
(
&
self
)
->
&
Properties
{
&
self
.data.properties
}
/// Get a reference to the tile's collision.
pub
fn
collision
(
&
self
)
->
Option
<&
ObjectLayerData
>
{
self
.data.collision
.as_ref
()
}
/// Get a reference to the tile's animation frames.
pub
fn
animation
(
&
self
)
->
Option
<&
[
Frame
]
>
{
self
.data.animation
.as_ref
()
.map
(
Vec
::
as_slice
)
}
/// Get a reference to the tile's type.
pub
fn
tile_type
(
&
self
)
->
Option
<&
str
>
{
self
.data.tile_type
.as_deref
()
}
/// Get the tile's probability.
#[inline]
pub
fn
probability
(
&
self
)
->
f32
{
fn
deref
(
&
self
)
->
&
'tileset
Self
::
Target
{
self
.data
.probability
self
.data
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/tileset.rs
+
4
−
4
View file @
3614aad0
...
@@ -10,7 +10,7 @@ use crate::error::{Error, Result};
...
@@ -10,7 +10,7 @@ use crate::error::{Error, Result};
use
crate
::
image
::
Image
;
use
crate
::
image
::
Image
;
use
crate
::
properties
::{
parse_properties
,
Properties
};
use
crate
::
properties
::{
parse_properties
,
Properties
};
use
crate
::
tile
::
TileData
;
use
crate
::
tile
::
TileData
;
use
crate
::{
util
::
*
,
Gid
,
Tile
};
use
crate
::{
util
::
*
,
Gid
,
Tile
,
TileId
};
/// A collection of tiles for usage in maps and template objects.
/// A collection of tiles for usage in maps and template objects.
///
///
...
@@ -53,7 +53,7 @@ pub struct Tileset {
...
@@ -53,7 +53,7 @@ pub struct Tileset {
pub
image
:
Option
<
Image
>
,
pub
image
:
Option
<
Image
>
,
/// All the tiles present in this tileset, indexed by their local IDs.
/// All the tiles present in this tileset, indexed by their local IDs.
tiles
:
HashMap
<
u32
,
TileData
>
,
tiles
:
HashMap
<
TileId
,
TileData
>
,
/// The custom properties of the tileset.
/// The custom properties of the tileset.
pub
properties
:
Properties
,
pub
properties
:
Properties
,
...
@@ -124,13 +124,13 @@ impl Tileset {
...
@@ -124,13 +124,13 @@ impl Tileset {
/// Gets the tile with the specified ID from the tileset.
/// Gets the tile with the specified ID from the tileset.
#[inline]
#[inline]
pub
fn
get_tile
(
&
self
,
id
:
u32
)
->
Option
<
Tile
>
{
pub
fn
get_tile
(
&
self
,
id
:
TileId
)
->
Option
<
Tile
>
{
self
.tiles
.get
(
&
id
)
.map
(|
data
|
Tile
::
new
(
self
,
data
))
self
.tiles
.get
(
&
id
)
.map
(|
data
|
Tile
::
new
(
self
,
data
))
}
}
/// Iterates through the tiles from this tileset.
/// Iterates through the tiles from this tileset.
#[inline]
#[inline]
pub
fn
tiles
(
&
self
)
->
impl
ExactSizeIterator
<
Item
=
(
u32
,
Tile
)
>
{
pub
fn
tiles
(
&
self
)
->
impl
ExactSizeIterator
<
Item
=
(
TileId
,
Tile
)
>
{
self
.tiles
self
.tiles
.iter
()
.iter
()
.map
(
move
|(
id
,
data
)|
(
*
id
,
Tile
::
new
(
self
,
data
)))
.map
(
move
|(
id
,
data
)|
(
*
id
,
Tile
::
new
(
self
,
data
)))
...
...
This diff is collapsed.
Click to expand it.
tests/lib.rs
+
1
−
1
View file @
3614aad0
...
@@ -192,7 +192,7 @@ fn test_tile_property() {
...
@@ -192,7 +192,7 @@ fn test_tile_property() {
let
prop_value
:
String
=
if
let
Some
(
&
PropertyValue
::
StringValue
(
ref
v
))
=
r
.tilesets
()[
0
]
let
prop_value
:
String
=
if
let
Some
(
&
PropertyValue
::
StringValue
(
ref
v
))
=
r
.tilesets
()[
0
]
.get_tile
(
1
)
.get_tile
(
1
)
.unwrap
()
.unwrap
()
.properties
()
.properties
.get
(
"a tile property"
)
.get
(
"a tile property"
)
{
{
v
.clone
()
v
.clone
()
...
...
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