Skip to content

Commit 58c0866

Browse files
committed
random cleanup
1 parent c86fd2c commit 58c0866

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

src/dungeon/dungeon.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,12 @@ impl Dungeon {
448448
let entry = self.room_grid.get(grid_x + (grid_z * 6));
449449
entry.and_then(|e| *e)
450450
}
451-
451+
452452
pub fn get_player_room(&mut self, player: &Player) -> Option<usize> {
453-
let room = self.get_room_at(
453+
self.get_room_at(
454454
player.position.x as i32,
455455
player.position.z as i32
456-
);
457-
println!("{:?}", room);
458-
room
456+
)
459457
}
460458

461459
pub fn start_dungeon(&mut self) {
@@ -512,16 +510,16 @@ impl Dungeon {
512510
DungeonState::Started { current_ticks } => {
513511
*current_ticks += 1;
514512
for (_, player) in &mut server.world.players {
515-
if let Some(room_index) = server.dungeon.get_player_room(player) {
516-
let room = server.dungeon.rooms.get_mut(room_index).unwrap();
513+
if let Some(room_index) = self.get_player_room(player) {
514+
let room = self.rooms.get_mut(room_index).unwrap();
517515

518516
for crusher in room.crushers.iter_mut() {
519517
crusher.tick(player);
520518
}
521519

522520
if !room.entered {
523521
room.entered = true;
524-
DungeonMap::draw_room(self, room_index);
522+
self.map.draw_room(&self.rooms, &self.doors, room_index);
525523

526524
// this needs to happen once a tick,
527525
// but currently the ticking stuff is a mess

src/dungeon/map.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::dungeon::door::DoorType;
2-
use crate::dungeon::dungeon::Dungeon;
1+
use crate::dungeon::door::{Door, DoorType};
32
use crate::dungeon::room::room::Room;
43
use crate::dungeon::room::room_data::{RoomData, RoomShape, RoomType::*};
54
use crate::server::block::block_parameter::Axis;
@@ -123,21 +122,20 @@ impl DungeonMap {
123122
}
124123
}
125124

126-
pub fn draw_room(dungeon: &mut Dungeon, room: usize) {
127-
let room = &dungeon.rooms[room];
128-
let map = &mut dungeon.map;
125+
pub fn draw_room(&mut self, rooms: &[Room], doors: &[Door], room_index: usize) {
126+
let room = &rooms[room_index];
129127
let color = get_room_color(&room.room_data);
130128

131129
for segment in room.segments.iter() {
132130
let x = segment.x * 20;
133131
let y = segment.z * 20;
134132

135-
map.fill_px(x, y, 16, 16, color);
133+
self.fill_px(x, y, 16, 16, color);
136134
if room.segments.iter().find(|seg| seg.x == segment.x + 1 && seg.z == segment.z).is_some() {
137-
map.fill_px(x + 16, y, 4, 16, color);
135+
self.fill_px(x + 16, y, 4, 16, color);
138136
}
139137
if room.segments.iter().find(|seg| seg.x == segment.x && seg.z == segment.z + 1).is_some() {
140-
map.fill_px(x, y + 16, 16, 4, color);
138+
self.fill_px(x, y + 16, 16, 4, color);
141139
}
142140

143141
for (index, neighbour) in segment.neighbours.iter().enumerate() {
@@ -147,9 +145,7 @@ impl DungeonMap {
147145

148146
let (neighbour_room, door) = {
149147
let neighbour = neighbour.as_ref().unwrap();
150-
let room = dungeon.rooms.get(neighbour.room_index).unwrap();
151-
let door = dungeon.doors.get(neighbour.door_index).unwrap();
152-
(room, door)
148+
(&rooms[neighbour.room_index], &doors[neighbour.door_index])
153149
};
154150

155151
let mut x = segment.x * 20 + 6;
@@ -170,15 +166,15 @@ impl DungeonMap {
170166
};
171167

172168
if neighbour_room.entered {
173-
let color = get_door_color(room, &*neighbour_room);
174-
map.fill_px(x, y, width, height, color);
169+
let color = get_door_color(room, neighbour_room);
170+
self.fill_px(x, y, width, height, color);
175171
} else {
176172
let color = match door.door_type {
177173
DoorType::WITHER => BLACK,
178174
DoorType::BLOOD => RED,
179175
_ => GRAY,
180176
};
181-
map.fill_px(x, y, width, height, color);
177+
self.fill_px(x, y, width, height, color);
182178

183179
let mut x = segment.x * 20;
184180
let mut y = segment.z * 20;
@@ -191,28 +187,28 @@ impl DungeonMap {
191187
_ => unreachable!()
192188
}
193189

194-
map.fill_px(x ,y, 16, 16, GRAY);
190+
self.fill_px(x ,y, 16, 16, GRAY);
195191

196192
for (qx, qy) in QUESTION_MARK_POSITIONS {
197-
map.set_px(x + qx + 5, y + qy + 5, BLACK);
193+
self.set_px(x + qx + 5, y + qy + 5, BLACK);
198194
}
199195
}
200-
}
196+
}
201197
}
202198

203199
// fill in hole
204200
if room.room_data.shape == RoomShape::TwoByTwo {
205201
let x = room.segments[0].x * 20 + 16;
206202
let y = room.segments[0].z * 20 + 16;
207-
map.fill_px(x, y, 4, 4, color)
203+
self.fill_px(x, y, 4, 4, color)
208204
}
209205

210206
{
211207
let x = room.segments[0].x * 20 + 4;
212208
let y = room.segments[0].z * 20 + 4;
213209

214210
for (cx, cy) in CHECKMARK_POSITIONS {
215-
map.set_px(x + cx, y + cy, GREEN)
211+
self.set_px(x + cx, y + cy, GREEN)
216212
}
217213
}
218214
}

src/dungeon/room/room.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ pub struct RoomSegment {
1818

1919
#[derive(Debug)]
2020
pub struct RoomNeighbour {
21-
// pub door: Rc<RefCell<Door>>,
22-
// pub room: Rc<RefCell<Room>>,
23-
2421
pub door_index: usize,
2522
pub room_index: usize,
2623
}
@@ -162,7 +159,7 @@ impl Room {
162159
}
163160
}
164161

165-
pub fn get_rotation_from_segments(segments: &Vec<RoomSegment>, dungeon_doors: &[Door]) -> Direction {
162+
pub fn get_rotation_from_segments(segments: &[RoomSegment], dungeon_doors: &[Door]) -> Direction {
166163
let unique_x = segments.iter()
167164
.map(|segment| segment.x)
168165
.collect::<HashSet<usize>>();

0 commit comments

Comments
 (0)