Skip to content

Commit

Permalink
Add resources from YExt.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaneDubya committed Jun 6, 2016
1 parent 41bc617 commit 8d91290
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ public void Dispose()

}

public Effect LoadEffect(string contentName)
public Effect LoadEffectContent(string contentName)
{
return m_Game.Content.Load<Effect>(contentName);
}

public Texture2D LoadTextureContent(string contentName)
{
return m_Game.Content.Load<Texture2D>(contentName);
}

public void Begin(Color? clear = null) {
if (clear == null)
return;
Expand Down
14 changes: 14 additions & 0 deletions Source/Libraries/YpsilonFramework/Core/Localization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Text;

namespace Ypsilon.Core {
public static class Strings {
public static readonly char Delim = '|';
public static string Name = "PlayerName";

public static string Localize(string s) {
StringBuilder sb = new StringBuilder(s);
sb.Replace("%name%", Name);
return sb.ToString();
}
}
}
53 changes: 53 additions & 0 deletions Source/Libraries/YpsilonFramework/Core/ModeManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Ypsilon.Core.Input;
using Ypsilon.Core.Patterns.MVC;

namespace Ypsilon.Core {
public class ModeManager {
private AModel m_Model;
private AModel m_QueuedModel;

public AModel ActiveModel {
get { return m_Model; }
set {
if (m_Model != null) {
m_Model.Dispose();
m_Model = null;
}
m_Model = value;
m_Model?.Initialize();
}
}

public AModel QueuedModel {
get { return m_QueuedModel; }
set {
if (m_QueuedModel != null) {
m_QueuedModel.Dispose();
m_QueuedModel = null;
}
m_QueuedModel = value;
m_QueuedModel?.Initialize();
}
}

public void ActivateQueuedModel() {
if (m_QueuedModel != null) {
ActiveModel = QueuedModel;
m_QueuedModel = null;
}
}

public void Draw(float frameSeconds) {
m_Model.GetView().Draw(frameSeconds);
}

public void Update(float totalSeconds, float frameSeconds) {
if (m_QueuedModel != null) {
ActivateQueuedModel();
}
InputManager input = ServiceRegistry.GetService<InputManager>();
m_Model.Update(totalSeconds, frameSeconds);
m_Model.GetController().Update(frameSeconds, input);
}
}
}
49 changes: 49 additions & 0 deletions Source/Libraries/YpsilonFramework/Core/ServiceRegistry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;

namespace Ypsilon.Core {
public static class ServiceRegistry {
private static readonly Dictionary<Type, object> m_Services = new Dictionary<Type, object>();

public static T GetService<T>() {
Type type = typeof(T);
if (m_Services.ContainsKey(type)) {
return (T)m_Services[type];
}
else {
// Tracer.Critical(string.Format("Attempted to get service service of type {0}, but no service of this type is registered.", type.ToString()));
return default(T);
}
}

public static T Register<T>(T service) {
Type type = typeof(T);
if (m_Services.ContainsKey(type)) {
// Tracer.Critical(string.Format("Attempted to register service of type {0} twice.", type.ToString()));
m_Services.Remove(type);
}
m_Services.Add(type, service);
return service;
}

public static bool ServiceExists<T>() {
Type type = typeof(T);
if (m_Services.ContainsKey(type)) {
return true;
}
else {
return false;
}
}

public static void Unregister<T>() {
Type type = typeof(T);
if (m_Services.ContainsKey(type)) {
m_Services.Remove(type);
}
else {
// Tracer.Critical(string.Format("Attempted to unregister service of type {0}, but no service of this type (or type and equality) is registered.", type.ToString()));
}
}
}
}
3 changes: 3 additions & 0 deletions Source/Libraries/YpsilonFramework/YpsilonFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
<Compile Include="Core\IO\BinaryFileReader.cs" />
<Compile Include="Core\IO\BinaryFileWriter.cs" />
<Compile Include="Core\IO\Compression.cs" />
<Compile Include="Core\Localization.cs" />
<Compile Include="Core\ModeManager.cs" />
<Compile Include="Core\Patterns\ECS\ComponentCollection.cs" />
<Compile Include="Core\ServiceRegistry.cs" />
<Compile Include="Extensions\PointX.cs" />
<Compile Include="Extensions\StringX.cs" />
<Compile Include="GraphicsUtility.cs" />
Expand Down

0 comments on commit 8d91290

Please sign in to comment.