-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mackysoft/change/history
Apply generics to history class for development of new features
- Loading branch information
Showing
6 changed files
with
97 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
} |
File renamed without changes.
81 changes: 0 additions & 81 deletions
81
Assets/MackySoft/MackySoft.Navigathena/Runtime/SceneManagement/SceneHistory.cs
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
Assets/MackySoft/MackySoft.Navigathena/Runtime/SceneManagement/SceneHistoryEntry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/MackySoft/MackySoft.Navigathena/Runtime/SceneManagement/SceneHistoryEntry.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters