-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all the data to an image.json file, to allow changing what is di…
…splayed on screen, and where.
- Loading branch information
Showing
10 changed files
with
406 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
255 changes: 173 additions & 82 deletions
255
src/main/java/alexiil/mods/load/MinecraftDisplayer.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package alexiil.mods.load.json; | ||
|
||
public class Area { | ||
public final int x; | ||
public final int y; | ||
public final int width; | ||
public final int height; | ||
|
||
public Area(int x, int y, int width, int height) { | ||
this.x = x; | ||
this.y = y; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ImageTexture [x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package alexiil.mods.load.json; | ||
|
||
public enum EPosition { | ||
TOP_LEFT(-1, -1), TOP_CENTER(0, -1), TOP_RIGHT(1, -1), CENTER_LEFT(-1, 0), CENTER(0, 0), CENTER_RIGHT(1, 0), BOTTOM_LEFT(-1, 1), BOTTOM_CENTER(0, | ||
1), BOTTOM_RIGHT(1, 1); | ||
|
||
private final int x; | ||
private final int y; | ||
|
||
private EPosition(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
private int transform(int switcher, int coord, int screenThing) { | ||
switch (switcher) { | ||
case -1: | ||
return coord; | ||
case 0: | ||
return screenThing / 2 - coord; | ||
case 1: | ||
return screenThing - coord; | ||
} | ||
throw new Error("switcher (" + switcher + ") != -1, 0 or 1 (" + this.toString() + ")"); | ||
} | ||
|
||
public int transformX(int x, int screenWidth) { | ||
return transform(this.x, x, screenWidth); | ||
} | ||
|
||
public int transformY(int y, int screenHeight) { | ||
return transform(this.y, y, screenHeight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package alexiil.mods.load.json; | ||
|
||
public enum EType { | ||
STATIC, STATIC_TEXT, DYNAMIC_TEXT_STATUS, DYNAMIC_TEXT_PERCENTAGE, DYNAMIC_PERCENTAGE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package alexiil.mods.load.json; | ||
|
||
public class ImageRender { | ||
public final String resourceLocation; | ||
public final EPosition positionType; | ||
public final EType type; | ||
public final Area texture; | ||
public final Area position; | ||
public final String colour; | ||
public final String text; | ||
|
||
public ImageRender(String resourceLocation, EPosition positionType, EType type, Area texture, Area position, String colour, String text) { | ||
this.resourceLocation = resourceLocation; | ||
this.positionType = positionType; | ||
this.type = type; | ||
this.texture = texture; | ||
this.position = position; | ||
this.colour = colour; | ||
this.text = text; | ||
} | ||
|
||
public ImageRender(String resourceLocation, EPosition positionType, EType type, Area texture, Area position) { | ||
this(resourceLocation, positionType, type, texture, position, null, null); | ||
} | ||
|
||
public int transformX(int screenWidth) { | ||
return positionType.transformX(position.x, screenWidth - position.width); | ||
} | ||
|
||
public int transformY(int screenWidth) { | ||
return positionType.transformY(position.y, screenWidth - position.height); | ||
} | ||
|
||
public int getColour() { | ||
if (colour == null) | ||
return 0xFFFFFF; | ||
else { | ||
try { | ||
return Integer.parseInt(colour, 16); | ||
} | ||
catch (NumberFormatException nfe) { | ||
return 0xFFFFFF; | ||
} | ||
} | ||
} | ||
|
||
private float getColourPart(int bitStart) { | ||
return ((getColour() >> bitStart) & 0xFF) / 256F; | ||
} | ||
|
||
public float getRed() { | ||
return getColourPart(16); | ||
} | ||
|
||
public float getGreen() { | ||
return getColourPart(8); | ||
} | ||
|
||
public float getBlue() { | ||
return getColourPart(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package alexiil.mods.load.json; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
public class JsonConfig<T> { | ||
private final Class<T> clazz; | ||
private final File file; | ||
private final T defaultConfig; | ||
|
||
public JsonConfig(File file, Class<T> clazz, T defaultConfig) { | ||
this.file = file; | ||
this.clazz = clazz; | ||
this.defaultConfig = defaultConfig; | ||
} | ||
|
||
/** Overwrite any existing config: Treat it as a default config */ | ||
public void createNew() { | ||
BufferedWriter writer = null; | ||
try { | ||
writer = new BufferedWriter(new FileWriter(file)); | ||
writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(defaultConfig)); | ||
writer.close(); | ||
} | ||
catch (IOException e1) { | ||
e1.printStackTrace(); | ||
} | ||
finally { | ||
if (writer != null) | ||
try { | ||
writer.close(); | ||
} | ||
catch (IOException e1) { | ||
e1.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public T load() { | ||
BufferedReader reader = null; | ||
try { | ||
reader = new BufferedReader(new FileReader(file)); | ||
return new Gson().fromJson(reader, clazz); | ||
} | ||
catch (FileNotFoundException e) { | ||
createNew(); | ||
} | ||
finally { | ||
if (reader != null) | ||
try { | ||
reader.close(); | ||
} | ||
catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return defaultConfig; | ||
} | ||
} |