estimate ui

This commit is contained in:
2022-12-14 21:57:03 +01:00
parent 5e2af5468c
commit 12b0acbcbe
7 changed files with 368 additions and 211 deletions

View File

@@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Linq;
using EscapeRoomEngine.Engine.Runtime.Measurements;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.UI;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;
@@ -27,9 +28,10 @@ namespace EscapeRoomEngine.Engine.Runtime
public int NumberOfRooms => _rooms.Count;
public IOption<Room> CurrentRoom => NumberOfRooms > 0 ? Some<Room>.Of(_rooms[^1]) : None<Room>.New();
public float EstimatedTimeRemaining { get; private set; }
private readonly List<Room> _rooms = new();
private List<PuzzleModuleDescription> _puzzles;
private List<PuzzleModuleDescription> _availablePuzzles, _plannedPuzzles;
private GameObject _playSpaceOrigin;
private void Awake()
@@ -38,7 +40,8 @@ namespace EscapeRoomEngine.Engine.Runtime
Measure.Clear();
_puzzles = new List<PuzzleModuleDescription>(theme.puzzleTypes);
_availablePuzzles = new List<PuzzleModuleDescription>(theme.puzzleTypes);
_plannedPuzzles = new List<PuzzleModuleDescription>(_availablePuzzles);
}
private void Start()
@@ -70,6 +73,7 @@ namespace EscapeRoomEngine.Engine.Runtime
Instantiate(theme.environment, room.roomObject.transform, false);
}
GameControl.Instance.TimeInRoom = 0;
UpdateUI();
}
@@ -79,9 +83,8 @@ namespace EscapeRoomEngine.Engine.Runtime
var tries = 0;
Space space;
Passage exit = null;
var puzzle = PlanPuzzles();
var puzzle = _puzzles.PopRandomElement();
do
{
tries++;
@@ -91,7 +94,7 @@ namespace EscapeRoomEngine.Engine.Runtime
space = new Space(room, entrance);
// add exit
if (_puzzles.Count > 0)
if (_plannedPuzzles.Count > 0)
{
var exitDoor = new DoorModule(space, theme.exitDoorTypes.RandomElement());
if (!space.AddModuleWithRequirements(exitDoor))
@@ -116,6 +119,19 @@ namespace EscapeRoomEngine.Engine.Runtime
room.AddSpace(space, exit);
}
/// <summary>
/// Updates the list of puzzles planned for this run and returns the puzzle to put in the next room.
/// </summary>
private PuzzleModuleDescription PlanPuzzles()
{
var nextPuzzle = _plannedPuzzles.PopRandomElement();
EstimatedTimeRemaining = Measure.AverageTime(_plannedPuzzles);
return nextPuzzle;
}
#endregion
public void HidePreviousRoom(bool destroy = true)