1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use bytes::Bytes;
use std::{fmt, rc::Rc};
use crate::engine::d2::{
asset::Asset,
display::{Graphics, SubTexture, Texture},
util::{Disposable, Value},
};
use super::{BasicAsset, TextureRoot};
#[derive(Default, Clone, Debug)]
pub struct BasicTexture<R: TextureRoot + fmt::Debug> {
pub inner: BasicAsset<BasicTexture<R>>,
pub graphics: Option<Rc<dyn Graphics>>,
pub root: R,
pub root_x: i32,
pub root_y: i32,
parent: Option<Box<BasicTexture<R>>>,
x: i32,
y: i32,
width: i32,
height: i32,
}
impl<R: TextureRoot + fmt::Debug> AsRef<BasicAsset<BasicTexture<R>>> for BasicTexture<R> {
fn as_ref(&self) -> &BasicAsset<BasicTexture<R>> {
&self.inner
}
}
impl<R: TextureRoot + fmt::Debug> BasicTexture<R> {
fn new(root: R, width: i32, height: i32) -> Self {
Self {
inner: BasicAsset::new(),
root,
width,
height,
graphics: None,
parent: None,
root_x: 0,
root_y: 0,
x: 0,
y: 0,
}
}
fn copy_from(&self, other: BasicTexture<R>) {
unimplemented!()
}
fn on_disposed(&mut self) {
if self.parent.is_none() {
self.root.dispose();
}
}
}
impl<R: TextureRoot + fmt::Debug> SubTexture for BasicTexture<R> {
#[inline]
fn parent(&self) -> Option<Box<dyn Texture>> {
unimplemented!()
}
#[inline]
fn x(&self) -> i32 {
self.x
}
#[inline]
fn y(&self) -> i32 {
self.y
}
}
impl<R: TextureRoot + fmt::Debug> Texture for BasicTexture<R> {
fn graphics(&self) -> Box<dyn Graphics> {
self.root.graphics()
}
#[inline]
fn height(&self) -> i32 {
self.height
}
#[inline]
fn width(&self) -> i32 {
self.width
}
fn read_pixels(&self, x: i32, y: i32, width: i32, height: i32) -> Bytes {
self.root
.read_pixels(self.root_x + x, self.root_y + y, width, height)
}
fn split(&self, tiles_wide: i32, tiles_high: i32) -> Vec<Rc<dyn SubTexture>> {
let mut tiles = Vec::new();
let tile_width = (self.width / tiles_wide) as i32;
let tile_height = (self.height / tiles_high) as i32;
for y in 0..tiles_high {
for x in 0..tiles_wide {
tiles.push(self.sub_texture(
x * tile_width,
y * tile_height,
tile_width,
tile_height,
));
}
}
tiles
}
fn sub_texture(&self, x: i32, y: i32, width: i32, height: i32) -> Rc<dyn SubTexture> {
unimplemented!()
}
fn write_pixels(&self, pixels: Bytes, x: i32, y: i32, source_w: i32, source_h: i32) {
self.root
.write_pixels(pixels, self.root_x + x, self.root_y + y, source_w, source_h);
}
}
impl<R: TextureRoot + fmt::Debug> Asset for BasicTexture<R> {
fn reload_count(&self) -> usize {
unimplemented!()
}
}
impl<R: TextureRoot + fmt::Debug> Disposable for BasicTexture<R> {
fn dispose(&self) {
}
}