RoomView.java

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
Location : <init>
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsObstacles()]
removed call to g0803/bindingofshiba/view/game/RoomView::createViews → KILLED

50

1.1
Location : <init>
Killed by : none
removed call to g0803/bindingofshiba/events/IEventManager::addObserver → SURVIVED

54

1.1
Location : createViews
Killed by : none
removed call to java/util/List::clear → SURVIVED

55

1.1
Location : createViews
Killed by : none
removed call to java/util/List::clear → SURVIVED

56

1.1
Location : createViews
Killed by : none
removed call to java/util/List::clear → SURVIVED

75

1.1
Location : getWallTextureFromDoorPosition
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsObstacles()]
negated conditional → KILLED

77

1.1
Location : getWallTextureFromDoorPosition
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsObstacles()]
replaced return value with null for g0803/bindingofshiba/view/game/RoomView::getWallTextureFromDoorPosition → KILLED

85

1.1
Location : drawWalls
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsObstacles()]
removed call to g0803/bindingofshiba/gui/GUI::blit → KILLED

95

1.1
Location : drawDoors
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsDoorClosed()]
negated conditional → KILLED

100

1.1
Location : drawDoors
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsDoorClosed()]
removed call to g0803/bindingofshiba/gui/GUI::blit → KILLED

106

1.1
Location : drawObstacles
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsObstacles()]
removed call to g0803/bindingofshiba/view/View::draw → KILLED

112

1.1
Location : drawMonsters
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsMonsters()]
removed call to g0803/bindingofshiba/view/View::draw → KILLED

118

1.1
Location : drawProjectiles
Killed by : none
removed call to g0803/bindingofshiba/view/View::draw → NO_COVERAGE

124

1.1
Location : draw
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsObstacles()]
removed call to g0803/bindingofshiba/view/game/RoomView::drawWalls → KILLED

125

1.1
Location : draw
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsDoorClosed()]
removed call to g0803/bindingofshiba/view/game/RoomView::drawDoors → KILLED

126

1.1
Location : draw
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsObstacles()]
removed call to g0803/bindingofshiba/view/game/RoomView::drawObstacles → KILLED

127

1.1
Location : draw
Killed by : g0803.bindingofshiba.view.game.RoomViewTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.view.game.RoomViewTest]/[method:blitsMonsters()]
removed call to g0803/bindingofshiba/view/game/RoomView::drawMonsters → KILLED

128

1.1
Location : draw
Killed by : none
removed call to g0803/bindingofshiba/view/game/RoomView::drawProjectiles → SURVIVED

133

1.1
Location : onProjectileSpawned
Killed by : none
negated conditional → NO_COVERAGE

140

1.1
Location : onProjectileDestroyed
Killed by : none
negated conditional → NO_COVERAGE

142

1.1
Location : lambda$onProjectileDestroyed$0
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : lambda$onProjectileDestroyed$0
Killed by : none
replaced boolean return with true for g0803/bindingofshiba/view/game/RoomView::lambda$onProjectileDestroyed$0 → NO_COVERAGE

147

1.1
Location : onMonsterDamaged
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : onMonsterDamaged
Killed by : none
negated conditional → NO_COVERAGE

149

1.1
Location : lambda$onMonsterDamaged$1
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : lambda$onMonsterDamaged$1
Killed by : none
replaced boolean return with true for g0803/bindingofshiba/view/game/RoomView::lambda$onMonsterDamaged$1 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.7.0