summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorromangraef <roman.graef@gmail.com>2018-05-30 12:06:31 +0200
committerromangraef <roman.graef@gmail.com>2018-05-30 12:06:31 +0200
commit2ac18d91635b023db7ff3918f5041cb51ed1c968 (patch)
tree8caffe3c5807e105eb474e2277ece57dc82823c3
downloadpluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.tar.gz
pluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.tar.bz2
pluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.zip
Initial commit
-rw-r--r--.editorconfig0
-rw-r--r--.gitignore5
-rw-r--r--.gradle/4.3.1/fileChanges/last-build.binbin0 -> 1 bytes
-rw-r--r--.gradle/4.3.1/fileContent/fileContent.lockbin0 -> 17 bytes
-rw-r--r--.gradle/4.3.1/fileHashes/fileHashes.binbin0 -> 21847 bytes
-rw-r--r--.gradle/4.3.1/fileHashes/fileHashes.lockbin0 -> 17 bytes
-rw-r--r--.gradle/4.3.1/fileHashes/resourceHashesCache.binbin0 -> 19177 bytes
-rw-r--r--.gradle/4.3.1/taskHistory/taskHistory.binbin0 -> 50091 bytes
-rw-r--r--.gradle/4.3.1/taskHistory/taskHistory.lockbin0 -> 17 bytes
-rw-r--r--.gradle/4.4/fileChanges/last-build.binbin0 -> 1 bytes
-rw-r--r--.gradle/4.4/fileContent/fileContent.lockbin0 -> 17 bytes
-rw-r--r--.gradle/4.4/fileHashes/fileHashes.binbin0 -> 23547 bytes
-rw-r--r--.gradle/4.4/fileHashes/fileHashes.lockbin0 -> 17 bytes
-rw-r--r--.gradle/4.4/fileHashes/resourceHashesCache.binbin0 -> 19381 bytes
-rw-r--r--.gradle/4.4/taskHistory/taskHistory.binbin0 -> 106499 bytes
-rw-r--r--.gradle/4.4/taskHistory/taskHistory.lockbin0 -> 17 bytes
-rw-r--r--.gradle/buildOutputCleanup/buildOutputCleanup.lockbin0 -> 17 bytes
-rw-r--r--.gradle/buildOutputCleanup/cache.properties2
-rw-r--r--.gradle/buildOutputCleanup/outputFiles.binbin0 -> 18983 bytes
-rw-r--r--build.gradle69
-rw-r--r--gradle/wrapper/gradle-wrapper.properties6
-rwxr-xr-xgradlew172
-rw-r--r--gradlew.bat84
-rw-r--r--settings.gradle3
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt65
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Dependency.kt3
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/DependencyMissing.kt4
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Event.kt3
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/EventHandler.kt5
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Events.kt15
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/IPlugin.kt5
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Inject.kt5
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/InjectException.kt3
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/PluginFolderNotFound.kt3
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/PluginLoader.kt76
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/PluginMeta.kt5
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/assets.kt28
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/events/InitEvent.kt5
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/events/PostInitEvent.kt5
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/events/PreInitEvent.kt6
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt109
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/main.kt49
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt45
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/MainMenu.kt52
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt42
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/SplashScreen.kt41
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/util.kt23
-rw-r--r--src/main/resources/images/button.pngbin0 -> 283 bytes
-rw-r--r--src/main/resources/images/cactus.pngbin0 -> 201 bytes
-rw-r--r--src/main/resources/images/characters.pngbin0 -> 1138 bytes
-rw-r--r--src/main/resources/images/groundline.pngbin0 -> 239 bytes
-rw-r--r--src/main/resources/images/splash.pngbin0 -> 14192 bytes
52 files changed, 938 insertions, 0 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/.editorconfig
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0e7936b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+assets/
+build/
+out/
+pluggablelogging/
+plugins/
diff --git a/.gradle/4.3.1/fileChanges/last-build.bin b/.gradle/4.3.1/fileChanges/last-build.bin
new file mode 100644
index 0000000..f76dd23
--- /dev/null
+++ b/.gradle/4.3.1/fileChanges/last-build.bin
Binary files differ
diff --git a/.gradle/4.3.1/fileContent/fileContent.lock b/.gradle/4.3.1/fileContent/fileContent.lock
new file mode 100644
index 0000000..9bd0f9b
--- /dev/null
+++ b/.gradle/4.3.1/fileContent/fileContent.lock
Binary files differ
diff --git a/.gradle/4.3.1/fileHashes/fileHashes.bin b/.gradle/4.3.1/fileHashes/fileHashes.bin
new file mode 100644
index 0000000..e2df64d
--- /dev/null
+++ b/.gradle/4.3.1/fileHashes/fileHashes.bin
Binary files differ
diff --git a/.gradle/4.3.1/fileHashes/fileHashes.lock b/.gradle/4.3.1/fileHashes/fileHashes.lock
new file mode 100644
index 0000000..412b1fc
--- /dev/null
+++ b/.gradle/4.3.1/fileHashes/fileHashes.lock
Binary files differ
diff --git a/.gradle/4.3.1/fileHashes/resourceHashesCache.bin b/.gradle/4.3.1/fileHashes/resourceHashesCache.bin
new file mode 100644
index 0000000..e5c7218
--- /dev/null
+++ b/.gradle/4.3.1/fileHashes/resourceHashesCache.bin
Binary files differ
diff --git a/.gradle/4.3.1/taskHistory/taskHistory.bin b/.gradle/4.3.1/taskHistory/taskHistory.bin
new file mode 100644
index 0000000..9141d5b
--- /dev/null
+++ b/.gradle/4.3.1/taskHistory/taskHistory.bin
Binary files differ
diff --git a/.gradle/4.3.1/taskHistory/taskHistory.lock b/.gradle/4.3.1/taskHistory/taskHistory.lock
new file mode 100644
index 0000000..4249219
--- /dev/null
+++ b/.gradle/4.3.1/taskHistory/taskHistory.lock
Binary files differ
diff --git a/.gradle/4.4/fileChanges/last-build.bin b/.gradle/4.4/fileChanges/last-build.bin
new file mode 100644
index 0000000..f76dd23
--- /dev/null
+++ b/.gradle/4.4/fileChanges/last-build.bin
Binary files differ
diff --git a/.gradle/4.4/fileContent/fileContent.lock b/.gradle/4.4/fileContent/fileContent.lock
new file mode 100644
index 0000000..77f2559
--- /dev/null
+++ b/.gradle/4.4/fileContent/fileContent.lock
Binary files differ
diff --git a/.gradle/4.4/fileHashes/fileHashes.bin b/.gradle/4.4/fileHashes/fileHashes.bin
new file mode 100644
index 0000000..f7cf6ef
--- /dev/null
+++ b/.gradle/4.4/fileHashes/fileHashes.bin
Binary files differ
diff --git a/.gradle/4.4/fileHashes/fileHashes.lock b/.gradle/4.4/fileHashes/fileHashes.lock
new file mode 100644
index 0000000..ef5b83e
--- /dev/null
+++ b/.gradle/4.4/fileHashes/fileHashes.lock
Binary files differ
diff --git a/.gradle/4.4/fileHashes/resourceHashesCache.bin b/.gradle/4.4/fileHashes/resourceHashesCache.bin
new file mode 100644
index 0000000..2f7ee1f
--- /dev/null
+++ b/.gradle/4.4/fileHashes/resourceHashesCache.bin
Binary files differ
diff --git a/.gradle/4.4/taskHistory/taskHistory.bin b/.gradle/4.4/taskHistory/taskHistory.bin
new file mode 100644
index 0000000..b0aa556
--- /dev/null
+++ b/.gradle/4.4/taskHistory/taskHistory.bin
Binary files differ
diff --git a/.gradle/4.4/taskHistory/taskHistory.lock b/.gradle/4.4/taskHistory/taskHistory.lock
new file mode 100644
index 0000000..f18d4ce
--- /dev/null
+++ b/.gradle/4.4/taskHistory/taskHistory.lock
Binary files differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
new file mode 100644
index 0000000..9964ec3
--- /dev/null
+++ b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary files differ
diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties
new file mode 100644
index 0000000..957faa6
--- /dev/null
+++ b/.gradle/buildOutputCleanup/cache.properties
@@ -0,0 +1,2 @@
+#Mon May 28 13:47:58 CEST 2018
+gradle.version=4.4
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
new file mode 100644
index 0000000..8ca1906
--- /dev/null
+++ b/.gradle/buildOutputCleanup/outputFiles.bin
Binary files differ
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..c27f34d
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,69 @@
+buildscript {
+ ext.kotlin_version = '1.2.41'
+
+ repositories {
+ mavenCentral()
+ maven {
+ url 'http://dl.bintray.com/cjstehno/public/'
+ }
+ }
+
+ dependencies {
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
+}
+plugins {
+ id 'java'
+ id 'application'
+ id 'com.stehno.natives' version '0.3.1'
+}
+apply plugin: 'kotlin'
+
+group 'de.romjaki'
+version '1.0-SNAPSHOT'
+
+ext.platform = 'linux'
+mainClassName = "de.romjaki.pluggabledino.MainKt"
+
+compileJava {
+ sourceCompatibility = 1.8
+ targetCompatibility = 1.8
+}
+repositories {
+ mavenCentral()
+ jcenter()
+}
+
+dependencies {
+ compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
+ compile 'com.beust:klaxon:3.0.1'
+ compile group: 'org.slick2d', name: 'slick2d-core', version: '1.0.2'
+ compile group: 'org.jbox2d', name: 'jbox2d-library', version: '2.2.1.1'
+}
+
+
+test {
+ systemProperty 'java.library.path', file("build/natives")
+}
+
+natives {
+}
+run {
+ systemProperty 'java.library.path', file('build/natives')
+}
+
+compileKotlin {
+ kotlinOptions.jvmTarget = "1.8"
+}
+compileTestKotlin {
+ kotlinOptions.jvmTarget = "1.8"
+}
+
+task copyResources(type: Copy) {
+ from 'src/main/resources'
+ into 'assets'
+}
+
+build.dependsOn copyResources
+
+
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..3d35a1b
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Sun May 27 10:11:44 CEST 2018
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..cccdd3d
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..f955316
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..c7e135c
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,3 @@
+rootProject.name = 'pluggabledino'
+include 'pluggablelogging'
+
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt
new file mode 100644
index 0000000..9b39e4b
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt
@@ -0,0 +1,65 @@
+package de.romjaki.pluggabledino.api
+
+import de.romjaki.pluggabledino.buttonImage
+import de.romjaki.pluggabledino.drawImageCentered
+import de.romjaki.pluggabledino.drawStringCentered
+import de.romjaki.pluggabledino.font
+import org.newdawn.slick.Graphics
+import org.newdawn.slick.Input
+import java.awt.Rectangle
+import kotlin.math.min
+
+class Button(private val text: String, val x: Float, val y: Float) {
+
+ val width = min(buttonImage.width, font.getWidth(text) + 10)
+ val image = buttonImage.getScaledCopy(width, buttonImage.height)
+
+ private var lastClicked = false
+
+ val leftX
+ get() = x - width / 2
+ val rightX
+ get() = x + width / 2
+ val topY
+ get() = y - image.height / 2
+ val bottomY
+ get() = y + image.height / 2
+
+ val rectangle
+ get() = Rectangle(leftX.toInt(), topY.toInt(), (rightX - leftX).toInt(), (bottomY - topY).toInt())
+
+
+ private val clickHandlers = mutableListOf<() -> Unit>()
+
+ fun addClickHandler(handler: () -> Unit) {
+ clickHandlers.add(handler)
+ }
+
+ fun draw(g: Graphics) {
+ g.drawImageCentered(image, x, y)
+ g.drawStringCentered(text, x, y)
+ }
+
+ override fun toString(): String =
+ "X: $leftX - $rightX, $topY - $bottomY, width=$width"
+
+ fun enter() {
+ lastClicked = true
+ }
+
+ fun isClicked(input: Input): Boolean =
+ input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && isMouseOver(input)
+
+ fun update(input: Input) {
+ val ret = isClicked(input)
+ if (!lastClicked && ret) {
+ clickHandlers.forEach({ it() })
+ }
+ lastClicked = ret
+ }
+
+ fun isMouseOver(input: Input): Boolean =
+ rectangle.contains(input.mouseX, input.mouseY)
+
+}
+
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Dependency.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Dependency.kt
new file mode 100644
index 0000000..65c8b06
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Dependency.kt
@@ -0,0 +1,3 @@
+package de.romjaki.pluggabledino.api
+
+data class Dependency(var dependencyName: String, var dependencyVersion: String) \ No newline at end of file
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/DependencyMissing.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/DependencyMissing.kt
new file mode 100644
index 0000000..85769f7
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/DependencyMissing.kt
@@ -0,0 +1,4 @@
+package de.romjaki.pluggabledino.api
+
+class DependencyMissing(plugin: String, dependencyName: String, dependencyVersion: String) :
+ Exception("$plugin is missing dependency ${dependencyName}with version $dependencyVersion")
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Event.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Event.kt
new file mode 100644
index 0000000..4aa702d
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Event.kt
@@ -0,0 +1,3 @@
+package de.romjaki.pluggabledino.api
+
+interface Event \ No newline at end of file
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/EventHandler.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/EventHandler.kt
new file mode 100644
index 0000000..989fb81
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/EventHandler.kt
@@ -0,0 +1,5 @@
+package de.romjaki.pluggabledino.api
+
+@Target(AnnotationTarget.FUNCTION)
+@Retention(AnnotationRetention.RUNTIME)
+annotation class EventHandler \ No newline at end of file
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Events.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Events.kt
new file mode 100644
index 0000000..6f43844
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Events.kt
@@ -0,0 +1,15 @@
+package de.romjaki.pluggabledino.api
+
+import java.util.*
+
+object Events {
+ fun broadcastEvent(event: Event) {
+ for (plugin in PluginLoader.plugins.values) {
+ Arrays.stream(plugin.javaClass.methods!!)
+ .filter { it.getAnnotation(EventHandler::class.java) != null }
+ .filter { it.parameterCount == 1 }
+ .filter { it.parameterTypes[0].isInstance(event) }
+ .forEach { it.invoke(plugin, event) }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/IPlugin.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/IPlugin.kt
new file mode 100644
index 0000000..e2e25fc
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/IPlugin.kt
@@ -0,0 +1,5 @@
+package de.romjaki.pluggabledino.api;
+
+open class IPlugin {
+ var meta: PluginMeta? = null
+}
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Inject.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Inject.kt
new file mode 100644
index 0000000..c3089c9
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Inject.kt
@@ -0,0 +1,5 @@
+package de.romjaki.pluggabledino.api
+
+@Target(AnnotationTarget.FIELD)
+@Retention(AnnotationRetention.RUNTIME)
+annotation class Inject(val what: String)
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/InjectException.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/InjectException.kt
new file mode 100644
index 0000000..2dc14dd
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/InjectException.kt
@@ -0,0 +1,3 @@
+package de.romjaki.pluggabledino.api
+
+class InjectException(plugin: String, dependency: String) : Exception("$plugin failed to load $dependency") \ No newline at end of file
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/PluginFolderNotFound.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/PluginFolderNotFound.kt
new file mode 100644
index 0000000..5ca946f
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/PluginFolderNotFound.kt
@@ -0,0 +1,3 @@
+package de.romjaki.pluggabledino.api
+
+class PluginFolderNotFound(folder: String) : Exception("Plugin folder not found at $folder")
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/PluginLoader.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/PluginLoader.kt
new file mode 100644
index 0000000..7ce8649
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/PluginLoader.kt
@@ -0,0 +1,76 @@
+package de.romjaki.pluggabledino.api
+
+import com.beust.klaxon.Klaxon
+import java.io.File
+import java.net.URL
+import java.net.URLClassLoader
+import java.util.*
+
+
+object PluginLoader {
+ private val _plugins: MutableMap<String, IPlugin> = mutableMapOf()
+ private val klaxon = Klaxon()
+ private const val pluginFolder = "plugins"
+
+ val plugins
+ get() = _plugins.toMap()
+
+
+ fun loadPlugin(url: URL): IPlugin? {
+ val cl = URLClassLoader(arrayOf(url))
+ val pluginInfo = klaxon.parse<PluginMeta>(
+ Scanner(
+ cl.getResourceAsStream("plugin.json"))
+ .useDelimiter("\\A")
+ .next())!!
+ val pluginClass = cl.loadClass(pluginInfo.clazz)
+ if (!IPlugin::class.java.isAssignableFrom(pluginClass)) {
+ return null
+ }
+ val plugin = pluginClass.newInstance() as IPlugin
+ plugin.meta = pluginInfo
+ _plugins[pluginInfo.name] = plugin
+ return plugin
+ }
+
+ private fun checkDependencies() {
+ for ((name, inst