diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..bf82ff0 Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..dc3affc --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://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. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/idea.md b/idea.md index 4841e39..ffb2141 100644 --- a/idea.md +++ b/idea.md @@ -50,4 +50,23 @@ it is the thing that activates the build layer. consequence is that without proper care a single event could immediately open & close the panel in the same frame. so, the event should be able to -be captured and cease propogation. \ No newline at end of file +be captured and cease propogation. + + +# ready() +call order goes from top to bottom \/\/\/ +ready is called before scene linkage, and +serves to initialize values that may be +needed before incoming requests. + +# connect() +connect is solely for ensuring links to +other objects. get() and getAll() + +# create() +create is guaranteed to only run once for +an object, even after save/load + +# start() +start is called any time the object is added +to a scene \ No newline at end of file diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..b7f0646 --- /dev/null +++ b/mvnw @@ -0,0 +1,287 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.1.1 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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 + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + printf '%s' "$(cd "$basedir"; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname $0)") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $wrapperUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + QUIET="--quiet" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + elif command -v curl > /dev/null; then + QUIET="--silent" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=`cygpath --path --windows "$javaSource"` + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..cba1f04 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,187 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.1.1 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 6c4934a..42f3e32 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ xyz.valnet.hadean hadean - 1.0-SNAPSHOT + 0.1-SNAPSHOT hadean diff --git a/src/main/java/xyz/valnet/engine/math/Vector2i.java b/src/main/java/xyz/valnet/engine/math/Vector2i.java index cb55739..80fe92d 100644 --- a/src/main/java/xyz/valnet/engine/math/Vector2i.java +++ b/src/main/java/xyz/valnet/engine/math/Vector2i.java @@ -22,7 +22,7 @@ public class Vector2i implements Serializable { public boolean isOneOf(Vector2i[] others) { for(Vector2i other : others) { - if(other.equals(this)) { + if(other.equals(this)) { return true; } } diff --git a/src/main/java/xyz/valnet/engine/math/Vector4i.java b/src/main/java/xyz/valnet/engine/math/Vector4i.java index c39567d..0a7dad6 100644 --- a/src/main/java/xyz/valnet/engine/math/Vector4i.java +++ b/src/main/java/xyz/valnet/engine/math/Vector4i.java @@ -20,4 +20,8 @@ public class Vector4i implements Serializable { this.w = w; } + public Vector2i xy() { + return new Vector2i(x, y); + } + } diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/Job.java b/src/main/java/xyz/valnet/hadean/gameobjects/Job.java index a71204b..c46d4c7 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/Job.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/Job.java @@ -36,7 +36,7 @@ public class Job extends GameObject { @Override public Vector2i[] getLocations() { - return new Vector2i[] { item.getWorldPosition().asInt() }; + return new Vector2i[] { item.getWorldPosition().xy() }; } @Override @@ -78,7 +78,7 @@ public class Job extends GameObject { Set positionSet = new HashSet(); for(Item item : that.getAll(Item.class)) { if(!item.matches(predicate)) continue; - positionSet.add(item.getWorldPosition().asInt()); + positionSet.add(item.getWorldPosition().xy()); } Vector2i[] positions = new Vector2i[positionSet.size()]; positionSet.toArray(positions); diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/JobBoard.java b/src/main/java/xyz/valnet/hadean/gameobjects/JobBoard.java index f8d4c6b..81cf4eb 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/JobBoard.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/JobBoard.java @@ -9,7 +9,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.stream.Stream; -import xyz.valnet.engine.math.Vector2f; +import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.hadean.gameobjects.worldobjects.pawn.Pawn; import xyz.valnet.hadean.interfaces.IWorkable; @@ -59,7 +59,7 @@ public class JobBoard extends GameObject { } private List getJobsForWorker(Pawn worker) { - Vector2f workerLocation = worker.getWorldPosition(); + Vector2i workerLocation = worker.getWorldPosition().xy(); List workables = availableJobs .stream() diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/Tile.java b/src/main/java/xyz/valnet/hadean/gameobjects/Tile.java index 6a0f059..f76ec8a 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/Tile.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/Tile.java @@ -3,9 +3,9 @@ package xyz.valnet.hadean.gameobjects; import java.util.ArrayList; import java.util.List; -import xyz.valnet.engine.math.Vector2f; import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector4f; +import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.hadean.gameobjects.worldobjects.FarmPlot; import xyz.valnet.hadean.gameobjects.worldobjects.Tree; @@ -35,40 +35,37 @@ public class Tile extends WorldObject implements IWorkable { private List toRemove = new ArrayList(); public Tile(int x, int y) { - this.x = x; - this.y = y; + setPosition(x, y); } public Vector2i getCoords() { - return new Vector2f(x, y).asInt(); + return getWorldPosition().xy(); } public void start() { super.start(); + Vector4i pos = getWorldPosition(); float scale = 1; - float red = (float) terrain.getNoise(redSeed, x * scale, y * scale); - float green = (float) terrain.getNoise(greenSeed, x * scale, y * scale); - float blue = (float) terrain.getNoise(blueSeed, x * scale, y * scale); + float red = (float) terrain.getNoise(redSeed, pos.x * scale, pos.y * scale); + float green = (float) terrain.getNoise(greenSeed, pos.x * scale, pos.y * scale); + float blue = (float) terrain.getNoise(blueSeed, pos.x * scale, pos.y * scale); if(color == null) color = new Vector4f(red * 0.1f, 0.4f + green * 0.15f, blue * 0.05f, 1f); } @Override protected void create() { + Vector4i pos = getWorldPosition(); if(Math.random() > 0.95) { rocks = true; } if(Math.random() > 0.97) { - Tree tree = new Tree((int)x, (int)y); - stuff.add(tree); - add(tree); + add(new Tree(pos.x, pos.y)); } else if(Math.random() > 0.98) { rocks = false; - Boulder tree = new Boulder((int)x, (int)y); - stuff.add(tree); - add(tree); + add(new Boulder(pos.x, pos.y)); } } @@ -130,15 +127,16 @@ public class Tile extends WorldObject implements IWorkable { @Override public void render() { + Vector4i pos = getWorldPosition(); if(tillLevel < 1f) { Assets.flat.pushColor(color); - camera.draw(Layers.TILES, Assets.defaultTerrain[tileSelector], x, y); + camera.draw(Layers.TILES, Assets.defaultTerrain[tileSelector], pos.x, pos.y); Assets.flat.popColor(); - if(rocks) camera.draw(Layers.TILES, Assets.rocks, x, y); + if(rocks) camera.draw(Layers.TILES, Assets.rocks, pos.x, pos.y); } if(tillLevel > 0f) { Assets.flat.pushColor(Vector4f.opacity(tillLevel)); - camera.draw(Layers.TILES, Assets.farmPlot[tileSelector], x, y); + camera.draw(Layers.TILES, Assets.farmPlot[tileSelector], pos.x, pos.y); Assets.flat.popColor(); } } @@ -154,16 +152,17 @@ public class Tile extends WorldObject implements IWorkable { @Override public Vector2i[] getWorkablePositions() { + Vector4i pos = getWorldPosition(); return new Vector2i[] { - new Vector2i((int)x - 1, (int)y - 1), - new Vector2i((int)x, (int)y - 1), - new Vector2i((int)x + 1, (int)y - 1), - new Vector2i((int)x - 1, (int)y + 0), - new Vector2i((int)x, (int)y + 0), - new Vector2i((int)x + 1, (int)y + 0), - new Vector2i((int)x - 1, (int)y + 1), - new Vector2i((int)x, (int)y + 1), - new Vector2i((int)x + 1, (int)y + 1), + new Vector2i(pos.x - 1, pos.y - 1), + new Vector2i(pos.x, pos.y - 1), + new Vector2i(pos.x + 1, pos.y - 1), + new Vector2i(pos.x - 1, pos.y + 0), + new Vector2i(pos.x, pos.y + 0), + new Vector2i(pos.x + 1, pos.y + 0), + new Vector2i(pos.x - 1, pos.y + 1), + new Vector2i(pos.x, pos.y + 1), + new Vector2i(pos.x + 1, pos.y + 1), }; } @@ -188,11 +187,6 @@ public class Tile extends WorldObject implements IWorkable { } else return "Tilled Soil"; } - @Override - public Vector4f getWorldBox() { - return new Vector4f(x, y, x+1, y+1); - } - public String toThingsString() { if(stuff.size() == 0) return " - Nothing"; String str = ""; diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/BuildLayer.java b/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/BuildLayer.java index 1648041..12e3f35 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/BuildLayer.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/BuildLayer.java @@ -7,6 +7,7 @@ import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.engine.scenegraph.IMouseCaptureArea; import xyz.valnet.engine.scenegraph.ITransient; import xyz.valnet.hadean.gameobjects.Camera; +import xyz.valnet.hadean.interfaces.BuildableMetadata; import xyz.valnet.hadean.interfaces.IBuildLayerListener; import xyz.valnet.hadean.util.Layers; @@ -20,6 +21,12 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi private IBuildLayerListener listener = null; + private BuildableMetadata.Type type = BuildableMetadata.Type.AREA; + + public void setBuildType(BuildableMetadata.Type type) { + this.type = type; + } + @Override protected void connect() { camera = get(Camera.class); @@ -28,6 +35,8 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi @Override public void update(float dTime) { if(listener == null) return; + if(type == BuildableMetadata.Type.SINGLE && mouseDown) return; + broadcastWorldCoords(); } @@ -77,27 +86,33 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi if(button == 1 && active && hovered) { listener.cancel(); } else if(button == 0 && active && hovered) { + // TODO this conversion in negative numbers definitely works wrong. Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt(); mouseDown = true; x = worldcoords.x; y = worldcoords.y; + if(type == BuildableMetadata.Type.SINGLE) { + listener.build(x, y); + } } } @Override public void mouseUp(int button) { if(button == 0 && active && mouseDown) { - Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt(); mouseDown = false; - int x1 = x; - int y1 = y; - int x2 = worldcoords.x; - int y2 = worldcoords.y; - int minX = Math.min(x1, x2); - int minY = Math.min(y1, y2); - int maxX = Math.max(x1, x2); - int maxY = Math.max(y1, y2); - listener.build(minX, minY, maxX, maxY); + if(type == BuildableMetadata.Type.AREA) { + Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt(); + int x1 = x; + int y1 = y; + int x2 = worldcoords.x; + int y2 = worldcoords.y; + int minX = Math.min(x1, x2); + int minY = Math.min(y1, y2); + int maxX = Math.max(x1, x2); + int maxY = Math.max(y1, y2); + listener.build(minX, minY, maxX, maxY); + } } } diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/ui/tabs/BuildTab.java b/src/main/java/xyz/valnet/hadean/gameobjects/ui/tabs/BuildTab.java index 016c06f..055f803 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/ui/tabs/BuildTab.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/ui/tabs/BuildTab.java @@ -57,7 +57,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap private record BuildableRecord( String name, Constructor constructor, - int type + BuildableMetadata.Type type ) { } @@ -85,7 +85,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap } String category = annotation.category(); String name = annotation.name(); - int type = annotation.type(); + BuildableMetadata.Type type = annotation.type(); if(!buildables.containsKey(category)) buildables.put(category, new ArrayList()); @@ -163,6 +163,11 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap if(buildableRecord == null) deselectBuilding(); if (selectedBuildable == null) activateBuildLayer(); selectedBuildable = buildableRecord; + swapBuildLayerType(selectedBuildable.type); + } + + private void swapBuildLayerType(BuildableMetadata.Type type) { + buildLayer.setBuildType(type); } private void activateBuildLayer() { @@ -191,6 +196,22 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap // opened.set(false); } + @Override + public void build(int x1, int y1) { + if(selectedBuildable == null) return; + try { + IBuildable building = selectedBuildable.constructor.newInstance(); + if(building instanceof GameObject) { + add((GameObject) building); + } + building.buildAt(x1, y1); + } catch (Exception e) { + System.out.println(e); + } + + // opened.set(false); + } + @Override public void cancel() { if(selectedBuildable == null) { diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Bed.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Bed.java index e4ebe03..5d3f430 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Bed.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Bed.java @@ -4,10 +4,10 @@ import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector4f; import xyz.valnet.hadean.gameobjects.Job; import xyz.valnet.hadean.gameobjects.JobBoard; +import xyz.valnet.hadean.gameobjects.Tile; import xyz.valnet.hadean.gameobjects.worldobjects.items.Item; import xyz.valnet.hadean.gameobjects.worldobjects.items.Log; import xyz.valnet.hadean.interfaces.BuildableMetadata; -import xyz.valnet.hadean.interfaces.IBuildable; import xyz.valnet.hadean.interfaces.IItemReceiver; import xyz.valnet.hadean.interfaces.ISelectable; import xyz.valnet.hadean.interfaces.IWorkable; @@ -19,8 +19,8 @@ import xyz.valnet.hadean.util.detail.Detail; import xyz.valnet.hadean.util.detail.ObjectDetail; import xyz.valnet.hadean.util.detail.PercentDetail; -@BuildableMetadata(category = "Furniture", name = "Bed", type = BuildableMetadata.SINGLE) -public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWorkable, ISelectable { +@BuildableMetadata(category = "Furniture", name = "Bed", type = BuildableMetadata.Type.SINGLE) +public class Bed extends Buildable implements IItemReceiver, IWorkable, ISelectable { private int logs = 0; private float work = 0; @@ -28,11 +28,15 @@ public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWork private Job job = null; + @Override + protected Vector2i getDefaultDimensions() { + return new Vector2i(1, 2); + } + @Override protected void create() { super.create(); job = add(new Job("Build Bed")); - Log log = get(Log.class); job.addStep(job.new PickupItemByPredicate(Log.LOG_PREDICATE)); job.addStep(job.new DropoffPredicateAtItemReceiver(this, Log.LOG_PREDICATE)); job.addStep(job.new Work(this)); @@ -42,15 +46,16 @@ public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWork @Override public void render() { super.render(); + Vector2i pos = getWorldPosition().xy(); if(isBuilt()) { - camera.draw(Layers.GROUND, Assets.bed, (int)x, (int)y, 1, 2); + camera.draw(Layers.GROUND, Assets.bed, pos.x, pos.y, 1, 2); } else { float p = work / maxWork; float b = 4; Assets.flat.pushColor(new Vector4f(b, b, b, 0.5f)); - camera.draw(Layers.GROUND, Assets.bed, (int)x, (int)y, 1, 2); + camera.draw(Layers.GROUND, Assets.bed, pos.x, pos.y, 1, 2); Assets.flat.popColor(); if(logs > 0) { @@ -61,24 +66,11 @@ public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWork } } - @Override - public void buildAt(int x, int y, int w, int h) { - this.x = x; - this.y = y; - this.w = 1; - this.h = 2; - } - @Override public String getName() { return "Bed"; } - @Override - public Vector4f getWorldBox() { - return new Vector4f(x, y, x+w, y+h); - } - @Override public boolean receive(Item item) { if(item == null) return false; @@ -99,16 +91,17 @@ public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWork } private Vector2i[] getBorders() { + Vector2i pos = getWorldPosition().xy(); return new Vector2i[] { - new Vector2i((int) x, (int) y - 1), + new Vector2i(pos.x, pos.y - 1), - new Vector2i((int) x - 1, (int) y), - new Vector2i((int) x + 1, (int) y), + new Vector2i(pos.x - 1, pos.y), + new Vector2i(pos.x + 1, pos.y), - new Vector2i((int) x - 1, (int) y + 1), - new Vector2i((int) x + 1, (int) y + 1), + new Vector2i(pos.x - 1, pos.y + 1), + new Vector2i(pos.x + 1, pos.y + 1), - new Vector2i((int) x, (int) y + 2), + new Vector2i(pos.x, pos.y + 2), }; } @@ -145,5 +138,19 @@ public class Bed extends WorldObject implements IBuildable, IItemReceiver, IWork new ObjectDetail("Logs", logs), }; } - + + @Override + public boolean isWalkable() { + return false; + } + + @Override + public boolean shouldRemove() { + return false; + } + + @Override + public void onRemove() { + + } } diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Buildable.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Buildable.java new file mode 100644 index 0000000..4567862 --- /dev/null +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Buildable.java @@ -0,0 +1,27 @@ +package xyz.valnet.hadean.gameobjects.worldobjects; + +import xyz.valnet.engine.math.Vector2i; +import xyz.valnet.hadean.gameobjects.Tile; +import xyz.valnet.hadean.interfaces.IBuildable; +import xyz.valnet.hadean.interfaces.ITileThing; + +public abstract class Buildable extends WorldObject implements IBuildable, ITileThing { + + protected Vector2i getDefaultDimensions() { + return new Vector2i(1, 1); + } + + @Override + public void buildAt(int x, int y, int w, int h) { + setPosition(x, y, w, h); + } + + @Override + public void buildAt(int x, int y) { + Vector2i dim = getDefaultDimensions(); + setPosition(x, y, dim.x, dim.y); + } + + @Override + public void onPlaced(Tile tile) {} +} diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/FarmPlot.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/FarmPlot.java index 435c956..930f70e 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/FarmPlot.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/FarmPlot.java @@ -1,34 +1,27 @@ package xyz.valnet.hadean.gameobjects.worldobjects; import xyz.valnet.engine.math.Vector4f; +import xyz.valnet.engine.math.Vector4i; import xyz.valnet.hadean.gameobjects.Tile; import xyz.valnet.hadean.interfaces.BuildableMetadata; -import xyz.valnet.hadean.interfaces.IBuildable; import xyz.valnet.hadean.interfaces.ISelectable; -import xyz.valnet.hadean.interfaces.ITileThing; 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; @BuildableMetadata(category = "Zones", name = "Farm Plot") -public class FarmPlot extends WorldObject implements ISelectable, ITileThing, IBuildable { - - private int w, h; +public class FarmPlot extends Buildable implements ISelectable { @Override public void renderAlpha() { if(!visible) return; + Vector4i pos = getWorldPosition(); Assets.flat.pushColor(new Vector4f(0.4f, 1f, 0.3f, 0.2f)); - camera.draw(Layers.GROUND, Assets.whiteBox, x, y, w, h); + camera.draw(Layers.GROUND, Assets.whiteBox, pos.x, pos.y, pos.z, pos.w); Assets.flat.popColor(); } - @Override - public Vector4f getWorldBox() { - return new Vector4f(x, y, x + w, y + h); - } - private static Action TOGGLE_VISIBILITY = new Action("Hide\n----\nShow"); @Override @@ -65,20 +58,6 @@ public class FarmPlot extends WorldObject implements ISelectable, ITileThing, IB } - @Override - public void buildAt(int x, int y, int w, int h) { - this.x = x; - this.y = y; - this.w = w; - this.h = h; - - for(int i = x; i < x + w; i ++) { - for(int j = y; j < y + h; j ++) { - terrain.getTile(i, j).placeThing(this); - } - } - } - @Override public String getName() { return "Farm Plot"; diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Rice.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Rice.java index cd7a927..89037c8 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Rice.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Rice.java @@ -1,6 +1,7 @@ package xyz.valnet.hadean.gameobjects.worldobjects; import xyz.valnet.engine.math.Vector2f; +import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector4f; import xyz.valnet.hadean.gameobjects.worldobjects.items.Item; import xyz.valnet.hadean.util.Action; @@ -12,16 +13,16 @@ public class Rice extends Item { public Rice(int x, int y) { - this.x = x; - this.y = y; + setPosition(x, y); } @Override public void render() { - camera.draw(Layers.AIR, Assets.riceBag, x, y); + Vector2i pos = getWorldPosition().xy(); + camera.draw(Layers.AIR, Assets.riceBag, pos.x, pos.y); Assets.flat.pushColor(Vector4f.black); - Vector2f screeCoords = camera.world2screen(x, y); + Vector2f screeCoords = camera.world2screen(pos.x, pos.y); Assets.miniFont.drawString("123", (int)screeCoords.x, (int)screeCoords.y); Assets.flat.popColor(); } @@ -39,11 +40,6 @@ public class Rice extends Item { @Override public void onRemove() {} - @Override - public Vector4f getWorldBox() { - return new Vector4f(x, y, x + 1, y + 1); - } - @Override public Action[] getActions() { return new Action[] {}; diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Stockpile.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Stockpile.java index e1f0bce..ec318f2 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Stockpile.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Stockpile.java @@ -1,21 +1,20 @@ package xyz.valnet.hadean.gameobjects.worldobjects; +import java.util.Set; + import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector4f; +import xyz.valnet.engine.math.Vector4i; import xyz.valnet.hadean.gameobjects.Tile; import xyz.valnet.hadean.interfaces.BuildableMetadata; -import xyz.valnet.hadean.interfaces.IBuildable; import xyz.valnet.hadean.interfaces.ISelectable; -import xyz.valnet.hadean.interfaces.ITileThing; 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; @BuildableMetadata(category = "Zones", name = "Stockpile") -public class Stockpile extends WorldObject implements ISelectable, ITileThing, IBuildable { - - private int w, h; +public class Stockpile extends Buildable implements ISelectable { @Override public void render() { @@ -24,43 +23,20 @@ public class Stockpile extends WorldObject implements ISelectable, ITileThing, I @Override public void renderAlpha() { if(!visible) return; + Vector4i pos = getWorldPosition(); Assets.flat.pushColor(new Vector4f(1f, 0.2f, 0.1f, 0.3f)); - camera.draw(Layers.TILES, Assets.whiteBox, x, y, w, h); + camera.draw(Layers.TILES, Assets.whiteBox, pos.x, pos.y, pos.z, pos.w); Assets.flat.popColor(); } - @Override - public void update(float dTime) { - super.update(dTime); - - } - - private Tile[] getTiles() { - Vector4f box = getWorldBox(); - int count = 0; - Tile[] tiles = new Tile[(int)box.z * (int)box.w]; - for(float x = box.x; x < box.z; x ++) { - for(float y = box.y; y < box.w; y ++) { - tiles[count] = terrain.getTile((int)x, (int)y); - count ++; - } - } - return tiles; - } - public Vector2i getFreeTile() { - Tile[] tiles = getTiles(); + Set tiles = getTiles(); for(Tile tile : tiles) { if(tile.isTileFree()) return tile.getCoords(); } return null; } - @Override - public Vector4f getWorldBox() { - return new Vector4f(x, y, x + w, y + h); - } - private static Action TOGGLE_VISIBILITY = new Action("Hide / Show"); @Override @@ -97,20 +73,6 @@ public class Stockpile extends WorldObject implements ISelectable, ITileThing, I } - @Override - public void buildAt(int x, int y, int w, int h) { - this.x = x; - this.y = y; - this.w = w; - this.h = h; - - for(int i = x; i < x + w; i ++) { - for(int j = y; j < y + h; j ++) { - terrain.getTile(i, j).placeThing(this); - } - } - } - @Override public String getName() { return "Stockpile"; diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Tree.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Tree.java index ddc89d7..e8de3b6 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Tree.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/Tree.java @@ -24,20 +24,20 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka private Job chopJob = null; public Tree(int x, int y) { - this.x = x; - this.y = y; + setPosition(x, y); } @Override public void render() { + Vector2i pos = getWorldPosition().xy(); // Assets.flat.pushColor(new Vector4f(1 - getProgress(), 1 - getProgress(), 1 - getProgress(), 1.0f)); - camera.draw(Layers.AIR, Assets.tree, x - 1, y - 2, 3, 3); + camera.draw(Layers.AIR, Assets.tree, pos.x - 1, pos.y - 2, 3, 3); // Assets.flat.popColor(); if(chopJob != null) { if(getProgress() > 0) { - camera.drawProgressBar(getProgress(), new Vector4f(x - 1, y - 2, x + 2, y + 1)); + camera.drawProgressBar(getProgress(), new Vector4f(pos.x - 1, pos.y - 2, pos.x + 2, pos.y + 1)); } - camera.draw(Layers.MARKERS, Assets.lilAxe, x, y); + camera.draw(Layers.MARKERS, Assets.lilAxe, pos.x, pos.y); } } @@ -46,11 +46,6 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka return false; } - @Override - public Vector4f getWorldBox() { - return new Vector4f(x, y, x + 1, y + 1); - } - public static final Action ACTION_CHOP = new Action("Chop"); @Override @@ -74,11 +69,12 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka @Override public Vector2i[] getWorkablePositions() { + Vector2i pos = getWorldPosition().xy(); return new Vector2i[] { - new Vector2i((int)x, (int)y - 1), - new Vector2i((int)x, (int)y + 1), - new Vector2i((int)x - 1, (int)y), - new Vector2i((int)x + 1, (int)y) + new Vector2i(pos.x, pos.y - 1), + new Vector2i(pos.x, pos.y + 1), + new Vector2i(pos.x - 1, pos.y), + new Vector2i(pos.x + 1, pos.y) }; } @@ -123,7 +119,8 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka @Override public void onRemove() { - Log log = new Log((int)x, (int)y); + Vector2i pos = getWorldPosition().xy(); + Log log = new Log(pos.x, pos.y); getTile().placeThing(log); } diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/WorldObject.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/WorldObject.java index 52ebc9d..9bc5d71 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/WorldObject.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/WorldObject.java @@ -1,37 +1,114 @@ package xyz.valnet.hadean.gameobjects.worldobjects; -import xyz.valnet.engine.math.Vector2f; +import java.util.HashSet; +import java.util.Set; + import xyz.valnet.engine.math.Vector4f; +import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.hadean.gameobjects.Camera; import xyz.valnet.hadean.gameobjects.Terrain; import xyz.valnet.hadean.gameobjects.Tile; +import xyz.valnet.hadean.interfaces.ITileThing; public abstract class WorldObject extends GameObject { - protected float x; - protected float y; - protected float w; - protected float h; + private int x; + private int y; + private int w; + private int h; protected Camera camera; protected Terrain terrain; + private Set linkedTiles; + + @Override + protected void ready() { + if(linkedTiles == null) linkedTiles = new HashSet(); + } + @Override protected void connect() { camera = get(Camera.class); terrain = get(Terrain.class); } - public Tile getTile() { - return terrain.getTile((int)x, (int)y); + @Override + protected void start() { + setPosition(x, y, w, h); } - public Vector2f getWorldPosition() { - return new Vector2f(x, y); + private void updateTileLinks(Set tiles) { + if(tiles == null || tiles.size() == 0) return; + if(!(this instanceof ITileThing)) return; + + Set removeTiles = new HashSet(); + Set addTiles = new HashSet(); + + for(Tile tile : tiles) { + if(linkedTiles.contains(tile)) continue; + addTiles.add(tile); + } + + for(Tile tile : linkedTiles) { + if(tiles.contains(tile)) continue; + removeTiles.add(tile); + } + + for(Tile tile : removeTiles) { + linkedTiles.remove(tile); + tile.remove(this); + } + + for(Tile tile : addTiles) { + linkedTiles.add(tile); + tile.placeThing((ITileThing) this); + } + + } + + public void setPosition(Vector4i vector) { + setPosition(vector.x, vector.y, vector.z, vector.w); + } + + public void setPosition(int x, int y) { + setPosition(x, y, 1, 1); + } + + public void setPosition(int x, int y, int w, int h) { + this.x = x; + this.y = y; + this.w = w; + this.h = h; + if(terrain == null) return; + + Set tiles = new HashSet(); + for(int i = 0; i < w; i ++) { + for(int j = 0; j < h; j ++) { + tiles.add(terrain.getTile(x + i, y + j)); + } + } + + updateTileLinks(tiles); + } + + public Tile getTile() { + return terrain.getTile(x, y); + } + + public Set getTiles() { + return linkedTiles; + } + + public Vector4i getWorldPosition() { + return new Vector4i(x, y, w, h); } public abstract String getName(); - public abstract Vector4f getWorldBox(); + + public Vector4f getWorldBox() { + return new Vector4f(x, y, x + w, y + h); + } } diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/agents/Agent.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/agents/Agent.java index 77176a3..44e5d97 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/agents/Agent.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/agents/Agent.java @@ -40,11 +40,12 @@ public abstract class Agent extends WorldObject implements ISelectable { } public Vector2f getCalculatedPosition() { - if(path == null || path.isComplete()) return getWorldPosition(); + if(path == null || path.isComplete()) return getWorldPosition().xy().asFloat(); + Vector2i pos = getWorldPosition().xy(); Vector2f nextPos = path.peek().getPosition().asFloat(); return new Vector2f( - lerp(x, nextPos.x, frameCounter / (float)speed), - lerp(y, nextPos.y, frameCounter / (float)speed) + lerp(pos.x, nextPos.x, frameCounter / (float)speed), + lerp(pos.y, nextPos.y, frameCounter / (float)speed) ); } @@ -68,8 +69,7 @@ public abstract class Agent extends WorldObject implements ISelectable { frameCounter += dTime; if(frameCounter >= speed) { Vector2i nextPos = path.pop().getPosition(); - this.x = nextPos.x; - this.y = nextPos.y; + setPosition(nextPos.x, nextPos.y); if(nextPath != null) { path = nextPath; nextPath = null; @@ -92,16 +92,17 @@ public abstract class Agent extends WorldObject implements ISelectable { private void correctPath() { if(path != null && path.isComplete()) path = null; if(path == null) return; - if(path.peek().getPosition().equals(this.getWorldPosition().asInt())) { + if(path.peek().getPosition().equals(this.getWorldPosition().xy())) { path.pop(); } if(path != null && path.isComplete()) path = null; if(path == null) return; Tile nextTile = terrain.getTile(path.peek().getPosition()); if(!nextTile.isWalkable()) { + Vector2i pos = getWorldPosition().xy(); path = pathfinder.getPath( - (int)Math.floor(x), - (int)Math.floor(y), + pos.x, + pos.y, path.dst.x, path.dst.y ); @@ -124,7 +125,8 @@ public abstract class Agent extends WorldObject implements ISelectable { private Path nextPath = null; public void goTo(int x, int y) { - Path newPath = pathfinder.getPath((int)this.x, (int)this.y, x, y); + Vector2i pos = getWorldPosition().xy(); + Path newPath = pathfinder.getPath(pos.x, pos.y, x, y); if(path == null) { path = newPath; frameCounter -= 0; @@ -134,7 +136,7 @@ public abstract class Agent extends WorldObject implements ISelectable { } public void goToClosest(Vector2i[] destinations) { - Path newPath = pathfinder.getBestPath(this.getWorldPosition().asInt(), destinations); + Path newPath = pathfinder.getBestPath(getWorldPosition().xy(), destinations); if(path == null) { path = newPath; frameCounter = 0; @@ -148,9 +150,10 @@ public abstract class Agent extends WorldObject implements ISelectable { } public void wander() { + Vector2i pos = getWorldPosition().xy(); int randomX = (int)Math.floor(Math.random() * Terrain.WORLD_SIZE); int randomY = (int)Math.floor(Math.random() * Terrain.WORLD_SIZE); - path = pathfinder.getPath((int)x, (int)y, randomX, randomY); + path = pathfinder.getPath(pos.x, pos.y, randomX, randomY); } @Override @@ -164,7 +167,8 @@ public abstract class Agent extends WorldObject implements ISelectable { glBegin(GL_LINES); Vector2f u, v; - if(node.from == null) u = camera.world2screen(x, y); + Vector2i pos = getWorldPosition().xy(); + if(node.from == null) u = camera.world2screen(pos.x, pos.y); else u = camera.world2screen(node.from.x + 0.5f, node.from.y + 0.5f); v = camera.world2screen(node.x + 0.5f, node.y + 0.5f); diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Boulder.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Boulder.java index 4ec7bcc..fa31d73 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Boulder.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Boulder.java @@ -1,5 +1,6 @@ package xyz.valnet.hadean.gameobjects.worldobjects.items; +import xyz.valnet.engine.math.Vector2i; import xyz.valnet.hadean.util.Assets; import xyz.valnet.hadean.util.Layers; import xyz.valnet.hadean.util.detail.Detail; @@ -7,8 +8,7 @@ import xyz.valnet.hadean.util.detail.Detail; public class Boulder extends Item { public Boulder(int x, int y) { - this.x = x; - this.y = y; + setPosition(x, y); } @Override @@ -18,7 +18,8 @@ public class Boulder extends Item { @Override public void render() { - camera.draw(Layers.GROUND, Assets.bigRock, x, y); + Vector2i pos = getWorldPosition().xy(); + camera.draw(Layers.GROUND, Assets.bigRock, pos.x, pos.y); } @Override diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Item.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Item.java index 11a60c9..65cecaa 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Item.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Item.java @@ -37,11 +37,6 @@ public abstract class Item extends WorldObject implements ISelectable, ITileThin return null; } - @Override - public Vector4f getWorldBox() { - return new Vector4f(x, y, x + 1, y + 1); - } - public static final Action HAUL = new Action("Haul"); public static final Action CANCEL_HAUL = new Action("Cancel\n Haul"); @@ -57,7 +52,7 @@ public abstract class Item extends WorldObject implements ISelectable, ITileThin public void renderAlpha() { if(haulJob != null) { // Assets.flat.pushColor(Vector4f.opacity(1f)); - camera.draw(Layers.MARKERS, Assets.haulArrow, getWorldPosition()); + camera.draw(Layers.MARKERS, Assets.haulArrow, getWorldPosition().xy().asFloat()); // Assets.flat.popColor(); } } @@ -90,8 +85,7 @@ public abstract class Item extends WorldObject implements ISelectable, ITileThin @Override public void onPlaced(Tile tile) { - this.x = tile.getCoords().x; - this.y = tile.getCoords().y; + setPosition(tile.getWorldPosition()); } public boolean matches(IItemPredicate itemPredicate) { diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Log.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Log.java index f3aec4b..2757d43 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Log.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/items/Log.java @@ -1,5 +1,6 @@ package xyz.valnet.hadean.gameobjects.worldobjects.items; +import xyz.valnet.engine.math.Vector2i; import xyz.valnet.hadean.interfaces.IItemPredicate; import xyz.valnet.hadean.util.Assets; import xyz.valnet.hadean.util.Layers; @@ -15,13 +16,13 @@ public class Log extends Item { public static IItemPredicate LOG_PREDICATE = (item) -> (item instanceof Log); public Log(int x, int y) { - this.x = x; - this.y = y; + setPosition(x, y); } @Override public void render() { - camera.draw(Layers.GROUND, Assets.log, x, y); + Vector2i pos = getWorldPosition().xy(); + camera.draw(Layers.GROUND, Assets.log, pos.x, pos.y); } @Override diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/pawn/JobActivity.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/pawn/JobActivity.java index 45e66c9..31d373d 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/pawn/JobActivity.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/pawn/JobActivity.java @@ -43,7 +43,7 @@ public class JobActivity extends Activity { } private boolean isAtJobStepLocation() { - return worker.getWorldPosition().asInt().isOneOf(job.getCurrentStep().getLocations()); + return worker.getWorldPosition().xy().isOneOf(job.getCurrentStep().getLocations()); } private void goToJobStepLocation() { diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/pawn/Pawn.java b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/pawn/Pawn.java index 6359979..8a80bca 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/pawn/Pawn.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/worldobjects/pawn/Pawn.java @@ -103,8 +103,10 @@ public class Pawn extends Agent { } protected void create() { - x = (int) (Math.random() * Terrain.WORLD_SIZE); - y = (int) (Math.random() * Terrain.WORLD_SIZE); + setPosition( + (int) (Math.random() * Terrain.WORLD_SIZE), + (int) (Math.random() * Terrain.WORLD_SIZE) + ); } @Override @@ -133,11 +135,6 @@ public class Pawn extends Agent { }); } - @Override - public Vector2f getWorldPosition() { - return new Vector2f(x, y); - } - @Override public String getName() { return name; diff --git a/src/main/java/xyz/valnet/hadean/interfaces/BuildableMetadata.java b/src/main/java/xyz/valnet/hadean/interfaces/BuildableMetadata.java index 89b2110..89b6978 100644 --- a/src/main/java/xyz/valnet/hadean/interfaces/BuildableMetadata.java +++ b/src/main/java/xyz/valnet/hadean/interfaces/BuildableMetadata.java @@ -6,10 +6,12 @@ import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) public @interface BuildableMetadata { - public static int AREA = 0; - public static int SINGLE = 1; + public enum Type { + AREA, + SINGLE + } public String name(); public String category(); - public int type() default AREA; + public Type type() default Type.AREA; } diff --git a/src/main/java/xyz/valnet/hadean/interfaces/IBuildLayerListener.java b/src/main/java/xyz/valnet/hadean/interfaces/IBuildLayerListener.java index cc68e1a..99bbc3b 100644 --- a/src/main/java/xyz/valnet/hadean/interfaces/IBuildLayerListener.java +++ b/src/main/java/xyz/valnet/hadean/interfaces/IBuildLayerListener.java @@ -3,5 +3,6 @@ package xyz.valnet.hadean.interfaces; public interface IBuildLayerListener { public void update(int x, int y, int w, int h); public void build(int x, int y, int w, int h); + public void build(int x, int y); public void cancel(); } diff --git a/src/main/java/xyz/valnet/hadean/interfaces/IBuildable.java b/src/main/java/xyz/valnet/hadean/interfaces/IBuildable.java index f2e2117..a3fc088 100644 --- a/src/main/java/xyz/valnet/hadean/interfaces/IBuildable.java +++ b/src/main/java/xyz/valnet/hadean/interfaces/IBuildable.java @@ -3,5 +3,6 @@ package xyz.valnet.hadean.interfaces; public interface IBuildable { public void buildAt(int x, int y, int w, int h); + public void buildAt(int x, int y); }