Code Monkey home page Code Monkey logo

libgdx-ingameconsole's Introduction

libGDX In-Game Console

This is a libGDX library that allows a developer to add a console (similar to how it is featured in Source games) to their game. Check out the changelog at my website!

How it works

Essentially what the console allows you to do is specify commands that you will be able to access from within the game, using the console. The console also enables live logging from within the application.

Purpose

This console speeds up development substantially by removing the need to recompile a program every time a minute change is made, specifically in regard to manipulating constants or other values when balancing a game, for example.

Integration

Gradle

Add the following line to your build.gradle file under the dependencies section of the core project:
compile "com.strongjoshua:libgdx-inGameConsole:{version}"
Replace {version} with the newest version number!

Then simply right-click the project and choose Gradle->Refresh All.

Maven

Right-click on your project and choose Maven->Add Dependency and search for strongjoshua. Make sure to choose the most recent version if multiple appear!

Eclipse

First, clone this project to your computer and add it to Eclipse. Then simply click on your project, and choose Build Path->Configure Build Path. Then go to Projects->Add and add the cloned project.

Versions

Latest Stable: 1.0.0
Latest Snapshot:

How the Numbers Work

First Digit

This digit goes up whenever I feel that the project has reached a milestone and/or no longer resembles the first version in it's current digit (e.g.: 0.13.3 is completely different from 0.1.0).

Second Digit

This digit goes up whenever a new feature is added, but if two or more features are added in one group of updates, this digit will still only rise by one. This number resets to 0 when the first digit goes up.

Third Digit

This digit goes up whenever a bugfix is released. This number resets to 0 when the second digit goes up.

License

Copyright 2015

Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

libgdx-ingameconsole's People

Contributors

6money avatar akashap avatar benmclean avatar blunderchips avatar born2snipe avatar dsaltares avatar kevinmurphy678 avatar maw016 avatar namek avatar patrikturi avatar piotr-j avatar silent-bob avatar strongjoshua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libgdx-ingameconsole's Issues

Support programatically registered commands

Hey, could you provide a possibility to register multiple command executors/support programmatically registered commands through the Console API? โค๏ธ

At this moment we can only use one command executor per instance. It works for some simple utilities, but it's not enough for a greater projects with a bunch of commands and component based layout. You can just collect their instances by e.g. addCommandExecutor instead of setCommandExecutor, it would be very helpful :)

classes cannot be resolved

hi
thx for sharing!!
i forked the repo and cloned it to my pc. then i imported the project to my game workspace via gradle and added it to the build path and to order/export.
but when i try to import the classes they cannot be resolved.
(i guess a stupid error on my side)
...
any suggestions?

bye
phil

Print Stack Trace

Would be nice to print the stack trace instead of just the message like so:

  catch (ReflectionException e) {
                String msg = e.getMessage();
                if (msg == null || msg.length() <= 0 || msg.equals("")) {
                    msg = "Unknown Error";
                    e.printStackTrace();
                }
               
               if(showConsoleStackTrace) {                   
                  StringWriter sw = new StringWriter();
                  PrintWriter pw = new PrintWriter(sw);
                  e.getCause().getCause().printStackTrace(pw);
                     log(sw.toString(), LogLevel.ERROR);
               }  else {
                  log(msg, LogLevel.ERROR);
               }
                return;
            }

Crash because of fast logging

