1 | package g0803.bindingofshiba.gui; | |
2 | ||
3 | import com.googlecode.lanterna.TerminalSize; | |
4 | import com.googlecode.lanterna.TextColor; | |
5 | import com.googlecode.lanterna.graphics.TextGraphics; | |
6 | import com.googlecode.lanterna.screen.Screen; | |
7 | import com.googlecode.lanterna.screen.TerminalScreen; | |
8 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; | |
9 | import com.googlecode.lanterna.terminal.Terminal; | |
10 | import com.googlecode.lanterna.terminal.swing.SwingTerminalFontConfiguration; | |
11 | import g0803.bindingofshiba.bundles.Bundle; | |
12 | import g0803.bindingofshiba.gui.keyboard.Keyboard; | |
13 | import g0803.bindingofshiba.gui.keyboard.LanternaKeyboard; | |
14 | import g0803.bindingofshiba.math.Vec2D; | |
15 | import g0803.bindingofshiba.textures.ITexture; | |
16 | import java.awt.*; | |
17 | import java.io.IOException; | |
18 | ||
19 | public class LanternaGUI implements GUI { | |
20 | ||
21 | private final Screen screen; | |
22 | private final Keyboard keyboard; | |
23 | ||
24 | public LanternaGUI(Bundle<Font> fonts, int width, int height) throws IOException { | |
25 | Terminal terminal = createTerminal(fonts.get("square"), width, height); | |
26 | ||
27 | this.screen = new TerminalScreen(terminal); | |
28 |
1
1. <init> : removed call to com/googlecode/lanterna/screen/Screen::startScreen → NO_COVERAGE |
this.screen.startScreen(); |
29 | this.screen.doResizeIfNecessary(); | |
30 |
1
1. <init> : removed call to com/googlecode/lanterna/screen/Screen::setCursorPosition → NO_COVERAGE |
this.screen.setCursorPosition(null); |
31 | ||
32 | this.keyboard = new LanternaKeyboard(this.screen); | |
33 | } | |
34 | ||
35 | public LanternaGUI(Screen screen) { | |
36 | this.screen = screen; | |
37 | this.keyboard = new LanternaKeyboard(screen); | |
38 | } | |
39 | ||
40 | private Terminal createTerminal(Font font, int width, int height) throws IOException { | |
41 | TerminalSize screenSize = new TerminalSize(width, height); | |
42 | SwingTerminalFontConfiguration fontConfig = | |
43 | SwingTerminalFontConfiguration.newInstance(font); | |
44 | ||
45 |
1
1. createTerminal : replaced return value with null for g0803/bindingofshiba/gui/LanternaGUI::createTerminal → NO_COVERAGE |
return new DefaultTerminalFactory() |
46 | .setInitialTerminalSize(screenSize) | |
47 | .setPreferTerminalEmulator(true) | |
48 | .setTerminalEmulatorFontConfiguration(fontConfig) | |
49 | .setTerminalEmulatorTitle("Binding of Shiba") | |
50 | .createTerminal(); | |
51 | } | |
52 | ||
53 | @Override | |
54 | public void close() throws IOException { | |
55 |
1
1. close : removed call to com/googlecode/lanterna/screen/Screen::close → KILLED |
this.screen.close(); |
56 | } | |
57 | ||
58 | @Override | |
59 | public void clear() { | |
60 |
1
1. clear : removed call to com/googlecode/lanterna/screen/Screen::clear → KILLED |
this.screen.clear(); |
61 | } | |
62 | ||
63 | @Override | |
64 | public void refresh() throws IOException { | |
65 |
1
1. refresh : removed call to com/googlecode/lanterna/screen/Screen::refresh → KILLED |
this.screen.refresh(); |
66 | } | |
67 | ||
68 | @Override | |
69 | public void blit(int x, int y, ITexture texture) { | |
70 | TextGraphics textGraphics = this.screen.newTextGraphics(); | |
71 | ||
72 | Vec2D offset = texture.getAnchorOffset(x, y).round(); | |
73 |
3
1. blit : changed conditional boundary → SURVIVED 2. blit : Changed increment from 1 to -1 → TIMED_OUT 3. blit : negated conditional → KILLED |
for (int i = 0; i < texture.getWidth(); i++) { |
74 |
3
1. blit : changed conditional boundary → SURVIVED 2. blit : Changed increment from 1 to -1 → TIMED_OUT 3. blit : negated conditional → KILLED |
for (int j = 0; j < texture.getHeight(); j++) { |
75 | Color color = texture.getColorAt(i, j); | |
76 |
3
1. blit : changed conditional boundary → KILLED 2. blit : negated conditional → KILLED 3. blit : negated conditional → KILLED |
if (color == null || color.getAlpha() < 128) continue; |
77 | ||
78 | int red = color.getRed(); | |
79 | int green = color.getGreen(); | |
80 | int blue = color.getBlue(); | |
81 | ||
82 | Vec2D position = new Vec2D(i, j).add(offset); | |
83 | int realX = (int) position.getX(); | |
84 | int realY = (int) position.getY(); | |
85 | ||
86 | textGraphics.setBackgroundColor(new TextColor.RGB(red, green, blue)); | |
87 | textGraphics.setCharacter(realX, realY, ' '); | |
88 | } | |
89 | } | |
90 | } | |
91 | ||
92 | @Override | |
93 | public void fill(Color color) { | |
94 |
3
1. fill : changed conditional boundary → SURVIVED 2. fill : negated conditional → KILLED 3. fill : negated conditional → KILLED |
if (color == null || color.getAlpha() < 128) return; |
95 | ||
96 | TextGraphics textGraphics = this.screen.newTextGraphics(); | |
97 | ||
98 | TextColor textColor = new TextColor.RGB(color.getRed(), color.getGreen(), color.getBlue()); | |
99 | textGraphics.setBackgroundColor(textColor); | |
100 | textGraphics.fill(' '); | |
101 | } | |
102 | ||
103 | @Override | |
104 | public Keyboard getKeyboard() { | |
105 |
1
1. getKeyboard : replaced return value with null for g0803/bindingofshiba/gui/LanternaGUI::getKeyboard → NO_COVERAGE |
return keyboard; |
106 | } | |
107 | } | |
Mutations | ||
28 |
1.1 |
|
30 |
1.1 |
|
45 |
1.1 |
|
55 |
1.1 |
|
60 |
1.1 |
|
65 |
1.1 |
|
73 |
1.1 2.2 3.3 |
|
74 |
1.1 2.2 3.3 |
|
76 |
1.1 2.2 3.3 |
|
94 |
1.1 2.2 3.3 |
|
105 |
1.1 |