finished game tracking
This commit is contained in:
parent
c30f4c3731
commit
dc3923caad
4 changed files with 10 additions and 10 deletions
|
@ -6,7 +6,6 @@ import com.github.stachelbeere1248.zombiesutils.game.GameMode;
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.Map;
|
import com.github.stachelbeere1248.zombiesutils.game.Map;
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
|
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
|
||||||
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
|
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
|
||||||
import com.github.stachelbeere1248.zombiesutils.timer.recorder.FileManager;
|
|
||||||
import com.github.stachelbeere1248.zombiesutils.timer.recorder.files.GameFile;
|
import com.github.stachelbeere1248.zombiesutils.timer.recorder.files.GameFile;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.ChatComponentText;
|
import net.minecraft.util.ChatComponentText;
|
||||||
|
@ -71,7 +70,7 @@ public class Timer {
|
||||||
if (passedRound == (byte) 1) pbTracking = true;
|
if (passedRound == (byte) 1) pbTracking = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileManager.
|
gameFile.setSegment(passedRound,roundTime);
|
||||||
RecordManager.compareSegment(passedRound, roundTime, category);
|
RecordManager.compareSegment(passedRound, roundTime, category);
|
||||||
if (pbTracking) RecordManager.compareBest(passedRound, gameTime, category);
|
if (pbTracking) RecordManager.compareBest(passedRound, gameTime, category);
|
||||||
} catch (IndexOutOfBoundsException exception) {
|
} catch (IndexOutOfBoundsException exception) {
|
||||||
|
|
|
@ -26,19 +26,19 @@ public class FileManager {
|
||||||
|
|
||||||
return gson.fromJson(dataJson, CategoryData.class);
|
return gson.fromJson(dataJson, CategoryData.class);
|
||||||
}
|
}
|
||||||
public static void createDataFile(ISplitsData splitsData, @NotNull SplitsFile splitsFile) {
|
public static void createDataFile(@NotNull SplitsFile splitsFile) {
|
||||||
try {
|
try {
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
splitsFile.getParentFile().mkdirs();
|
splitsFile.getParentFile().mkdirs();
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
splitsFile.createNewFile();
|
splitsFile.createNewFile();
|
||||||
writeDataToFile(splitsData, splitsFile);
|
writeDataToFile(splitsFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void writeDataToFile(@NotNull ISplitsData splitsData, SplitsFile splitsFile) throws IOException {
|
public static void writeDataToFile(SplitsFile splitsFile) throws IOException {
|
||||||
FileUtils.writeStringToFile(splitsFile, splitsData.toJSON(), StandardCharsets.US_ASCII);
|
FileUtils.writeStringToFile(splitsFile, splitsFile.getData().toJSON(), StandardCharsets.US_ASCII);
|
||||||
}
|
}
|
||||||
public static CategoryData categoryReadOrCreate(CategoryFile file) {
|
public static CategoryData categoryReadOrCreate(CategoryFile file) {
|
||||||
CategoryData data;
|
CategoryData data;
|
||||||
|
@ -46,7 +46,7 @@ public class FileManager {
|
||||||
data = FileManager.readDataFromFile(file);
|
data = FileManager.readDataFromFile(file);
|
||||||
} catch (FileNotFoundException ignored) {
|
} catch (FileNotFoundException ignored) {
|
||||||
data = new CategoryData(file.getGameMode().getMap());
|
data = new CategoryData(file.getGameMode().getMap());
|
||||||
FileManager.createDataFile(data, file);
|
FileManager.createDataFile(file);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class CategoryFile extends SplitsFile {
|
||||||
public void setBestSegment(int round, short ticks) {
|
public void setBestSegment(int round, short ticks) {
|
||||||
data.setBestSegment(round-1, ticks);
|
data.setBestSegment(round-1, ticks);
|
||||||
|
|
||||||
try { FileManager.writeDataToFile(data,this); }
|
try { FileManager.writeDataToFile(this); }
|
||||||
catch (IOException e) { throw new RuntimeException(e); }
|
catch (IOException e) { throw new RuntimeException(e); }
|
||||||
}
|
}
|
||||||
public int getPersonalBest(int round) {
|
public int getPersonalBest(int round) {
|
||||||
|
@ -36,7 +36,7 @@ public class CategoryFile extends SplitsFile {
|
||||||
public void setPersonalBest(int round, int ticks) {
|
public void setPersonalBest(int round, int ticks) {
|
||||||
data.setPersonalBest(round-1, ticks);
|
data.setPersonalBest(round-1, ticks);
|
||||||
|
|
||||||
try { FileManager.writeDataToFile(data,this); }
|
try { FileManager.writeDataToFile(this); }
|
||||||
catch (IOException e) { throw new RuntimeException(e); }
|
catch (IOException e) { throw new RuntimeException(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ public class GameFile extends SplitsFile {
|
||||||
public GameFile(String serverNumber, Map map) {
|
public GameFile(String serverNumber, Map map) {
|
||||||
super("zombies" + File.separator + "runs", formattedTime() + "_" + serverNumber + ".times");
|
super("zombies" + File.separator + "runs", formattedTime() + "_" + serverNumber + ".times");
|
||||||
data = new GameData(map);
|
data = new GameData(map);
|
||||||
|
FileManager.createDataFile(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @NotNull String formattedTime() {
|
private static @NotNull String formattedTime() {
|
||||||
|
@ -30,7 +31,7 @@ public class GameFile extends SplitsFile {
|
||||||
public void setSegment(int round, short ticks) {
|
public void setSegment(int round, short ticks) {
|
||||||
data.setSegment(round-1, ticks);
|
data.setSegment(round-1, ticks);
|
||||||
|
|
||||||
try { FileManager.writeDataToFile(data,this); }
|
try { FileManager.writeDataToFile(this); }
|
||||||
catch (IOException e) { throw new RuntimeException(e); }
|
catch (IOException e) { throw new RuntimeException(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue