Re-introduce prototype code

This commit is contained in:
2024-08-23 00:39:15 -07:00
parent 8b3d1bed8a
commit 2fb0c364ca
62 changed files with 1685 additions and 187 deletions

61
src/app/App.cs Normal file
View File

@@ -0,0 +1,61 @@
using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
namespace GameJamDungeon
{
public interface IApp : ICanvasLayer, IProvide<IAppRepo>;
[Meta(typeof(IAutoNode))]
public partial class App : CanvasLayer, IApp
{
public override void _Notification(int what) => this.Notify(what);
public const string GAME_SCENE_PATH = "res://src/game/Game.tscn";
public IGame Game { get; set; } = default!;
public IInstantiator Instantiator { get; set; } = default!;
IAppRepo IProvide<IAppRepo>.Value() => AppRepo;
public IAppRepo AppRepo { get; set; } = default!;
public IAppLogic AppLogic { get; set; } = default!;
public AppLogic.IBinding AppBinding { get; set; } = default!;
[Node] public ISubViewport GameWindow { get; set; } = default!;
public void Initialize()
{
Instantiator = new Instantiator(GetTree());
AppRepo = new AppRepo();
AppLogic = new AppLogic();
AppLogic.Set(AppRepo);
this.Provide();
}
public void OnReady()
{
Game = Instantiator.LoadAndInstantiate<Game>(GAME_SCENE_PATH);
GameWindow.AddChildEx(Game);
AppBinding = AppLogic.Bind();
AppLogic.Start();
Instantiator.SceneTree.Paused = false;
}
public void OnNewGame() => AppLogic.Input(new AppLogic.Input.NewGame());
public void OnQuit() => AppLogic.Input(new AppLogic.Input.QuitGame());
public void OnExitTree()
{
AppLogic.Stop();
AppBinding.Dispose();
AppRepo.Dispose();
}
}
}

View File

