Skip to content

Commit

Permalink
Merge pull request #3 from mackysoft/change/history
Browse files Browse the repository at this point in the history
Apply generics to history class for development of new features
  • Loading branch information
mackysoft committed Oct 26, 2023
2 parents fc9df67 + d0d3042 commit 1790aa0
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 82 deletions.
56 changes: 56 additions & 0 deletions Assets/MackySoft/MackySoft.Navigathena/Runtime/History.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MackySoft.Navigathena
{

public class History<T> : IReadOnlyCollection<T>
{

const int kDefauktCapacity = 8;

readonly Stack<T> m_Stack;

public int Count => m_Stack.Count;

public History ()
{
m_Stack = new Stack<T>(kDefauktCapacity);
}

public History (IEnumerable<T> entries)
{
if (entries == null)
{
throw new ArgumentNullException(nameof(entries));
}
m_Stack = new Stack<T>(entries.Where(x => x != null));
}

public void Push (T entry)
{
if (entry == null)
{
throw new ArgumentNullException(nameof(entry));
}
m_Stack.Push(entry);
}

public T Pop () => m_Stack.Pop();

public T Peek () => m_Stack.Peek();

public bool TryPop (out T result) => m_Stack.TryPop(out result);

public bool TryPeek (out T result) => m_Stack.TryPeek(out result);

public void Clear () => m_Stack.Clear();

public IEnumerator<T> GetEnumerator () => m_Stack.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator () => m_Stack.GetEnumerator();

}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using MackySoft.Navigathena.Transitions;

namespace MackySoft.Navigathena.SceneManagement
{

public interface IReadOnlySceneHistoryEntry
{
ISceneIdentifier Scene { get; }
ITransitionDirector TransitionDirector { get; }
ISceneDataReader DataReader { get; }
}

public sealed class SceneHistoryEntry : IReadOnlySceneHistoryEntry
{
public ISceneIdentifier Scene { get; }
public ITransitionDirector TransitionDirector { get; }
public SceneDataStore DataStore { get; }

ISceneDataReader IReadOnlySceneHistoryEntry.DataReader => DataStore.Reader;

public SceneHistoryEntry (ISceneIdentifier scene, ITransitionDirector transitionDirectorData, SceneDataStore sceneDataStore)
{
Scene = scene ?? throw new ArgumentNullException(nameof(scene));
TransitionDirector = transitionDirectorData;
DataStore = sceneDataStore ?? throw new ArgumentNullException(nameof(sceneDataStore));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class StandardSceneNavigator : ISceneNavigator, IUnsafeSceneNaviga
/// History of all scenes, including the current scene.
/// Since interrupt processing may occur on ISceneEntryPoint events, the history must be updated prior to calling the event.
/// </summary>
readonly SceneHistory m_History = new();
readonly History<SceneHistoryEntry> m_History = new();

/// <summary>
/// A counter to prevent <see cref="OnSceneLoaded(Scene, LoadSceneMode)"/> from causing a double initialization process.
Expand Down

0 comments on commit 1790aa0

Please sign in to comment.