I have different random exceptions when use log() if there no long time spent between logging calls (When I add 1 second delay manually there no exceptions ever). Examples of exceptions:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: offset 20, count 20, length 26 at java.base/java.lang.String.checkBoundsOffCount(String.java:4586) at java.base/java.lang.String.getChars(String.java:1674) at com.badlogic.gdx.utils.StringBuilder.append0(StringBuilder.java:164) at com.badlogic.gdx.utils.StringBuilder.append(StringBuilder.java:985) at com.badlogic.gdx.scenes.scene2d.ui.Label.setText(Label.java:117) at com.strongjoshua.console.GUIConsole$ConsoleDisplay.refresh(GUIConsole.java:516) at com.strongjoshua.console.GUIConsole.log(GUIConsole.java:308) at com.strongjoshua.console.AbstractConsole.log(AbstractConsole.java:70) at com.tagang.glademassacre.Networking.Network.Connect(Network.java:45) at com.tagang.glademassacre.UI.ConnectionMenu.connectButtonClick(ConnectionMenu.java:28) at com.tagang.glademassacre.UI.UIElement.click(UIElement.java:98) at com.tagang.glademassacre.UI.ConnectionMenu.clickM1(ConnectionMenu.java:59) at com.tagang.glademassacre.UI.SceneManager.clickM1(SceneManager.java:44) at com.tagang.glademassacre.InputAction.M1Clicked(InputAction.java:20) at com.tagang.glademassacre.KeyboardAdapter.touchUp(KeyboardAdapter.java:82) at com.badlogic.gdx.InputMultiplexer.touchUp(InputMultiplexer.java:124) at com.badlogic.gdx.InputEventQueue.drain(InputEventQueue.java:70) at com.badlogic.gdx.backends.lwjgl3.DefaultLwjgl3Input.update(DefaultLwjgl3Input.java:189) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:378) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:192) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:166) at com.tagang.glademassacre.DesktopLauncher.main(DesktopLauncher.java:18)

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.badlogic.gdx.scenes.scene2d.ui.Value.get(com.badlogic.gdx.scenes.scene2d.Actor)" because "c.minWidth" is null at com.badlogic.gdx.scenes.scene2d.ui.Table.computeSize(Table.java:828) at com.badlogic.gdx.scenes.scene2d.ui.Table.getPrefWidth(Table.java:432) at com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.layout(ScrollPane.java:406) at com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup.validate(WidgetGroup.java:113) at com.strongjoshua.console.GUIConsole$ConsoleDisplay.refresh(GUIConsole.java:520) at com.strongjoshua.console.GUIConsole.log(GUIConsole.java:308) at com.strongjoshua.console.AbstractConsole.log(AbstractConsole.java:70) at com.tagang.glademassacre.Networking.Network.Connect(Network.java:45) at com.tagang.glademassacre.UI.ConnectionMenu.connectButtonClick(ConnectionMenu.java:28) at com.tagang.glademassacre.UI.UIElement.click(UIElement.java:98) at com.tagang.glademassacre.UI.ConnectionMenu.clickM1(ConnectionMenu.java:59) at com.tagang.glademassacre.UI.SceneManager.clickM1(SceneManager.java:44) at com.tagang.glademassacre.InputAction.M1Clicked(InputAction.java:20) at com.tagang.glademassacre.KeyboardAdapter.touchUp(KeyboardAdapter.java:82) at com.badlogic.gdx.InputMultiplexer.touchUp(InputMultiplexer.java:124) at com.badlogic.gdx.InputEventQueue.drain(InputEventQueue.java:70) at com.badlogic.gdx.backends.lwjgl3.DefaultLwjgl3Input.update(DefaultLwjgl3Input.java:189) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:378) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:192) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:166) at com.tagang.glademassacre.DesktopLauncher.main(DesktopLauncher.java:18)

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.badlogic.gdx.scenes.scene2d.ui.Table.row()" because "this.table" is null at com.badlogic.gdx.scenes.scene2d.ui.Cell.row(Cell.java:892) at com.strongjoshua.console.GUIConsole$ConsoleDisplay.refresh(GUIConsole.java:518) at com.strongjoshua.console.GUIConsole.log(GUIConsole.java:308) at com.strongjoshua.console.AbstractConsole.log(AbstractConsole.java:70) at com.tagang.glademassacre.Networking.Network.Connect(Network.java:45) at com.tagang.glademassacre.UI.ConnectionMenu.connectButtonClick(ConnectionMenu.java:28) at com.tagang.glademassacre.UI.UIElement.click(UIElement.java:98) at com.tagang.glademassacre.UI.ConnectionMenu.clickM1(ConnectionMenu.java:59) at com.tagang.glademassacre.UI.SceneManager.clickM1(SceneManager.java:44) at com.tagang.glademassacre.InputAction.M1Clicked(InputAction.java:20) at com.tagang.glademassacre.KeyboardAdapter.touchUp(KeyboardAdapter.java:82) at com.badlogic.gdx.InputMultiplexer.touchUp(InputMultiplexer.java:124) at com.badlogic.gdx.InputEventQueue.drain(InputEventQueue.java:70) at com.badlogic.gdx.backends.lwjgl3.DefaultLwjgl3Input.update(DefaultLwjgl3Input.java:189) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:378) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:192) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:166) at com.tagang.glademassacre.DesktopLauncher.main(DesktopLauncher.java:18)

Fail to compile on GWT

I'm currently getting this compilation error on GWT:

