Skip to content

Commit 74c7065

Browse files
committed
More Abstraction and a few changes to existing API
1 parent e7cc80b commit 74c7065

File tree

13 files changed

+177
-51
lines changed

13 files changed

+177
-51
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package de.geolykt.starloader.api;
2+
3+
public interface Identifiable {
4+
5+
/**
6+
* Obtains the usually unique (numeric) identifier of the object. There should be no duplicates.
7+
* However due to the way the game operates, there might be duplicates, which can have unintended consquences.
8+
* @return The UID of the empire
9+
*/
10+
public int getUID();
11+
12+
}

src/main/java/de/geolykt/starloader/api/empire/ActiveEmpire.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.jetbrains.annotations.NotNull;
77
import org.jetbrains.annotations.Nullable;
88

9+
import de.geolykt.starloader.api.Metadatable;
910
import snoddasmannen.galimulator.Fleet;
1011
import snoddasmannen.galimulator.Religion;
1112
import snoddasmannen.galimulator.actors.Flagship;
@@ -14,7 +15,7 @@
1415
/**
1516
* Interface for any empire that is still in the game
1617
*/
17-
public interface ActiveEmpire extends Empire {
18+
public interface ActiveEmpire extends Empire, Metadatable {
1819

1920
/**
2021
* Assigns a {@link StateActor} to the empire.

src/main/java/de/geolykt/starloader/api/empire/Empire.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import org.jetbrains.annotations.NotNull;
44

55
import de.geolykt.starloader.api.Galimulator;
6-
import de.geolykt.starloader.api.Metadatable;
6+
import de.geolykt.starloader.api.Identifiable;
77
import snoddasmannen.galimulator.GalColor;
88

99
/**
1010
* Base interface for any empires that exist in the game, whether collapsed or not
1111
*/
12-
public interface Empire extends Dateable, Metadatable {
12+
public interface Empire extends Dateable, Identifiable {
1313

1414
/**
1515
* The age of an empire is counted in years and ceases to stop increasing once the empire has collapsed.
@@ -45,12 +45,6 @@ public default int getAge() {
4545
*/
4646
public int getStarCount();
4747

48-
/**
49-
* Obtains the unique (numeric) identifier of the empire. There should be no duplicates.
50-
* @return The UID of the empire
51-
*/
52-
public int getUID();
53-
5448
/**
5549
* Empires are usually not in the collapse state, however sometimes this is true, albeit rare.
5650
* @return true if the empire ceased to exist

src/main/java/de/geolykt/starloader/api/empire/Star.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
import com.badlogic.gdx.math.Vector2;
1111

1212
import de.geolykt.starloader.api.Galimulator;
13+
import de.geolykt.starloader.api.Identifiable;
1314
import de.geolykt.starloader.api.Metadatable;
1415
import snoddasmannen.galimulator.Religion;
1516

1617
/**
1718
* Wrapper interface for Stars
1819
*/
19-
public interface Star extends Metadatable {
20+
public interface Star extends Identifiable, Metadatable {
2021

2122
/**
2223
* Adds a star to the neighbour lists. Please note that you likely do not want to call this method yourself.
@@ -97,16 +98,6 @@ public interface Star extends Metadatable {
9798
*/
9899
public @NotNull Vector<Star> getNeighboursRecursive(int recurseDepth);
99100

100-
/**
101-
* The unique identifier of the star should not change throughout it's lifecycle,
102-
* however nothing forbids it from actually doing that.
103-
* However it should not be done by any extension as this likely breaks something.
104-
* Additionally nothing verifies it's uniqueness, however if it is not unique most lookup techniques will fail
105-
* or return unexpected results.
106-
* @return The unique identifier that represents the star
107-
*/
108-
public int getUniqueId();
109-
110101
/**
111102
* Obtains the wealth of the star.
112103
* Wealthier stars are harder to take and have more additional extras for them and the empire owning the star
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package de.geolykt.starloader.api.gui;
2+
3+
public interface AutocloseableDialog {
4+
5+
/**
6+
* Obtains the time at which the dialog will be closed automatically, or -1 if automatic closing is not done.
7+
* The time is relative to the starting point of {@link System#currentTimeMillis()} and is in milliseconds.
8+
*/
9+
public long getAutocloseTime();
10+
11+
}
Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
11
package de.geolykt.starloader.api.gui;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
6-
import org.jetbrains.annotations.NotNull;
7-
import org.jetbrains.annotations.Nullable;
8-
9-
import de.geolykt.starloader.impl.DialogCloseListenerWrapper;
10-
import snoddasmannen.galimulator.Space;
11-
import snoddasmannen.galimulator.ui.bh;
12-
133
/**
14-
* A simple wrapper around the dialog, a graphical component of Galimulator
4+
* A basic dialog.
155
*/
16-
public class BasicDialog {
6+
public interface BasicDialog extends AutocloseableDialog, ButtonDialog {
177

18-
/**
19-
* Creates and displays a dialog
20-
* @param title The title of the dialog
21-
* @param description The description (content/body) of the dialog
22-
* @param choices The buttons of the dialog
23-
* @param listeners The listeners that are applied to the dialog
24-
* @param duration The duration that the dialog should stay opened in seconds
25-
* @param playSFX True if the close sound should be used.
26-
*/
27-
public BasicDialog(@NotNull String title, @NotNull String description, @Nullable List<String> choices,
28-
@NotNull ArrayList<BasicDialogCloseListener> listeners, int duration, boolean playSFX) {
29-
bh dialog = Space.a(title, description, choices, duration, null, true);
30-
dialog.a(new DialogCloseListenerWrapper(listeners, playSFX));
31-
}
328
}

src/main/java/de/geolykt/starloader/api/gui/BasicDialogBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ public BasicDialogBuilder supressCloseSound() {
111111
* @return The dialog that was built via the operation.
112112
*/
113113
public BasicDialog buildAndShow() {
114-
return new BasicDialog(title, description, choices, listeners, duration, playSFX);
114+
return new de.geolykt.starloader.impl.BasicDialog(title, description, choices, listeners, duration, playSFX);
115115
}
116116
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package de.geolykt.starloader.api.gui;
2+
3+
import org.jetbrains.annotations.Nullable;
4+
5+
public interface ButtonDialog {
6+
7+
/**
8+
* This call simulates a button click. However this method can also be called if the dialog was closed automatically.
9+
* @param buttonPressed Some magic value that I don't fully understand or null, if the dialog was closed automatically
10+
*/
11+
public void close(@Nullable Object buttonPressed); // TODO understand the parameter
12+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package de.geolykt.starloader.apimixins;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.Shadow;
6+
7+
import de.geolykt.starloader.api.Galimulator;
8+
import de.geolykt.starloader.api.empire.Empire;
9+
import snoddasmannen.galimulator.GalColor;
10+
11+
@Mixin(snoddasmannen.galimulator.EmpireAnnals.class)
12+
public class EmpireAnnalsMixins implements Empire {
13+
14+
@Shadow
15+
public int empireId;
16+
17+
@Shadow
18+
public int birthYear;
19+
20+
@Shadow
21+
public int deathYear;
22+
23+
@Shadow
24+
public String name;
25+
26+
@Shadow
27+
public String nameIdentifier;
28+
29+
@Shadow
30+
public GalColor color;
31+
32+
@Override
33+
public int getFoundationYear() {
34+
return birthYear;
35+
}
36+
37+
@Override
38+
public int getUID() {
39+
return empireId;
40+
}
41+
42+
@Override
43+
public int getCollapseYear() {
44+
return deathYear;
45+
}
46+
47+
@Override
48+
public @NotNull GalColor getColor() {
49+
return color;
50+
}
51+
52+
@Override
53+
public @NotNull String getEmpireName() {
54+
return name;
55+
}
56+
57+
@Override
58+
public int getStarCount() {
59+
if (deathYear != -1) {
60+
return 0;
61+
} else {
62+
return Galimulator.getEmpirePerUID(getUID()).getStarCount();
63+
}
64+
}
65+
66+
@Override
67+
public boolean hasCollapsed() {
68+
return deathYear != -1;
69+
}
70+
71+
}

src/main/java/de/geolykt/starloader/apimixins/StarMixins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public Vector<Integer> getNeighbourIDs() {
142142
}
143143

144144
@Override
145-
public int getUniqueId() {
145+
public int getUID() {
146146
return id;
147147
}
148148

0 commit comments

Comments
 (0)