Skip to content

Commit

Permalink
Merge pull request #1 from AnvilloyDevStudio/plus-pr-504
Browse files Browse the repository at this point in the history
Add Debug Panel
  • Loading branch information
BenCheung0422 authored Jan 20, 2025
2 parents 5291bed + 9d0a840 commit 19b3ecc
Show file tree
Hide file tree
Showing 29 changed files with 2,785 additions and 112 deletions.
1 change: 1 addition & 0 deletions src/client/java/minicraft/core/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected Game() {
public static List<String> notifications = new ArrayList<>();

public static int MAX_FPS;
public static boolean debug = false;

// DISPLAY
static Display currentDisplay = null;
Expand Down
2 changes: 2 additions & 0 deletions src/client/java/minicraft/core/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static void parseArgs(String[] args) {
saveDir = args[i];
} else if (args[i].equalsIgnoreCase("--fullscreen")) {
Updater.FULLSCREEN = true;
} else if (args[i].equalsIgnoreCase("--debug")) { // Basic debugging flag
debug = true;
} else if (args[i].equalsIgnoreCase("--debug-log-time")) {
Logging.logTime = true;
} else if (args[i].equalsIgnoreCase("--debug-log-thread")) {
Expand Down
81 changes: 6 additions & 75 deletions src/client/java/minicraft/core/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import minicraft.level.tile.Tile;
import minicraft.level.tile.Tiles;
import minicraft.saveload.Save;
import minicraft.screen.DebugPanelDisplay;
import minicraft.screen.Display;
import minicraft.screen.EndGameDisplay;
import minicraft.screen.LevelTransitionDisplay;
Expand All @@ -30,6 +31,7 @@ private Updater() {
public static float gamespeed = 1; // Measured in MULTIPLES OF NORMSPEED.
public static boolean paused = true; // If the game is paused.

public static boolean timeFlow = true;
public static int tickCount = 0; // The number of ticks since the beginning of the game day.
static int time = 0; // Facilites time of day / sunlight.
public static final int dayLength = 64800; // This value determines how long one game day is.
Expand Down Expand Up @@ -92,7 +94,6 @@ static void updateFullscreen() {
// VERY IMPORTANT METHOD!! Makes everything keep happening.
// In the end, calls menu.tick() if there's a menu, or level.tick() if no menu.
public static void tick() {

if (input.getMappedKey("FULLSCREEN").isClicked()) {
Updater.FULLSCREEN = !Updater.FULLSCREEN;
Updater.updateFullscreen();
Expand Down Expand Up @@ -157,7 +158,7 @@ public static void tick() {
}

// Increment tickCount if the game is not paused
if (!paused) setTime(tickCount + 1);
if (!paused && timeFlow) setTime(tickCount + 1);

// SCORE MODE ONLY

Expand Down Expand Up @@ -219,79 +220,9 @@ public static void tick() {
}

// For debugging only
{
// Quick Level change: move the player for -1, or 1 levels
if (isMode("minicraft.settings.mode.creative") && input.getMappedKey("SHIFT-S").isClicked()) {
Game.setDisplay(new LevelTransitionDisplay(-1));

} else if (isMode("minicraft.settings.mode.creative") && input.getMappedKey("SHIFT-W").isClicked()) {
Game.setDisplay(new LevelTransitionDisplay(1));
}

if (input.getMappedKey("F3-L").isClicked()) {
// Print all players on all levels, and their coordinates.
Logging.WORLD.info("Printing players on all levels.");
for (Level value : levels) {
if (value == null) continue;
value.printEntityLocs(Player.class);
}
}

// Host-only cheats.
if (input.getMappedKey("F3-T-1").isClicked()) changeTimeOfDay(Time.Morning);
if (input.getMappedKey("F3-T-2").isClicked()) changeTimeOfDay(Time.Day);
if (input.getMappedKey("F3-T-3").isClicked()) changeTimeOfDay(Time.Evening);
if (input.getMappedKey("F3-T-4").isClicked()) changeTimeOfDay(Time.Night);

String prevMode = (String) Settings.get("mode");
if (input.getMappedKey("F3-F4-2").isClicked()) {
Settings.set("mode", "minicraft.settings.mode.creative");
Logging.WORLDNAMED.trace("Game mode changed from {} into {}.", prevMode, "minicraft.settings.mode.creative");
}
if (input.getMappedKey("F3-F4-1").isClicked()) {
Settings.set("mode", "minicraft.settings.mode.survival");
Logging.WORLDNAMED.trace("Game mode changed from {} into {}.", prevMode, "minicraft.settings.mode.survival");
}
if (input.getMappedKey("F3-F4-3").isClicked()) {
Settings.set("mode", "minicraft.settings.mode.score");
Logging.WORLDNAMED.trace("Game mode changed from {} into {}.", prevMode, "minicraft.settings.mode.score");
}

if (isMode("minicraft.settings.mode.score") && input.getMappedKey("F3-SHIFT-T").isClicked()) {
scoreTime = normSpeed * 5; // 5 seconds
}

float prevSpeed = gamespeed;
if (input.getMappedKey("F3-S-0").isClicked()) {
gamespeed = 1;
Logging.WORLDNAMED.trace("Tick speed reset from {} into 1.", prevSpeed);
}
if (input.getMappedKey("F3-S-equals").isClicked()) {
if (gamespeed < 1) gamespeed *= 2;
else if (normSpeed * gamespeed < 2000) gamespeed++;
Logging.WORLDNAMED.trace("Tick speed increased from {} into {}.", prevSpeed, gamespeed);
}
if (input.getMappedKey("F3-S-minus").isClicked()) {
if (gamespeed > 1) gamespeed--;
else if (normSpeed * gamespeed > 5) gamespeed /= 2;
Logging.WORLDNAMED.trace("Tick speed decreased from {} into {}.", prevSpeed, gamespeed);
}

if (input.getMappedKey("F3-h").isClicked()) player.health--;
if (input.getMappedKey("F3-b").isClicked()) player.hunger--;

if (input.getMappedKey("F3-M-0").isClicked()) player.moveSpeed = 1;
if (input.getMappedKey("F3-M-equals").isClicked()) player.moveSpeed++;
if (input.getMappedKey("F3-M-minus").isClicked() && player.moveSpeed > 1)
player.moveSpeed--; // -= 0.5D;

if (input.getMappedKey("F3-u").isClicked()) {
levels[currentLevel].setTile(player.x >> 4, player.y >> 4, Tiles.get("Stairs Up"));
}
if (input.getMappedKey("F3-d").isClicked()) {
levels[currentLevel].setTile(player.x >> 4, player.y >> 4, Tiles.get("Stairs Down"));
}
} // End debug only cond.
if (debug && currentDisplay == null && input.getMappedKey("F4").isClicked()) {
Game.setDisplay(new DebugPanelDisplay());
}
} // End "menu-null" conditional
} // End hasfocus conditional
} // End tick()
Expand Down
1 change: 1 addition & 0 deletions src/client/java/minicraft/core/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static void initWorld()
Bed.removePlayers();
Updater.gameTime = 0;
Updater.gamespeed = 1;
Updater.timeFlow = true;
lastWorldEnterTime = System.currentTimeMillis();

Updater.changeTimeOfDay(Updater.Time.Morning); // Resets tickCount; game starts in the day, so that it's nice and bright.
Expand Down
3 changes: 2 additions & 1 deletion src/client/java/minicraft/core/io/Localization.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package minicraft.core.io;

import minicraft.core.Game;
import minicraft.util.Logging;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
Expand Down Expand Up @@ -44,7 +45,7 @@ public static String getLocalized(String key, Object... arguments) {

String localString = localization.get(key);

if (localString == null) {
if (localString == null && Game.debug) {
if (!knownUnlocalizedStrings.containsKey(selectedLocale))
knownUnlocalizedStrings.put(selectedLocale, new HashSet<>());
if (!knownUnlocalizedStrings.get(selectedLocale).contains(key)) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/java/minicraft/core/io/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class Settings {
options.put("quests", new BooleanEntry("minicraft.settings.quests", false));
options.put("showquests", new BooleanEntry("minicraft.settings.show_quests", true));

options.get("mode").setChangeAction(value ->
options.get("mode").setChangeListener(value ->
options.get("scoretime").setVisible("minicraft.settings.mode.score".equals(value))
);
}
Expand Down
14 changes: 0 additions & 14 deletions src/client/java/minicraft/entity/mob/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,6 @@ public HashMap<PotionType, Integer> getPotionEffects() {
public void tick() {
if (level == null || isRemoved()) return;
if (Game.getDisplay() != null) return; // Don't tick player when menu is open
if (input.getMappedKey("F3-Y").isClicked()) {
World.scheduleLevelChange(1);
return;
} else if (input.getMappedKey("F3-H").isClicked()) {
World.scheduleLevelChange(-1);
return;
}

super.tick(); // Ticks Mob.java

Expand Down Expand Up @@ -553,13 +546,6 @@ public void tick() {
LoadingDisplay.setPercentage(0);
new Save(WorldSelectDisplay.getWorldName());
}
//debug feature:
if (input.inputDown("F3-p")) { // Remove all potion effects
for (PotionType potionType : potioneffects.keySet()) {
PotionItem.applyPotion(this, potionType, false);
}
}
}

if (attackTime > 0) {
attackTime--;
Expand Down
8 changes: 8 additions & 0 deletions src/client/java/minicraft/item/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class Items {

Expand Down Expand Up @@ -144,5 +148,9 @@ public static class CreativeModeInventory extends Inventory {
});
}
}

public static Set<String> getRegisteredItemKeys() {
return items.stream().map(Item::getName).collect(Collectors.toCollection(TreeSet::new));
}
}

3 changes: 3 additions & 0 deletions src/client/java/minicraft/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public static String getDepthString(int depth) {

private static final int MOB_SPAWN_FACTOR = 100; // The chance of a mob actually trying to spawn when trySpawn is called equals: mobCount / maxMobCount * MOB_SPAWN_FACTOR. so, it basically equals the chance, 1/number, of a mob spawning when the mob cap is reached. I hope that makes sense...

// TODO Level#w and Level#h should be stored in a world instead of being saved separately
// as the level widths and heights should be the same within the same world
// to ensure that there are no errors occurring and by the game design.
public int w, h; // Width and height of the level
private final long seed; // The used seed that was used to generate the world

Expand Down
2 changes: 1 addition & 1 deletion src/client/java/minicraft/level/tile/StairsTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void handleDamage(Level level, int x, int y, Entity source, @Nullable
@Override
public @Nullable Item take(Level level, int x, int y, Player player) {
// Makes it so you can remove the stairs if you are in creative and debug mode.
if (Game.isMode("minicraft.settings.mode.creative")) {
if (Game.isMode("minicraft.settings.mode.creative") && Game.debug) {
level.setTile(x, y, Tiles.get("Grass"));
Sound.play("monsterhurt");
}
Expand Down
8 changes: 7 additions & 1 deletion src/client/java/minicraft/level/tile/Tiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.HashSet;

public final class Tiles {
/// Idea: to save tile names while saving space, I could encode the names in base 64 in the save file...^M
Expand Down Expand Up @@ -293,4 +295,8 @@ public static String getName(String descriptName) {
public static HashMap<Short, Tile> getAll() {
return new HashMap<>(tiles);
}

public static Set<String> getRegisteredTileKeys() {
return tiles.values().stream().map(t -> t.name).collect(Collectors.toCollection(TreeSet::new));
}
}
2 changes: 2 additions & 0 deletions src/client/java/minicraft/network/Analytics.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import kong.unirest.HttpResponse;
import kong.unirest.Unirest;
import kong.unirest.UnirestException;
import minicraft.core.Game;
import org.jetbrains.annotations.Nullable;
import org.tinylog.Logger;

Expand Down Expand Up @@ -57,6 +58,7 @@ public Future<HttpResponse<Empty>> ping() {

@Nullable
public Future<HttpResponse<Empty>> ping(int value) {
if (Game.debug) return null;
final String url = "https://pingdat.io?t=" + token + "&v=" + value;

return Unirest.get(url).asEmptyAsync(new Callback<Empty>() {
Expand Down
Loading

0 comments on commit 19b3ecc

Please sign in to comment.