Compiling module net.benmclean.planetgenerator.GdxDefinition
Tracing compile failure path for type 'com.strongjoshua.console.ConsoleUtils'
[ERROR] Errors in 'jar:file:/C:/Users/[MY USERNAME HERE]/.gradle/caches/modules-2/files-2.1/com.github.BenMcLean/libgdx-inGameConsole/703cc7f896/f15812e13f5df40710a975d17039035913274d85/libgdx-inGameConsole-703cc7f896-sources.jar!/com/strongjoshua/console/ConsoleUtils.java'
[ERROR] Line 26: The method currentThread() is undefined for the type Thread

It's referencing my fork, but my fork has no changes to ConsoleUtils.java so this is something affecting the original too.

Way to override help?

I would like to override help and create my own help list with a better explanation for each command. Is this possible? Or is it possible to give the commands a description in help?

Way to reuse console object?

What's the best practice in terms of managing the Console and the CommandExecutors? It seems that the easiest way is to have a separate one for each Screen in the game - if relevant. Is that the normal way of managing it? Or is there a better way to manage the objects involved?
I hope that all makes sense!

Repeating the same command using up arrow and enter

Minor suggestion.
When using a standard GUIConsole, the index increments in CommandHistory when pressing the up arrow regardless if I press enter.

I would like to just keep pressing up and enter like in a traditional console to keep spamming the same command. Right now if I type 2 different commands and press up and enter multiple times, the second time it will switch to the first command I typed instead of the one I wanted to repeat.

Btw, thanks a lot for this repo, I find it immensely useful! ๐Ÿ‘

GWT Compatibility

Could you provide compatibility with GWT?
It looks like you already thought on this issue, but it's not finished though.

There are a few calls to unimplemented GWT functions.

Thank you.

Issue with invocation with overloaded methods.

While working on a lib to get it to work with GWT, Ive found a bug in execCommand(String command). Overloading methods doesnt work, since the methods returns on first failure. This can be easily fixed by removing return at line 487. However, the log message and stacktrace remains and makes it ugly. Checking primitive types is little annoying, so I propose that exceptions are logged after the loop, if all possible candidates failed.

Ill PR working GWT implementation once this issue is resolved.

Add method "Console.setHidden(boolean value)"

I would like to show/hide the console from a button or programatically when certain errors happen. It would be useful to have the method Console.setHidden(boolean value) to allow this.

ArrayIndexOutOfBoundsException when i enter Space and hit return

it crashes with ArrayIndexOutOfBoundsException when i enter Space and hit return:

Exception in thread "LWJGL Application" java.lang.ArrayIndexOutOfBoundsException: 0
at com.strongjoshua.console.Console.execCommand(Console.java:265)
at com.strongjoshua.console.Console.access$3(Console.java:261)
at com.strongjoshua.console.Console$KeyListener.keyDown(Console.java:410)
at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:44)

Feature request: setter for the console title

Hello, I've noticed that the title of the console window, "Console", is hardcoded on line 114 of GUIConsole.java, which is a bummer because I would really like to rename my window to something else. Couldn't this become parameterized or have at least a setter?

Possibility to set a font

I think in most apps console font would be somehow special / different than a "default-font". Please, can you implement a way how can we say smth. like "console-font", which would be present in my skin of course? That would be awesome. Without this, console forces me to put a font suitable for it as a default one, which is not suitable for the rest of the app. Thank you!

Console only shows first time

Hi,

I updated from 0.5.3 to 0.7.0 and now the console only shows the first time I push the assigned key.

In my case I have set the key with console.setDisplayKeyID(Keys.F1);

Steps to reproduce it:

  1. Push F1 -> the console shows
  2. Push F1 -> the console hides
  3. Push F1 -> the console doesn't show anymore.

Best Regards.

Illegal argument exception for boolean type

Creating a command with a boolean as an argument does not work.

Example:

public class MyCommandExecutor extends CommandExecutor {
        public void test(boolean t) {
            console.log(String.valueOf(t));
        }
    }

All commands on "help"

Please, can "help" command list contain "help", "exit", "saveLog" as well? I MyCommandExecutor i did it like:

/**
 * keep it here for "help" hint
 */
@Override
public void help()
{
    super.help();
}

/**
 * keep it here for "help" hint
 */
@Override
public void exitApp()
{
    super.exitApp();
}

/**
 * keep it here for "help" hint
 */
