debug logger

bottom-bar
Ivory 2023-01-28 22:15:43 -05:00
parent b1171ed4eb
commit 8bcc7b0714
22 changed files with 115 additions and 85 deletions

View File

@ -92,7 +92,6 @@ public class App {
});
glfwSetScrollCallback(window, (long window, double xOffset, double yOffset) -> {
DebugTab.log("Scroll " + yOffset);
if(yOffset > 0)
game.scrollUp();
else if(yOffset < 0)
@ -114,7 +113,8 @@ public class App {
if(button == GLFW_MOUSE_BUTTON_LEFT) { mouseLeft = action == 1; return; }
if(button == GLFW_MOUSE_BUTTON_RIGHT) { mouseRight = action == 1; return; }
if(button == GLFW_MOUSE_BUTTON_MIDDLE) { mouseMiddle = action == 1; return ; }
System.out.println("Mouse: action " + action + " : button " + button);
DebugTab.log("Mouse: action " + action + " : button " + button);
});
// Get the thread stack and push a new frame

View File

@ -1,6 +1,8 @@
package xyz.valnet.engine.graphics;
public class Color {
import java.io.Serializable;
public class Color implements Serializable {
public final float r, g, b, a;
public static Color black = new Color(0, 0, 0);

View File

@ -90,7 +90,6 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
private Button getButton(String id) {
if(hasButton(id)) return buttons.get(id);
System.out.println("Created new Button");
Button btn = new Button(Assets.uiFrame, "", 0, 0, 0, 0, 0);
btn.registerClickListener((target) -> {
if(!clicks.containsKey(target)) clicks.put(target, 0);

View File

@ -1,6 +1,8 @@
package xyz.valnet.engine.math;
public class Box {
import java.io.Serializable;
public class Box implements Serializable {
public final float x, y, w, h, x2, y2;
public final Vector2f a, b;

View File

@ -6,6 +6,8 @@ import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
public class CustomObjectDeserializer extends ObjectInputStream {
@ -20,8 +22,8 @@ public class CustomObjectDeserializer extends ObjectInputStream {
try {
localClass = Class.forName(resultClassDescriptor.getName());
} catch (ClassNotFoundException e) {
System.out.println("No local class for " + resultClassDescriptor.getName());
System.out.println(e);
DebugTab.log("No local class for " + resultClassDescriptor.getName());
DebugTab.log(e);
return resultClassDescriptor;
}
ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
@ -33,8 +35,8 @@ public class CustomObjectDeserializer extends ObjectInputStream {
s.append("local serialVersionUID = ").append(localSUID);
s.append(" stream serialVersionUID = ").append(streamSUID);
Exception e = new InvalidClassException(s.toString());
System.out.println("Potentially Fatal Deserialization Operation.");
System.out.println(e);
DebugTab.log("Potentially Fatal Deserialization Operation.");
DebugTab.log(e);
resultClassDescriptor = localClassDescriptor; // Use local class descriptor for deserialization
}
}

View File

@ -17,6 +17,7 @@ import java.util.stream.Collectors;
import xyz.valnet.engine.App;
import xyz.valnet.engine.math.Box;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
public abstract class SceneGraph implements IScene {
protected final List<GameObject> objects = new ArrayList<GameObject>();
@ -159,7 +160,7 @@ public abstract class SceneGraph implements IScene {
public void dump() {
for(GameObject go : objects)
System.out.println(go);
DebugTab.log(go);
}
private void dump(List<GameObject> objects) {
@ -171,7 +172,7 @@ public abstract class SceneGraph implements IScene {
count.put(clazz, count.get(clazz) + 1);
}
for(Entry<Class<? extends GameObject>, Integer> entry : count.entrySet()) {
System.out.println("" + entry.getValue() + "x " + entry.getKey().getSimpleName());
DebugTab.log("" + entry.getValue() + "x " + entry.getKey().getSimpleName());
}
}
@ -186,15 +187,15 @@ public abstract class SceneGraph implements IScene {
FileOutputStream file = new FileOutputStream("SAVE_DATA.TXT");
ObjectOutputStream out = new ObjectOutputStream(file);
ArrayList<GameObject> toSave = getNonTransientObjects();
System.out.println("=== [ SAVING ] ===");
DebugTab.log("=== [ SAVING ] ===");
dump(toSave);
out.writeObject(toSave);
out.close();
file.close();
System.out.println("=== [ SAVED ] ===");
DebugTab.log("=== [ SAVED ] ===");
} catch (Exception e) {
e.printStackTrace();
System.out.println("=== [ FAILED ] ===");
DebugTab.log("=== [ FAILED ] ===");
}
saveFlag = false;
}
@ -207,7 +208,7 @@ public abstract class SceneGraph implements IScene {
List<GameObject> newObjects = (List<GameObject>) input.readObject();
input.close();
file.close();
System.out.println("imported " + newObjects.size() + " objects");
DebugTab.log("imported " + newObjects.size() + " objects");
ArrayList<GameObject> toRemove = getNonTransientObjects();
for(GameObject obj : toRemove) {
@ -251,7 +252,7 @@ public abstract class SceneGraph implements IScene {
@Override
public final void keyPress(int key) {
System.out.println("keyCode: " + key);
DebugTab.log("keyCode: " + key);
keys.add(key);
for(IKeyboardListener ikbl : getAll(IKeyboardListener.class)) {
ikbl.keyPress(key);

View File

@ -0,0 +1,5 @@
package xyz.valnet.hadean;
public class Constants {
public static final float animationSpeed = 20;
}

View File

@ -61,8 +61,7 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
}
Vector2f move = direction.normalize().multiply(dTime / 5f);
// move = Vector2f.east;
// System.out.println(move);
focus = focus.add(move);
} else {
Vector2f dragDifference = screen2world(App.mouseX, App.mouseY).subtract(focus);

View File

@ -1,5 +1,7 @@
package xyz.valnet.hadean.gameobjects;
import static xyz.valnet.engine.util.Math.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -9,16 +11,16 @@ import java.util.Set;
import xyz.valnet.engine.graphics.IModalUI;
import xyz.valnet.engine.graphics.ImmediateUI;
import xyz.valnet.engine.scenegraph.ITransient;
import xyz.valnet.hadean.Constants;
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
import xyz.valnet.hadean.gameobjects.ui.ExclusivityManager;
import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
import xyz.valnet.hadean.util.detail.Detail;
import static xyz.valnet.engine.util.Math.lerp;
public class SelectionUI extends ImmediateUI implements ISelectionChangeListener, ITransient, IModalUI {
private class SelectedByType extends HashMap<Class<? extends ISelectable>, List<ISelectable>> {}
@ -33,7 +35,7 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
private SelectionLayer selectionManager;
private final int width = 300, height = 200;
private final int padding = 10;
private final int padding = 0;
private boolean opened = false;
private float openness = 0f;
@ -55,7 +57,7 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
@Override
public void update(float dTime) {
openness = lerp(openness, opened ? 1 : 0, dTime / 20);
openness = lerp(openness, opened ? 1 : 0, dTime / Constants.animationSpeed);
if(newSelection != null) {
selectionManager.updateSelection(newSelection);
newSelection = null;
@ -75,6 +77,10 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
@Override
public void selectionChanged(List<ISelectable> newSelection) {
if(selected.size() != 0 && newSelection.size() != 0) {
Assets.sndBubble.play();
}
if(newSelection.size() == 0) {
close();
return;
@ -109,7 +115,6 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
}
private int animate(int a, int b) {
System.out.println(openness);
return (int) Math.round(lerp(a, b, openness));
}
@ -118,7 +123,8 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
// if(selected.isEmpty()) return;
if(!opened && openness <= 0.0001f) return;
window(animate(-width - 50, padding), 576 - padding - height - BottomBar.bottomBarHeight, width, height, () -> {
// main window
window(animate(-width - 50, 0), 576 - height - BottomBar.bottomBarHeight + 1, width, height, () -> {
if(selectedByType.size() == 1) {
if(selectedCount == 1) {
text(properName);
@ -151,8 +157,9 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
}
});
if(selectedByType.size() == 1) {
root(padding * 2 + width, 576 - 32 - padding - BottomBar.bottomBarHeight, 1000, 32, () -> {
// actions
window(width - 1, animate(576 + 50, 576 - 48 - BottomBar.bottomBarHeight + 1), 1024 - width + 1, 48, () -> {
if(selectedByType.size() == 1) {
horizontal(() -> {
for(Action action : actions) {
if(button(action.name)) {
@ -163,8 +170,11 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
space(8);
}
});
});
}
} else {
space(8);
text(" Select an Item Type");
}
});
}

View File

@ -149,9 +149,6 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
}
private void broadcastSelectionChanged() {
// Assets.sndSelectionChanged.play();
if(selected.size() > 0) Assets.sndBubble.play();
if(selected.size() == 0) Assets.sndCancel.play();
for(ISelectionChangeListener listener : listeners) {
listener.selectionChanged(selected);

View File

@ -1,6 +1,7 @@
package xyz.valnet.hadean.gameobjects.ui;
import xyz.valnet.engine.graphics.ImmediateUI;
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
public class Popup extends ImmediateUI {
@ -24,7 +25,7 @@ public class Popup extends ImmediateUI {
text("But not this...");
if(button("Click Me!")) {
System.out.println("The Event!");
DebugTab.log("The Event!");
}
text("This after button...");

View File

@ -69,13 +69,13 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
try {
BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
if(annotation == null) {
System.out.println(clazz + " has no buildable data annotation");
DebugTab.log(clazz + " has no buildable data annotation");
return;
}
Constructor<? extends IBuildable> constructor = (Constructor<? extends IBuildable>) clazz.getConstructor();
if(constructor.getParameterCount() != 0) {
System.out.println(clazz + " has no default constructor (no params)");
DebugTab.log(clazz + " has no default constructor (no params)");
return;
}
@ -83,7 +83,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
String name = annotation.name();
BuildableMetadata.Type type = annotation.type();
System.out.println("Added " + category + " / " + name);
DebugTab.log("Added " + category + " / " + name);
if(!buildables.containsKey(category))
buildables.put(category, new ArrayList<BuildableRecord>());
@ -166,7 +166,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
}
building.buildAt(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
} catch (Exception e) {
System.out.println(e);
DebugTab.log(e);
}
}
@ -180,7 +180,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
}
building.buildAt(x1, y1);
} catch (Exception e) {
System.out.println(e);
DebugTab.log(e);
}
}

View File

@ -14,7 +14,7 @@ public class DebugTab extends Tab implements IKeyboardListener {
@Override
public String getTabName() {
return "Toggle Debug";
return "Debug";
}
@Override
@ -67,6 +67,10 @@ public class DebugTab extends Tab implements IKeyboardListener {
}
}
public static void log(Object obj) {
log(obj.toString());
}
@Override
public void keyPress(int code) {
if(code == 96) { // tilde

View File

@ -72,4 +72,22 @@ public class JobBoardTab extends Tab implements ISelectionChangeListener {
public String getTabName() {
return "Jobs";
}
@Override
protected void onClose() {
// TODO Auto-generated method stub
}
@Override
protected void onOpen() {
// TODO Auto-generated method stub
}
@Override
protected void gui() {
// TODO Auto-generated method stub
}
}

View File

@ -1,15 +0,0 @@
package xyz.valnet.hadean.gameobjects.ui.tabs;
public class LoadTab extends Tab {
@Override
public void evoke() {
load();
}
@Override
public String getTabName() {
return "Load";
}
}

View File

@ -2,28 +2,51 @@ package xyz.valnet.hadean.gameobjects.ui.tabs;
public class MenuTab extends Tab {
private int width = 300;
private int height = 6 * 32 + 9 * 8;
@Override
protected void onClose() {
// TODO Auto-generated method stub
}
@Override
protected void onOpen() {
// TODO Auto-generated method stub
}
@Override
protected void gui() {
// TODO Auto-generated method stub
window(1024 / 2 - width / 2, animate(-height - 50, 576 / 2 - height / 2), width, height, () -> {
if(button("Options")) {
}
space(8);
if(button("Debug")) {
get(DebugTab.class).open();
}
space(8);
if(button("Save")) {
save();
}
space(8);
if(button("Load")) {
load();
}
space(24);
if(button("Main Menu")) {
}
space(8);
if(button("Quit to Desktop")) {
}
});
}
@Override
public String getTabName() {
// TODO Auto-generated method stub
return null;
return "Menu";
}
}

View File

@ -1,15 +0,0 @@
package xyz.valnet.hadean.gameobjects.ui.tabs;
public class SaveTab extends Tab {
@Override
public void evoke() {
save();
}
@Override
public String getTabName() {
return "Save";
}
}

View File

@ -5,6 +5,7 @@ import static xyz.valnet.engine.util.Math.lerp;
import xyz.valnet.engine.graphics.IModalUI;
import xyz.valnet.engine.graphics.ImmediateUI;
import xyz.valnet.engine.scenegraph.ITransient;
import xyz.valnet.hadean.Constants;
import xyz.valnet.hadean.gameobjects.BottomBar;
import xyz.valnet.hadean.gameobjects.ui.ExclusivityManager;
import xyz.valnet.hadean.interfaces.IBottomBarItem;
@ -21,7 +22,7 @@ public abstract class Tab extends ImmediateUI implements IBottomBarItem, ITransi
@Override
public void update(float dTime) {
animation = lerp(animation, opened ? 1 : 0, dTime / 20);
animation = lerp(animation, opened ? 1 : 0, dTime / Constants.animationSpeed);
}
@Override

View File

@ -50,9 +50,6 @@ public class Quarry extends Construction {
if (digJob != null) return;
if (terrain.getTile(getWorldPosition().xy().south().east()).has(Boulder.class)) return;
System.out.println("Dig job?");
digJob = get(JobBoard.class)
.postSimpleWorkJob("Mine at Quarry", new IWorkable() {

View File

@ -29,7 +29,7 @@ public class SleepActivity extends Activity {
// as it will induce oversleep
WeightedAverage average = new WeightedAverage();
average.add(needs.getSleepNeed(), 1);
// System.out.println(1 - 2 * clock.getSunlight());
average.add(1 - 2 * clock.getSunlight(), circadianStrength);
return average.calculate();
}

View File

@ -14,6 +14,7 @@ import xyz.valnet.hadean.gameobjects.ui.ExclusivityManager;
import xyz.valnet.hadean.gameobjects.ui.HoverQuery;
import xyz.valnet.hadean.gameobjects.ui.tabs.BuildTab;
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
import xyz.valnet.hadean.gameobjects.ui.tabs.MenuTab;
import xyz.valnet.hadean.gameobjects.worldobjects.pawn.Pawn;
// TODO BIG IDEAS
@ -54,8 +55,7 @@ public class GameScene extends SceneGraph {
objects.add(new BuildTab());
// objects.add(new JobBoardTab());
objects.add(new DebugTab());
// objects.add(new SaveTab());
// objects.add(new LoadTab());
objects.add(new MenuTab());
// objects.add(new Popup());

View File

@ -11,13 +11,13 @@ import xyz.valnet.engine.graphics.Tile9;
import xyz.valnet.engine.math.Vector4i;
import xyz.valnet.engine.shaders.SimpleShader;
import xyz.valnet.engine.sound.Sound;
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
public class Assets {
public static final Sound sndBubble;
public static final Sound sndCancel;
public static final Sound sndGlassTap;
public static final Sound sndSelectionChanged;
public static final Texture atlas;
public static final Font font;
@ -59,7 +59,7 @@ public class Assets {
public static final SimpleShader flat;
static {
System.out.println("=== [ LOADING ASSETS ] ===");
DebugTab.log("=== [ LOADING ASSETS ] ===");
flat = new SimpleShader("res/shaders/flat.vert", "res/shaders/flat.frag");
atlas = new Texture("res/textures.png");
@ -316,12 +316,11 @@ public class Assets {
wall = new Tile16(atlas, new Vector4i(0, 17 * 8, 32, 32));
sndSelectionChanged = new Sound("res/sounds/leohpaz/retro-rpg-menu-sounds/079_Buy_sell_01.ogg");
sndBubble = new Sound("res/sounds/p0ss/interface-sounds/appear-online.ogg");
// sndCancel = new Sound("res/sounds/Listener/botton-sound-pack/cancel.ogg").setVolume(2f);
sndCancel = new Sound("res/sounds/leohpaz/retro-rpg-menu-sounds/098_Unpause_04.ogg").setVolume(0.8f);
sndGlassTap = new Sound("res/sounds/p0ss/interface-sounds/click5.ogg").setVolume(0.2f);
System.out.println("=== [ ASSETS LOADED ] ===");
DebugTab.log("=== [ ASSETS LOADED ] ===");
}
}