aboutsummaryrefslogtreecommitdiff
path: root/renderer/src/map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'renderer/src/map.rs')
-rw-r--r--renderer/src/map.rs62
1 files changed, 49 insertions, 13 deletions
diff --git a/renderer/src/map.rs b/renderer/src/map.rs
index 8ce932f..f7672c1 100644
--- a/renderer/src/map.rs
+++ b/renderer/src/map.rs
@@ -2,7 +2,8 @@ use std::collections::HashMap;
use log::{info, warn};
use skia_safe::{
- canvas::SrcRectConstraint, BlendMode, Canvas, Color4f, ColorSpace, ISize, Image, Paint, Rect,
+ canvas::SrcRectConstraint, BlendMode, Canvas, Color4f, ColorSpace, ISize, Image, Matrix, Paint,
+ Rect,
};
use twclient::world::{
map::{format, TILE_NUM},
@@ -51,6 +52,7 @@ impl MapRenderer {
}
pub fn draw(&mut self, world: &World, canvas: &mut Canvas) {
+ let rot90 = Matrix::rotate_deg(90.0);
let mut grid_paint = Paint::new(
Color4f {
a: 1.0,
@@ -89,22 +91,14 @@ impl MapRenderer {
let layer_x = layer_x.try_into().unwrap_or(0);
let layer_y = layer_y.try_into().unwrap_or(0);
- let tile_rect = Rect {
- top: layer_y as f32 * TILE_SIZE,
- left: layer_x as f32 * TILE_SIZE,
- bottom: layer_y as f32 * TILE_SIZE + TILE_SIZE,
- right: layer_x as f32 * TILE_SIZE + TILE_SIZE,
- };
- // canvas.draw_rect(tile_rect, &grid_paint);
-
let tile = match l.tiles.get((layer_y, layer_x)) {
Some(t) => t,
None => continue,
};
- let _rotate = tile.flags & format::TILEFLAG_ROTATE != 0;
- let _vflip = tile.flags & format::TILEFLAG_VFLIP != 0;
- let _hflip = tile.flags & format::TILEFLAG_HFLIP != 0;
+ let rotate = tile.flags & format::TILEFLAG_ROTATE != 0;
+ let vflip = tile.flags & format::TILEFLAG_VFLIP != 0;
+ let hflip = tile.flags & format::TILEFLAG_HFLIP != 0;
let tile_x = tile.index as u32 % TILE_NUM;
let tile_y = tile.index as u32 / TILE_NUM;
@@ -112,6 +106,21 @@ impl MapRenderer {
continue;
}
+ canvas.save();
+ canvas.translate((
+ (layer_x as f32 + 0.5) * TILE_SIZE,
+ (layer_y as f32 + 0.5) * TILE_SIZE,
+ ));
+ if rotate {
+ canvas.concat(&rot90);
+ }
+ if vflip {
+ canvas.scale((-1.0, 1.0));
+ }
+ if hflip {
+ canvas.scale((1.0, -1.0));
+ }
+
const TL: u32 = 64;
canvas.draw_image_rect(
tileset,
@@ -124,9 +133,36 @@ impl MapRenderer {
},
SrcRectConstraint::Strict,
)),
- tile_rect,
+ Rect {
+ top: -TILE_SIZE / 2.0,
+ bottom: TILE_SIZE / 2.0,
+ left: -TILE_SIZE / 2.0,
+ right: TILE_SIZE / 2.0,
+ },
&layer_tint,
);
+
+ // if hflip {
+ // canvas.draw_rect(
+ // Rect {
+ // top: -TILE_SIZE / 2.0,
+ // bottom: TILE_SIZE / 2.0,
+ // left: -TILE_SIZE / 2.0,
+ // right: TILE_SIZE / 2.0,
+ // },
+ // &Paint::new(
+ // Color4f {
+ // a: 0.5,
+ // b: 1.0,
+ // g: 0.0,
+ // r: 1.0,
+ // },
+ // &ColorSpace::new_srgb(),
+ // ),
+ // );
+ // }
+
+ canvas.restore();
}
}
}