Skip to content

Commit

Permalink
Added debug shortcut for skipping the main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed May 1, 2024
1 parent c4bcc7a commit a4a8eb0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions game/src/main/scala/hexacraft/gui/comp/Component.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import hexacraft.renderer.*
import hexacraft.shaders.{ColorShader, FancyRectShader, ImageShader}
import hexacraft.text.{Fonts, Text, TextMaster}
import hexacraft.text.font.Font

import org.joml.{Matrix4f, Vector2f, Vector4f}

abstract class Component {
Expand Down
8 changes: 8 additions & 0 deletions game/src/main/scala/hexacraft/main/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import hexacraft.infra.audio.AudioSystem
import hexacraft.infra.fs.FileSystem
import hexacraft.infra.os.OSUtils
import hexacraft.infra.window.WindowSystem
import hexacraft.world.WorldSettings

import java.io.File

Expand All @@ -21,6 +22,13 @@ object Main {
val windowSystem = WindowSystem.create()

val window = new MainWindow(isDebug, saveFolder, fs, audioSystem, windowSystem)

val startWorldName = System.getProperty("hexacraft.start_world")
if isDebug && startWorldName != null then {
val worldSaveDir = new File(saveFolder, s"saves/$startWorldName")
window.setNextScene(SceneRoute.Game(worldSaveDir, WorldSettings.none, true, false, null))
}

try {
window.run()
} catch {
Expand Down
11 changes: 7 additions & 4 deletions game/src/main/scala/hexacraft/main/MainWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MainWindow(
private val keyboard: GameKeyboard = new GameKeyboard.GlfwKeyboard(window)

private var scene: Option[Scene] = None
private var nextScene: Option[SceneRoute] = None
private var nextScene: Option[SceneRoute] = Some(SceneRoute.Main)

private val router = makeSceneRouter()

Expand All @@ -57,14 +57,18 @@ class MainWindow(
mouse.skipNextMouseMovedUpdate()
}

def setNextScene(scene: SceneRoute): Unit = {
this.nextScene = Some(scene)
}

private def switchSceneIfNeeded(): Unit = {
if nextScene.isDefined then {
val (s, rx) = router.route(nextScene.get)
nextScene = None

rx.onEvent {
case MainRouter.Event.ChangeScene(newRoute) =>
nextScene = Some(newRoute)
setNextScene(newRoute)
case MainRouter.Event.QuitRequested =>
window.requestClose()
}
Expand Down Expand Up @@ -250,8 +254,6 @@ class MainWindow(
initGL()
audioSystem.init()

nextScene = Some(SceneRoute.Main)

try {
resetMousePos()
loop()
Expand Down Expand Up @@ -314,6 +316,7 @@ class MainWindow(
// OpenGL.glEnable(OpenGL.State.MultiSample)
OpenGL.glEnable(OpenGL.State.DepthTest)
OpenGL.glDepthFunc(OpenGL.DepthFunc.LessThanOrEqual)
OpenGL.glBlendFunc(OpenGL.BlendFactor.SrcAlpha, OpenGL.BlendFactor.OneMinusSrcAlpha)
OpenGL.glEnable(OpenGL.State.CullFace)

if isDebug && OpenGL.hasDebugExtension then {
Expand Down

0 comments on commit a4a8eb0

Please sign in to comment.