1 | package g0803.bindingofshiba.view.game; | |
2 | ||
3 | import g0803.bindingofshiba.App; | |
4 | import g0803.bindingofshiba.bundles.Bundle; | |
5 | import g0803.bindingofshiba.events.IEventManager; | |
6 | import g0803.bindingofshiba.events.Observer; | |
7 | import g0803.bindingofshiba.events.game.MonsterDamagedEvent; | |
8 | import g0803.bindingofshiba.events.game.ProjectileDestroyedEvent; | |
9 | import g0803.bindingofshiba.events.game.ProjectileSpawnedEvent; | |
10 | import g0803.bindingofshiba.gui.GUI; | |
11 | import g0803.bindingofshiba.math.Vec2D; | |
12 | import g0803.bindingofshiba.model.game.elements.Monster; | |
13 | import g0803.bindingofshiba.model.game.elements.Obstacle; | |
14 | import g0803.bindingofshiba.model.game.elements.Projectile; | |
15 | import g0803.bindingofshiba.model.game.room.Door; | |
16 | import g0803.bindingofshiba.model.game.room.DoorPosition; | |
17 | import g0803.bindingofshiba.model.game.room.Room; | |
18 | import g0803.bindingofshiba.textures.ITexture; | |
19 | import g0803.bindingofshiba.view.View; | |
20 | import g0803.bindingofshiba.view.ViewFactory; | |
21 | import java.util.*; | |
22 | ||
23 | public class RoomView extends View<Room> implements Observer { | |
24 | ||
25 | private final ViewFactory<Monster> monsterViewFactory; | |
26 | private final ViewFactory<Obstacle> obstacleViewFactory; | |
27 | private final ViewFactory<Projectile> projectileViewFactory; | |
28 | ||
29 | private final List<View<Monster>> monsterViews = new ArrayList<>(); | |
30 | private final List<View<Obstacle>> obstacleViews = new ArrayList<>(); | |
31 | private final List<View<Projectile>> projectileViews = new ArrayList<>(); | |
32 | ||
33 | public RoomView(Room model, IEventManager eventManager) { | |
34 | this(model, eventManager, MonsterView::new, ObstacleView::new, ProjectileView::new); | |
35 | } | |
36 | ||
37 | public RoomView( | |
38 | Room model, | |
39 | IEventManager eventManager, | |
40 | ViewFactory<Monster> monsterViewFactory, | |
41 | ViewFactory<Obstacle> obstacleViewFactory, | |
42 | ViewFactory<Projectile> projectileViewFactory) { | |
43 | super(model, eventManager); | |
44 | ||
45 | this.monsterViewFactory = monsterViewFactory; | |
46 | this.obstacleViewFactory = obstacleViewFactory; | |
47 | this.projectileViewFactory = projectileViewFactory; | |
48 | ||
49 |
1
1. <init> : removed call to g0803/bindingofshiba/view/game/RoomView::createViews → KILLED |
createViews(); |
50 |
1
1. <init> : removed call to g0803/bindingofshiba/events/IEventManager::addObserver → SURVIVED |
getEventManager().addObserver(this); |
51 | } | |
52 | ||
53 | private void createViews() { | |
54 |
1
1. createViews : removed call to java/util/List::clear → SURVIVED |
monsterViews.clear(); |
55 |
1
1. createViews : removed call to java/util/List::clear → SURVIVED |
obstacleViews.clear(); |
56 |
1
1. createViews : removed call to java/util/List::clear → SURVIVED |
projectileViews.clear(); |
57 | ||
58 | for (Monster monster : getModel().getMonsters()) { | |
59 | monsterViews.add(monsterViewFactory.create(monster, getEventManager())); | |
60 | } | |
61 | ||
62 | for (Obstacle obstacle : getModel().getObstacles()) { | |
63 | obstacleViews.add(obstacleViewFactory.create(obstacle, getEventManager())); | |
64 | } | |
65 | ||
66 | for (Projectile projectile : getModel().getProjectiles()) { | |
67 | projectileViews.add(projectileViewFactory.create(projectile, getEventManager())); | |
68 | } | |
69 | } | |
70 | ||
71 | private ITexture getWallTextureFromDoorPosition( | |
72 | Bundle<ITexture> textures, DoorPosition doorPosition) { | |
73 | String builder = | |
74 | "room.walls." | |
75 |
1
1. getWallTextureFromDoorPosition : negated conditional → KILLED |
+ (getModel().getDoors().containsKey(doorPosition) ? "open." : "closed.") |
76 | + doorPosition.name().toLowerCase(Locale.ROOT); | |
77 |
1
1. getWallTextureFromDoorPosition : replaced return value with null for g0803/bindingofshiba/view/game/RoomView::getWallTextureFromDoorPosition → KILLED |
return textures.get(builder); |
78 | } | |
79 | ||
80 | private void drawWalls(App app, GUI gui, Vec2D offset) { | |
81 | Bundle<ITexture> textures = app.getTextures(); | |
82 | ||
83 | for (DoorPosition doorPosition : DoorPosition.values()) { | |
84 | ITexture texture = getWallTextureFromDoorPosition(textures, doorPosition); | |
85 |
1
1. drawWalls : removed call to g0803/bindingofshiba/gui/GUI::blit → KILLED |
gui.blit((int) offset.getX(), (int) offset.getY(), texture); |
86 | } | |
87 | } | |
88 | ||
89 | private void drawDoors(App app, GUI gui, Vec2D offset) { | |
90 | Bundle<ITexture> textures = app.getTextures(); | |
91 | Map<DoorPosition, Door> doors = getModel().getDoors(); | |
92 | ||
93 | for (Door door : doors.values()) { | |
94 | ITexture texture = | |
95 |
1
1. drawDoors : negated conditional → KILLED |
door.getUnlocked() |
96 | ? textures.get(door.getDoorPosition(getModel()).getOpenKey()) | |
97 | : textures.get(door.getDoorPosition(getModel()).getClosedKey()); | |
98 | ||
99 | Vec2D position = door.getPositionByWall(getModel()).add(offset).round(); | |
100 |
1
1. drawDoors : removed call to g0803/bindingofshiba/gui/GUI::blit → KILLED |
gui.blit((int) position.getX(), (int) position.getY(), texture); |
101 | } | |
102 | } | |
103 | ||
104 | private void drawObstacles(App app, GUI gui, Vec2D offset) { | |
105 | for (View<Obstacle> view : obstacleViews) { | |
106 |
1
1. drawObstacles : removed call to g0803/bindingofshiba/view/View::draw → KILLED |
view.draw(app, gui, offset); |
107 | } | |
108 | } | |
109 | ||
110 | private void drawMonsters(App app, GUI gui, Vec2D offset) { | |
111 | for (View<Monster> view : monsterViews) { | |
112 |
1
1. drawMonsters : removed call to g0803/bindingofshiba/view/View::draw → KILLED |
view.draw(app, gui, offset); |
113 | } | |
114 | } | |
115 | ||
116 | private void drawProjectiles(App app, GUI gui, Vec2D offset) { | |
117 | for (View<Projectile> view : projectileViews) { | |
118 |
1
1. drawProjectiles : removed call to g0803/bindingofshiba/view/View::draw → NO_COVERAGE |
view.draw(app, gui, offset); |
119 | } | |
120 | } | |
121 | ||
122 | @Override | |
123 | public void draw(App app, GUI gui, Vec2D offset) { | |
124 |
1
1. draw : removed call to g0803/bindingofshiba/view/game/RoomView::drawWalls → KILLED |
drawWalls(app, gui, offset); |
125 |
1
1. draw : removed call to g0803/bindingofshiba/view/game/RoomView::drawDoors → KILLED |
drawDoors(app, gui, offset); |
126 |
1
1. draw : removed call to g0803/bindingofshiba/view/game/RoomView::drawObstacles → KILLED |
drawObstacles(app, gui, offset); |
127 |
1
1. draw : removed call to g0803/bindingofshiba/view/game/RoomView::drawMonsters → KILLED |
drawMonsters(app, gui, offset); |
128 |
1
1. draw : removed call to g0803/bindingofshiba/view/game/RoomView::drawProjectiles → SURVIVED |
drawProjectiles(app, gui, offset); |
129 | } | |
130 | ||
131 | @Override | |
132 | public void onProjectileSpawned(ProjectileSpawnedEvent event) { | |
133 |
1
1. onProjectileSpawned : negated conditional → NO_COVERAGE |
if (event.getRoom() != getModel()) return; |
134 | ||
135 | projectileViews.add(projectileViewFactory.create(event.getProjectile(), getEventManager())); | |
136 | } | |
137 | ||
138 | @Override | |
139 | public void onProjectileDestroyed(ProjectileDestroyedEvent event) { | |
140 |
1
1. onProjectileDestroyed : negated conditional → NO_COVERAGE |
if (event.getRoom() != getModel()) return; |
141 | ||
142 |
2
1. lambda$onProjectileDestroyed$0 : negated conditional → NO_COVERAGE 2. lambda$onProjectileDestroyed$0 : replaced boolean return with true for g0803/bindingofshiba/view/game/RoomView::lambda$onProjectileDestroyed$0 → NO_COVERAGE |
projectileViews.removeIf(view -> view.getModel() == event.getProjectile()); |
143 | } | |
144 | ||
145 | @Override | |
146 | public void onMonsterDamaged(MonsterDamagedEvent event) { | |
147 |
2
1. onMonsterDamaged : negated conditional → NO_COVERAGE 2. onMonsterDamaged : negated conditional → NO_COVERAGE |
if (event.getRoom() != getModel() || event.getMonster().isAlive()) return; |
148 | ||
149 |
2
1. lambda$onMonsterDamaged$1 : negated conditional → NO_COVERAGE 2. lambda$onMonsterDamaged$1 : replaced boolean return with true for g0803/bindingofshiba/view/game/RoomView::lambda$onMonsterDamaged$1 → NO_COVERAGE |
monsterViews.removeIf(view -> view.getModel() == event.getMonster()); |
150 | } | |
151 | } | |
Mutations | ||
49 |
1.1 |
|
50 |
1.1 |
|
54 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
75 |
1.1 |
|
77 |
1.1 |
|
85 |
1.1 |
|
95 |
1.1 |
|
100 |
1.1 |
|
106 |
1.1 |
|
112 |
1.1 |
|
118 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
133 |
1.1 |
|
140 |
1.1 |
|
142 |
1.1 2.2 |
|
147 |
1.1 2.2 |
|
149 |
1.1 2.2 |