Make properties editable
This commit is contained in:
@@ -39,11 +39,11 @@ pub struct Object {
|
||||
|
||||
impl Object {
|
||||
pub fn parse(object: [u16; 4]) -> Self {
|
||||
let x = ((object[0] & 0x3ff) << 6 >> 6) as i16;
|
||||
let parallax = ((object[1] & 0x3ff) << 6 >> 6) as i16;
|
||||
let x = ((object[0] & 0x03ff) << 6 >> 6) as i16;
|
||||
let parallax = ((object[1] & 0x03ff) << 6 >> 6) as i16;
|
||||
let lon = object[1] & 0x8000 != 0;
|
||||
let ron = object[1] & 0x4000 != 0;
|
||||
let y = (object[2] & 0x0ff) as i16;
|
||||
let y = (object[2] & 0x00ff) as i16;
|
||||
// Y is stored as the bottom 8 bits of an i16,
|
||||
// so only sign extend if it's out of range.
|
||||
let y = if y > 224 { y << 8 >> 8 } else { y };
|
||||
@@ -57,6 +57,30 @@ impl Object {
|
||||
data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&self, source: &mut [u16; 4]) -> bool {
|
||||
let mut changed = false;
|
||||
|
||||
let new_x = (self.x as u16 & 0x03ff) | (source[0] & 0xfc00);
|
||||
changed |= source[0] != new_x;
|
||||
source[0] = new_x;
|
||||
|
||||
let new_p = if self.lon { 0x8000 } else { 0x0000 }
|
||||
| if self.ron { 0x4000 } else { 0x0000 }
|
||||
| (self.parallax as u16 & 0x3ff)
|
||||
| (source[1] & 0x3c00);
|
||||
changed |= source[1] != new_p;
|
||||
source[1] = new_p;
|
||||
|
||||
let new_y = (self.y as u16 & 0x00ff) | (source[2] & 0xff00);
|
||||
changed |= source[2] != new_y;
|
||||
source[2] = new_y;
|
||||
|
||||
if self.data.update(&mut source[3]) {
|
||||
changed = true;
|
||||
}
|
||||
changed
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CellData {
|
||||
@@ -79,6 +103,17 @@ impl CellData {
|
||||
palette_index,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&self, source: &mut u16) -> bool {
|
||||
let new_value = (self.palette_index as u16) << 14
|
||||
| if self.hflip { 0x2000 } else { 0x0000 }
|
||||
| if self.vflip { 0x1000 } else { 0x0000 }
|
||||
| (self.char_index as u16 & 0x07ff)
|
||||
| (*source & 0x0800);
|
||||
let changed = *source != new_value;
|
||||
*source = new_value;
|
||||
changed
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_char_row(
|
||||
|
||||
Reference in New Issue
Block a user