@Override
public void printLog(String path)
{
    super.printLog(path);
}

but those methods are final now.
I would like to get all commands after "help".

Thank You!
J.

Console not working with latest libgdx v1.9.4

Hi!

With the latest libgdx version (1.9.4) the console doesn't work.

The stacktrace:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoSuchMethodError: com.badlogic.gdx.scenes.scene2d.Stage.setKeyboardFocus(Lcom/badlogic/gdx/scenes/scene2d/Actor;)V
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131)
Caused by: java.lang.NoSuchMethodError: com.badlogic.gdx.scenes.scene2d.Stage.setKeyboardFocus(Lcom/badlogic/gdx/scenes/scene2d/Actor;)V
    at com.strongjoshua.console.GUIConsole.<init>(GUIConsole.java:111)
    at com.strongjoshua.console.GUIConsole.<init>(GUIConsole.java:69)
    at com.strongjoshua.console.GUIConsole.<init>(GUIConsole.java:60)
    at com.bladecoder.engineeditor.Editor.create(Editor.java:151)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)

Signing stuff on Gradle causes problems

I get jars of libgdx-inGameConsole made through Jitpack. As this build log shows, the signing stuff in build.gradle causes the build to fail, presumably for anyone using gradle except StrongJoshua himself.

I've been able to work around this over on my fork by simply stripping out all signing related stuff from build.gradle. But what you'll probably want to do to address this is to configure gradle properly so that it only attempts this signing stuff on request.

Crash with libGDX 1.9.9

When using the latest libGDX v1.9.9 and the latest libgdx-inGameConsole v1.0.0b-SNAPSHOT, if you create a GUIConsole with the default empty constructor, the app crashes with the following stacktrace:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoSuchMethodError: com.badlogic.gdx.InputMultiplexer.getProcessors()Lcom/badlogic/gdx/utils/Array;
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:133)
Caused by: java.lang.NoSuchMethodError: com.badlogic.gdx.InputMultiplexer.getProcessors()Lcom/badlogic/gdx/utils/Array;
	at com.strongjoshua.console.GUIConsole.hasStage(GUIConsole.java:259)
	at com.strongjoshua.console.GUIConsole.resetInputProcessing(GUIConsole.java:233)
	at com.strongjoshua.console.GUIConsole.<init>(GUIConsole.java:152)
	at com.strongjoshua.console.GUIConsole.<init>(GUIConsole.java:127)
	at com.strongjoshua.console.GUIConsole.<init>(GUIConsole.java:113)
	at com.strongjoshua.console.GUIConsole.<init>(GUIConsole.java:86)
	at com.strongjoshua.console.GUIConsole.<init>(GUIConsole.java:73)

It seems to be due to a breaking change introduced to InputMultiplexer in 1.9.9.

Enhancement - hook for open/close console

Basically, I'd like to pause my game while the console is open. Can we perhaps get an empty protected method in CommandExecutor that gets called when the console is opened or closed? If this is of interest, I could create a PR

Crashes when log method is called.

Crashing with the following exception.

Exception in thread "LWJGL Application" java.lang.IndexOutOfBoundsException: index can't be >= size: 26 >= 0 at com.badlogic.gdx.utils.Array.removeIndex(Array.java:260) at com.badlogic.gdx.utils.SnapshotArray.removeIndex(SnapshotArray.java:130) at com.badlogic.gdx.utils.Array.removeValue(Array.java:243) at com.badlogic.gdx.utils.SnapshotArray.removeValue(SnapshotArray.java:125) at com.badlogic.gdx.scenes.scene2d.Group.removeActor(Group.java:330) at com.badlogic.gdx.scenes.scene2d.ui.Table.removeActor(Table.java:298) at com.badlogic.gdx.scenes.scene2d.Actor.remove(Actor.java:216) at com.badlogic.gdx.scenes.scene2d.ui.Table.clearChildren(Table.java:310) at com.badlogic.gdx.scenes.scene2d.Group.clear(Group.java:357) at com.strongjoshua.console.GUIConsole$ConsoleDisplay.refresh(GUIConsole.java:420) at com.strongjoshua.console.GUIConsole.log(GUIConsole.java:275)

This issue can be replicated by logging a lot of messages to the console. I suspect the console is trying to remove a log that has already been removed.

Dead link on readme

The link to the strongjoshua.net site is dead. Is the website still active but changed name or should the link be removed from the readme?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.