Overhaul game state logic to support gameplay loop
This commit is contained in:
28
Zennysoft.Game.Ma/src/map/IMap.cs
Normal file
28
Zennysoft.Game.Ma/src/map/IMap.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface IMap : INode3D, IProvide<ISaveChunk<MapData>>
|
||||
{
|
||||
void LoadMap();
|
||||
|
||||
void LoadFloor();
|
||||
|
||||
List<string> FloorScenes { get; }
|
||||
|
||||
IDungeonFloor CurrentFloor { get; }
|
||||
|
||||
void SpawnNextFloor();
|
||||
|
||||
Transform3D GetPlayerSpawnPosition();
|
||||
|
||||
IDungeonRoom GetPlayersCurrentRoom();
|
||||
|
||||
void InitializeMapData();
|
||||
|
||||
public int CurrentFloorNumber { get; }
|
||||
}
|
||||
1
Zennysoft.Game.Ma/src/map/IMap.cs.uid
Normal file
1
Zennysoft.Game.Ma/src/map/IMap.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b2q36geko8vms
|
||||
@@ -1,5 +1,4 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Godot;
|
||||
@@ -9,24 +8,6 @@ using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface IMap : INode3D, IProvide<ISaveChunk<MapData>>
|
||||
{
|
||||
void LoadMap();
|
||||
|
||||
List<string> FloorScenes { get; }
|
||||
|
||||
IDungeonFloor CurrentFloor { get; }
|
||||
|
||||
void SpawnNextFloor();
|
||||
|
||||
Transform3D GetPlayerSpawnPosition();
|
||||
|
||||
IDungeonRoom GetPlayersCurrentRoom();
|
||||
|
||||
public int CurrentFloorNumber { get; }
|
||||
}
|
||||
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Map : Node3D, IMap
|
||||
{
|
||||
@@ -50,7 +31,7 @@ public partial class Map : Node3D, IMap
|
||||
[Export]
|
||||
private Godot.Collections.Array<PackedScene> _floors { get; set; } = default!;
|
||||
|
||||
public List<string> FloorScenes { get; private set; }
|
||||
public List<string> FloorScenes { get; private set; } = [];
|
||||
|
||||
public IDungeonFloor CurrentFloor { get; private set; }
|
||||
|
||||
@@ -58,66 +39,77 @@ public partial class Map : Node3D, IMap
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
FloorScenes = [];
|
||||
MapChunk = new SaveChunk<MapData>(
|
||||
onSave: (chunk) => new MapData()
|
||||
{
|
||||
FloorScenes = FloorScenes,
|
||||
},
|
||||
onLoad: (chunk, data) =>
|
||||
{
|
||||
FloorScenes = data.FloorScenes;
|
||||
}
|
||||
);
|
||||
|
||||
MapChunk = new SaveChunk<MapData>(
|
||||
onSave: (chunk) => new MapData()
|
||||
{
|
||||
FloorScenes = FloorScenes,
|
||||
},
|
||||
onLoad: (chunk, data) =>
|
||||
{
|
||||
FloorScenes = data.FloorScenes;
|
||||
}
|
||||
);
|
||||
GameChunk.AddChunk(MapChunk);
|
||||
|
||||
GameChunk.AddChunk(MapChunk);
|
||||
this.Provide();
|
||||
|
||||
this.Provide();
|
||||
InitializeMapData();
|
||||
}
|
||||
|
||||
public void InitializeMapData()
|
||||
{
|
||||
ClearMap();
|
||||
FloorScenes = [];
|
||||
foreach (var floor in _floors)
|
||||
FloorScenes.Add(floor.ResourcePath);
|
||||
CurrentFloorNumber = 0;
|
||||
}
|
||||
|
||||
public void LoadMap()
|
||||
{
|
||||
foreach (var floor in _floors)
|
||||
FloorScenes.Add(floor.ResourcePath);
|
||||
LoadFloor();
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
CurrentFloor.FloorIsLoaded = true;
|
||||
}
|
||||
|
||||
LoadFloor();
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
CurrentFloor.FloorIsLoaded = true;
|
||||
Game.NextFloorLoaded();
|
||||
private void ClearMap()
|
||||
{
|
||||
CurrentFloor?.CallDeferred(MethodName.QueueFree, []);
|
||||
}
|
||||
|
||||
public void SpawnNextFloor()
|
||||
{
|
||||
var oldFloor = CurrentFloor;
|
||||
oldFloor.CallDeferred(MethodName.QueueFree, []);
|
||||
LoadFloor();
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
CurrentFloor.FloorIsLoaded = true;
|
||||
Game.NextFloorLoaded();
|
||||
CurrentFloorNumber += 1;
|
||||
ClearMap();
|
||||
LoadFloor();
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
CurrentFloor.FloorIsLoaded = true;
|
||||
CurrentFloorNumber += 1;
|
||||
}
|
||||
|
||||
public IDungeonRoom GetPlayersCurrentRoom()
|
||||
{
|
||||
var rooms = CurrentFloor.Rooms;
|
||||
var playersRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom);
|
||||
return playersRoom;
|
||||
var rooms = CurrentFloor.Rooms;
|
||||
var playersRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom);
|
||||
return playersRoom;
|
||||
}
|
||||
|
||||
public Transform3D GetPlayerSpawnPosition() => CurrentFloor.GetPlayerSpawnPoint();
|
||||
|
||||
private void LoadFloor()
|
||||
public void LoadFloor()
|
||||
{
|
||||
var currentFloorScene = FloorScenes.First();
|
||||
var instantiator = new Instantiator(GetTree());
|
||||
var loadedScene = instantiator.LoadAndInstantiate<Node3D>(currentFloorScene);
|
||||
AddChild(loadedScene);
|
||||
CurrentFloor = (IDungeonFloor)loadedScene;
|
||||
FloorScenes.Remove(currentFloorScene);
|
||||
ClearMap();
|
||||
var currentFloorScene = FloorScenes.First();
|
||||
var instantiator = new Instantiator(GetTree());
|
||||
var loadedScene = instantiator.LoadAndInstantiate<Node3D>(currentFloorScene);
|
||||
AddChild(loadedScene);
|
||||
CurrentFloor = (IDungeonFloor)loadedScene;
|
||||
FloorScenes.Remove(currentFloorScene);
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://by67pn7fdsg1m"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://by67pn7fdsg1m"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://14e8mu48ed4" path="res://src/map/Map.cs" id="1_bw70o"]
|
||||
[ext_resource type="PackedScene" uid="uid://dl6h1djc27ddl" path="res://src/map/dungeon/floors/Floor00.tscn" id="2_0m8h8"]
|
||||
[ext_resource type="PackedScene" uid="uid://bc1sp6xwe0j65" path="res://src/map/dungeon/floors/Floor01.tscn" id="2_merfv"]
|
||||
[ext_resource type="PackedScene" uid="uid://g28xmp6cn16h" path="res://src/map/dungeon/floors/Floor10.tscn" id="3_caf7v"]
|
||||
[ext_resource type="PackedScene" uid="uid://w2peiubnalof" path="res://src/map/dungeon/floors/Floor20.tscn" id="3_y74f3"]
|
||||
[ext_resource type="PackedScene" uid="uid://dmiqwmivkjgmq" path="res://src/map/dungeon/floors/Floor02.tscn" id="4_8y0oy"]
|
||||
[ext_resource type="PackedScene" uid="uid://dl1scvkp8r5sw" path="res://src/map/dungeon/floors/Floor03.tscn" id="5_uag72"]
|
||||
[ext_resource type="PackedScene" uid="uid://cikq7vuorlpbl" path="res://src/map/dungeon/floors/Floor04.tscn" id="6_55rmo"]
|
||||
[ext_resource type="PackedScene" uid="uid://t7cac7801bnk" path="res://src/map/dungeon/floors/Floor05.tscn" id="7_f6kwn"]
|
||||
[ext_resource type="PackedScene" uid="uid://da107mywg18x1" path="res://src/map/dungeon/floors/Floor06.tscn" id="8_ne2vg"]
|
||||
[ext_resource type="PackedScene" uid="uid://cgtqjgh1f5fqi" path="res://src/map/dungeon/floors/Floor07.tscn" id="9_abpbr"]
|
||||
[ext_resource type="PackedScene" uid="uid://dg20ovvj2m2lp" path="res://src/map/dungeon/floors/Floor08.tscn" id="10_caf7v"]
|
||||
[ext_resource type="PackedScene" uid="uid://b5jk743ng6fqg" path="res://src/map/dungeon/floors/Floor09.tscn" id="11_y74f3"]
|
||||
[ext_resource type="PackedScene" uid="uid://dl6h1djc27ddl" path="res://src/map/dungeon/floors/Floor00.tscn" id="3_s7lwc"]
|
||||
[ext_resource type="PackedScene" uid="uid://dmiqwmivkjgmq" path="res://src/map/dungeon/floors/Floor02.tscn" id="4_0qcd2"]
|
||||
[ext_resource type="PackedScene" uid="uid://bc1sp6xwe0j65" path="res://src/map/dungeon/floors/Floor01.tscn" id="4_1ny7u"]
|
||||
|
||||
[node name="Map" type="Node3D"]
|
||||
script = ExtResource("1_bw70o")
|
||||
_floors = Array[PackedScene]([ExtResource("2_0m8h8"), ExtResource("2_merfv"), ExtResource("4_8y0oy"), ExtResource("5_uag72"), ExtResource("6_55rmo"), ExtResource("7_f6kwn"), ExtResource("8_ne2vg"), ExtResource("9_abpbr"), ExtResource("10_caf7v"), ExtResource("11_y74f3"), ExtResource("3_caf7v"), ExtResource("3_y74f3")])
|
||||
_floors = Array[PackedScene]([ExtResource("3_s7lwc"), ExtResource("4_1ny7u"), ExtResource("4_0qcd2")])
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -63,5 +64,9 @@ public partial class BossRoomA : Node3D, IBossRoom
|
||||
public void ExitReached()
|
||||
=> Game.FloorExitReached();
|
||||
|
||||
private void Exit_AreaEntered(Area3D area) => ExitReached();
|
||||
private void Exit_AreaEntered(Area3D area)
|
||||
{
|
||||
if (area.GetOwner() is IPlayer)
|
||||
ExitReached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -21,5 +22,9 @@ public partial class ExitRoom : DungeonRoom
|
||||
public void ExitReached()
|
||||
=> Game.FloorExitReached();
|
||||
|
||||
private void Exit_AreaEntered(Area3D area) => ExitReached();
|
||||
private void Exit_AreaEntered(Area3D area)
|
||||
{
|
||||
if (area.GetOwner() is IPlayer)
|
||||
ExitReached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System.Collections.Immutable;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -22,12 +23,16 @@ public partial class Floor0 : Node3D, IDungeonFloor
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Show();
|
||||
Exit.AreaEntered += Exit_AreaEntered;
|
||||
FloorIsLoaded = true;
|
||||
Show();
|
||||
Exit.AreaEntered += Exit_AreaEntered;
|
||||
FloorIsLoaded = true;
|
||||
}
|
||||
|
||||
private void Exit_AreaEntered(Area3D area) => ExitReached();
|
||||
private void Exit_AreaEntered(Area3D area)
|
||||
{
|
||||
if (area.GetOwner() is IPlayer)
|
||||
ExitReached();
|
||||
}
|
||||
|
||||
public void ExitReached() => Game.FloorExitReached();
|
||||
public void InitializeDungeon() { return; }
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user