|
|
@ -28,8 +28,8 @@ impl Tile for Teleporter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn draw(&self, x: usize, y: usize, state: State, surface: &mut TextSurface) {
|
|
|
|
fn draw_simple(&self, state: State) -> TextChar {
|
|
|
|
surface.set(x, y, TextChar::from_state('P', state));
|
|
|
|
TextChar::from_state('P', state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -166,53 +166,71 @@ impl Tile for Sender {
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: read self.signals to determine the state of each char
|
|
|
|
// TODO: read self.signals to determine the state of each char
|
|
|
|
// TODO: automated test
|
|
|
|
// TODO: automated test
|
|
|
|
fn draw(&self, x: usize, y: usize, _state: State, surface: &mut TextSurface) {
|
|
|
|
fn draw(&self, x: i32, y: i32, _state: State, surface: &mut TextSurface) {
|
|
|
|
for (prev, next) in self.path.iter().zip(self.path.iter().skip(1)) {
|
|
|
|
for (prev, next) in self.path.iter().zip(self.path.iter().skip(1)) {
|
|
|
|
if prev.0 != next.0 {
|
|
|
|
if prev.0 != next.0 {
|
|
|
|
// Draw the diode of the corner
|
|
|
|
// Draw the diode of the corner
|
|
|
|
let ch = if next.0 > prev.0 { '>' } else { '<' };
|
|
|
|
let ch = if next.0 > prev.0 { '>' } else { '<' };
|
|
|
|
|
|
|
|
let x2 = x + prev.0;
|
|
|
|
|
|
|
|
let y2 = y + prev.1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if x2 >= 0 && y2 >= 0 {
|
|
|
|
surface.set(
|
|
|
|
surface.set(
|
|
|
|
(x as i32 + prev.0) as usize,
|
|
|
|
x2 as usize,
|
|
|
|
(y as i32 + prev.1) as usize,
|
|
|
|
y2 as usize,
|
|
|
|
TextChar::from_state(ch, State::Idle),
|
|
|
|
TextChar::from_state(ch, State::Idle),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Draw the horizontal line
|
|
|
|
// Draw the horizontal line
|
|
|
|
|
|
|
|
|
|
|
|
for dx in (prev.0 + 1)..(next.0) {
|
|
|
|
for dx in (prev.0 + 1)..(next.0) {
|
|
|
|
|
|
|
|
let x2 = x + dx;
|
|
|
|
|
|
|
|
let y2 = y + prev.1;
|
|
|
|
|
|
|
|
if x2 >= 0 && y2 >= 0 {
|
|
|
|
surface.set(
|
|
|
|
surface.set(
|
|
|
|
(x as i32 + dx) as usize,
|
|
|
|
x2 as usize,
|
|
|
|
(y as i32 + prev.1) as usize,
|
|
|
|
y2 as usize,
|
|
|
|
TextChar::from_state('-', State::Idle),
|
|
|
|
TextChar::from_state('-', State::Idle),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Draw the diode of the corner
|
|
|
|
// Draw the diode of the corner
|
|
|
|
let ch = if next.1 > prev.1 { 'v' } else { '^' };
|
|
|
|
let ch = if next.1 > prev.1 { 'v' } else { '^' };
|
|
|
|
|
|
|
|
let x2 = x + prev.0;
|
|
|
|
|
|
|
|
let y2 = y + prev.1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if x2 >= 0 && y2 >= 0 {
|
|
|
|
surface.set(
|
|
|
|
surface.set(
|
|
|
|
(x as i32 + prev.0) as usize,
|
|
|
|
x2 as usize,
|
|
|
|
(y as i32 + prev.1) as usize,
|
|
|
|
y2 as usize,
|
|
|
|
TextChar::from_state(ch, State::Idle),
|
|
|
|
TextChar::from_state(ch, State::Idle),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Draw the vertical line
|
|
|
|
// Draw the vertical line
|
|
|
|
|
|
|
|
|
|
|
|
for dy in (prev.1 + 1)..(next.1) {
|
|
|
|
for dy in (prev.1 + 1)..(next.1) {
|
|
|
|
|
|
|
|
let x2 = x + prev.0;
|
|
|
|
|
|
|
|
let y2 = y + dy;
|
|
|
|
|
|
|
|
if x2 >= 0 && y2 >= 0 {
|
|
|
|
surface.set(
|
|
|
|
surface.set(
|
|
|
|
(y as i32 + prev.0) as usize,
|
|
|
|
x2 as usize,
|
|
|
|
(y as i32 + dy) as usize,
|
|
|
|
y2 as usize,
|
|
|
|
TextChar::from_state('|', State::Idle),
|
|
|
|
TextChar::from_state('-', State::Idle),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
use super::*;
|
|
|
|
use veccell::{VecRef, VecRefMut};
|
|
|
|
use veccell::{VecRef};
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_teleporter_transmit_same_pane() {
|
|
|
|
fn test_teleporter_transmit_same_pane() {
|
|
|
|