@@ -1,89 +1,22 @@
[gd_scene load_steps=8 format=3 uid="uid://cagfc5ridmteu"]
[gd_scene load_steps=2 format=3 uid="uid://cagfc5ridmteu"]
[ext_resource type="PackedScene" uid="uid://wg25dg65ksgg" path="res://src/map/dungeon/DungeonGenerator.tscn" id="1_eapuk"]
[ext_resource type="PackedScene" uid="uid://dhpwwqow1ahrc" path="res://src/map/dungeon/rooms/Room1.tscn" id="2_x112h"]
[ext_resource type="Script" path="res://addons/SimpleDungeons/DungeonRoom3D.gd" id="3_614ds"]
[ext_resource type="PackedScene" uid="uid://bn4gslp2gk8ds" path="res://src/map/dungeon/corridor/Corridor.tscn" id="4_tex41"]
[ext_resource type="Script" path="res://src/character_controller_3d.gd" id="4_vtqs3"]
[ext_resource type="Script" path="res://src/app/App.cs" id="1_rt73h"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_ult2r"]
radius = 0.25
height = 0.5
[node name="App" type="CanvasLayer"]
script = ExtResource("1_rt73h")
[sub_resource type="Environment" id="Environment_3njg4"]
[node name="SubViewportContainer" type="SubViewportContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
stretch = true
[node name="App" type="Node"]
[node name="DungeonGenerator3D" parent="." instance=ExtResource("1_eapuk")]
[node name="RoomsContainer" type="Node3D" parent="DungeonGenerator3D"]
[node name="DungeonRoom3D_0" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("2_x112h")]
transform = Transform3D(1.19249e-08, 0, -1, 0, 1, 0, 1, 0, 1.19249e-08, 35, 0, 45)
script = ExtResource("3_614ds")
[node name="DungeonRoom3D_1" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("2_x112h")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 35)
script = ExtResource("3_614ds")
[node name="Corridor_2" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25, 0, 45)
script = ExtResource("3_614ds")
[node name="Corridor_3" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15, 0, 45)
script = ExtResource("3_614ds")
[node name="Corridor_4" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, 45)
script = ExtResource("3_614ds")
[node name="Corridor_5" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, 45)
script = ExtResource("3_614ds")
[node name="Corridor_6" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, 45)
script = ExtResource("3_614ds")
[node name="Corridor_7" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 45)
script = ExtResource("3_614ds")
[node name="Corridor_8" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 45, 0, 45)
script = ExtResource("3_614ds")
[node name="Corridor_9" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 25)
script = ExtResource("3_614ds")
[node name="Corridor_10" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, 25)
script = ExtResource("3_614ds")
[node name="Corridor_11" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, 25)
script = ExtResource("3_614ds")
[node name="Corridor_12" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, 25)
script = ExtResource("3_614ds")
[node name="Corridor_13" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("4_tex41")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, 35)
script = ExtResource("3_614ds")
[node name="CharacterBody3D" type="CharacterBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 14.0223, -3.8587, -16.1332)
script = ExtResource("4_vtqs3")
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
shape = SubResource("CapsuleShape3D_ult2r")
[node name="OmniLight3D" type="OmniLight3D" parent="CharacterBody3D"]
[node name="Camera3D" type="Camera3D" parent="CharacterBody3D"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_3njg4")
[node name="GameWindow" type="SubViewport" parent="SubViewportContainer"]
unique_name_in_owner = true
transparent_bg = true
handle_input_locally = false
audio_listener_enable_3d = true
size = Vector2i(1920, 1080)
render_target_update_mode = 4

68
src/app/domain/AppRepo.cs Normal file
View File

@@ -0,0 +1,68 @@
using System;
namespace GameJamDungeon
{
public interface IAppRepo : IDisposable
{
event Action? GameEntered;
event Action? GameExited;
event Action? SplashScreenSkipped;
event Action? MainMenuEntered;
void SkipSplashScreen();
void OnMainMenuEntered();
void OnEnterGame();
void OnExitGame();
void OnGameOver();
}
public class AppRepo : IAppRepo
{
public event Action? SplashScreenSkipped;
public event Action? MainMenuEntered;
public event Action? GameEntered;
public event Action? GameExited;
private bool _disposedValue;
public void SkipSplashScreen() => SplashScreenSkipped?.Invoke();
public void OnMainMenuEntered() => MainMenuEntered?.Invoke();
public void OnEnterGame() => GameEntered?.Invoke();
public void OnExitGame() => GameExited?.Invoke();
public void OnGameOver() => GameExited?.Invoke();
protected void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
// Dispose managed objects.
SplashScreenSkipped = null;
MainMenuEntered = null;
GameEntered = null;
GameExited = null;
}
_disposedValue = true;
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@@ -0,0 +1,18 @@
namespace GameJamDungeon
{
public partial class AppLogic
{
public static class Input
{
public readonly record struct NewGame;
public readonly record struct FadeInFinished;
public readonly record struct FadeOutFinished;
public readonly record struct QuitGame;
public readonly record struct GameOver;
}
}
}

View File

@@ -0,0 +1,30 @@
namespace GameJamDungeon
{
public partial class AppLogic
{
public static class Output
{
public readonly record struct FadeToBlack;
public readonly record struct ShowSplashScreen;
public readonly record struct HideSplashScreen;
public readonly record struct RemoveExistingGame;
public readonly record struct PlayGame;
public readonly record struct ShowGame;
public readonly record struct HideGame;
public readonly record struct SetupGameScene();
public readonly record struct ShowMainMenu;
public readonly record struct ExitGame;
public readonly record struct GameOver;
}
}
}

View File

@@ -0,0 +1,11 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace GameJamDungeon
{
public partial class AppLogic
{
[Meta]
public abstract partial record State : StateLogic<State>;
}
}

14
src/app/state/AppLogic.cs Normal file
View File

@@ -0,0 +1,14 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace GameJamDungeon
{
public interface IAppLogic : ILogicBlock<AppLogic.State>;
[Meta]
[LogicBlock(typeof(State), Diagram = true)]
public partial class AppLogic : LogicBlock<AppLogic.State>, IAppLogic
{
public override Transition GetInitialState() => To<State.SplashScreen>();
}
}

View File

@@ -0,0 +1,25 @@
@startuml AppLogic
state "AppLogic State" as GameJam2024Practice_AppLogic_State {
state "InGame" as GameJam2024Practice_AppLogic_State_InGame
state "MainMenu" as GameJam2024Practice_AppLogic_State_MainMenu
state "SplashScreen" as GameJam2024Practice_AppLogic_State_SplashScreen
state "LeavingMenu" as GameJam2024Practice_AppLogic_State_LeavingMenu
}
GameJam2024Practice_AppLogic_State_InGame --> GameJam2024Practice_AppLogic_State_MainMenu : GameOver
GameJam2024Practice_AppLogic_State_LeavingMenu --> GameJam2024Practice_AppLogic_State_InGame : FadeOutFinished
GameJam2024Practice_AppLogic_State_MainMenu --> GameJam2024Practice_AppLogic_State_LeavingMenu : NewGame
GameJam2024Practice_AppLogic_State_MainMenu --> GameJam2024Practice_AppLogic_State_MainMenu : QuitGame
GameJam2024Practice_AppLogic_State_SplashScreen --> GameJam2024Practice_AppLogic_State_MainMenu : FadeOutFinished
GameJam2024Practice_AppLogic_State_InGame : OnEnter → ShowGame
GameJam2024Practice_AppLogic_State_InGame : OnExit → HideGame
GameJam2024Practice_AppLogic_State_InGame : OnGameOver → RemoveExistingGame
GameJam2024Practice_AppLogic_State_LeavingMenu : OnEnter → FadeToBlack
GameJam2024Practice_AppLogic_State_MainMenu : OnEnter → SetupGameScene, ShowMainMenu
GameJam2024Practice_AppLogic_State_MainMenu : OnQuitGame → ExitGame
GameJam2024Practice_AppLogic_State_SplashScreen : OnEnter → ShowSplashScreen
GameJam2024Practice_AppLogic_State_SplashScreen : OnSplashScreenSkipped() → HideSplashScreen
[*] --> GameJam2024Practice_AppLogic_State_SplashScreen
@enduml

View File

@@ -0,0 +1,37 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace GameJamDungeon
{
public partial class AppLogic
{
public partial record State
{
[Meta]
public partial record InGame : State, IGet<Input.GameOver>
{
public InGame()
{
this.OnEnter(() =>
{
Get<IAppRepo>().OnEnterGame();
Output(new Output.ShowGame());
});
this.OnExit(() => Output(new Output.HideGame()));
OnAttach(() => Get<IAppRepo>().GameExited += OnGameExited);
OnDetach(() => Get<IAppRepo>().GameExited -= OnGameExited);
}
public Transition On(in Input.GameOver input)
{
Output(new Output.RemoveExistingGame());
return To<MainMenu>();
}
public void OnGameExited() => Input(new Input.GameOver());
}
}
}
}

View File

@@ -0,0 +1,22 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace GameJamDungeon
{
public partial class AppLogic
{
public partial record State
{
[Meta]
public partial record LeavingMenu : State, IGet<Input.FadeOutFinished>
{
public LeavingMenu()
{
this.OnEnter(() => Output(new Output.FadeToBlack()));
}
public Transition On(in Input.FadeOutFinished input) => To<InGame>();
}
}
}
}

View File

@@ -0,0 +1,35 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace GameJamDungeon
{
public partial class AppLogic
{
public partial record State
{
[Meta]
public partial record MainMenu : State, IGet<Input.NewGame>, IGet<Input.QuitGame>
{
public MainMenu()
{
this.OnEnter(() =>
{
Output(new Output.SetupGameScene());
Get<IAppRepo>().OnMainMenuEntered();
Output(new Output.ShowMainMenu());
});
}
public Transition On(in Input.NewGame input) => To<LeavingMenu>();
public Transition On(in Input.QuitGame input)
{
Output(new Output.ExitGame());
return ToSelf();
}
}
}
}
}

View File

@@ -0,0 +1,33 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace GameJamDungeon
{
public partial class AppLogic
{
public partial record State
{
[Meta]
public partial record SplashScreen : State, IGet<Input.FadeOutFinished>
{
public SplashScreen()
{
this.OnEnter(() => Output(new Output.ShowSplashScreen()));
OnAttach(
() => Get<IAppRepo>().SplashScreenSkipped += OnSplashScreenSkipped
);
OnDetach(
() => Get<IAppRepo>().SplashScreenSkipped -= OnSplashScreenSkipped
);
}
public Transition On(in Input.FadeOutFinished input) => To<MainMenu>();
public void OnSplashScreenSkipped() =>
Output(new Output.HideSplashScreen());
}
}
}
}