Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
Separated Scene class to multiple classes to avoid mess in one file
Browse files Browse the repository at this point in the history
  • Loading branch information
craftersmine committed Apr 19, 2019
1 parent ce36910 commit 2ede682
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 98 deletions.
45 changes: 45 additions & 0 deletions craftersmine.EtherEngine.Core/Scene.Audio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using craftersmine.EtherEngine.Content;

namespace craftersmine.EtherEngine.Core
{
public partial class Scene
{
internal Dictionary<string, AudioChannel> AudioChannels = new Dictionary<string, AudioChannel>();

public bool CreateAudioChannel(string id, AudioClip audioClip)
{
if (!AudioChannels.ContainsKey(id))
{
AudioChannels.Add(id, new AudioChannel(audioClip));
return true;
}
else return false;
}

public void RemoveAudioChannel(string id)
{
if (AudioChannels.ContainsKey(id))
{
AudioChannels[id].Stop();
AudioChannels.Remove(id);
}
}

public AudioChannel GetAudioChannel(string id)
{
if (AudioChannels.ContainsKey(id))
return AudioChannels[id];
else return null;
}

public void PlayAudioOnce(AudioClip audio)
{
new AudioChannel(audio).Play();
}
}
}
47 changes: 47 additions & 0 deletions craftersmine.EtherEngine.Core/Scene.GameObjects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace craftersmine.EtherEngine.Core
{
public partial class Scene
{
internal List<GameObject> GameObjects = new List<GameObject>();

/// <summary>
/// Adds <see cref="GameObject"/> to scene
/// </summary>
/// <param name="gameObject">Addable object</param>
public void AddGameObject(GameObject gameObject)
{
gameObject.InternalCreate();
GameObjects.Add(gameObject);
}

/// <summary>
/// Adds range of <see cref="GameObject"/> to scene
/// </summary>
/// <param name="gameObjects">Addable objects collection</param>
public void AddGameObjects(IEnumerable<GameObject> gameObjects)
{
foreach (var obj in gameObjects)
{
AddGameObject(obj);
}
}

/// <summary>
/// Removes <see cref="GameObject"/> from scene
/// </summary>
/// <param name="gameObject">Removable object</param>
public void RemoveGameObject(GameObject gameObject)
{
if (GameObjects.Contains(gameObject))
{
GameObjects.Remove(gameObject);
}
}
}
}
23 changes: 23 additions & 0 deletions craftersmine.EtherEngine.Core/Scene.UIWidgets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace craftersmine.EtherEngine.Core
{
public partial class Scene
{
internal List<UIWidget> UIWidgets = new List<UIWidget>();

public void AddUIWidget(UIWidget widget)
{
UIWidgets.Add(widget);
}

public void RemoveUIWidget(UIWidget widget)
{
UIWidgets.Remove(widget);
}
}
}
33 changes: 33 additions & 0 deletions craftersmine.EtherEngine.Core/Scene.Virtuals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace craftersmine.EtherEngine.Core
{
public partial class Scene
{
/// <summary>
/// Calls when scene is being updated
/// </summary>
public virtual void OnUpdate(float deltaTime)
{

}

/// <summary>
/// Calls when scene is being created
/// </summary>
public virtual void OnStart()
{

}

/// <summary>
/// Calls when scene is being unloaded
/// </summary>
public virtual void OnUnload()
{ }
}
}
99 changes: 1 addition & 98 deletions craftersmine.EtherEngine.Core/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ namespace craftersmine.EtherEngine.Core
/// <summary>
/// Represents game scene. This class cannot be inherited
/// </summary>
public class Scene
public partial class Scene
{
private Color _bgColor;

internal List<GameObject> GameObjects = new List<GameObject>();
internal List<UIWidget> UIWidgets = new List<UIWidget>();

internal Dictionary<string, AudioChannel> AudioChannels = new Dictionary<string, AudioChannel>();

/// <summary>
/// Gets or sets <see cref="Scene"/> background color
/// </summary>
Expand All @@ -40,98 +35,6 @@ public Scene()

}

/// <summary>
/// Calls when scene is being updated
/// </summary>
public virtual void OnUpdate(float deltaTime)
{

}

/// <summary>
/// Calls when scene is being created
/// </summary>
public virtual void OnStart()
{

}

/// <summary>
/// Calls when scene is being unloaded
/// </summary>
public virtual void OnUnload()
{ }

/// <summary>
/// Adds <see cref="GameObject"/> to scene
/// </summary>
/// <param name="gameObject">Addable object</param>
public void AddGameObject(GameObject gameObject)
{
gameObject.InternalCreate();
GameObjects.Add(gameObject);
}

/// <summary>
/// Adds range of <see cref="GameObject"/> to scene
/// </summary>
/// <param name="gameObjects">Addable objects collection</param>
public void AddGameObjects(IEnumerable<GameObject> gameObjects)
{
foreach (var obj in gameObjects)
{
AddGameObject(obj);
}
}

/// <summary>
/// Removes <see cref="GameObject"/> from scene
/// </summary>
/// <param name="gameObject">Removable object</param>
public void RemoveGameObject(GameObject gameObject)
{
if (GameObjects.Contains(gameObject))
{
GameObjects.Remove(gameObject);
}
}

public bool CreateAudioChannel(string id, AudioClip audioClip)
{
if (!AudioChannels.ContainsKey(id))
{
AudioChannels.Add(id, new AudioChannel(audioClip));
return true;
}
else return false;
}

public void RemoveAudioChannel(string id)
{
if (AudioChannels.ContainsKey(id))
{
AudioChannels[id].Stop();
AudioChannels.Remove(id);
}
}

public AudioChannel GetAudioChannel(string id)
{
if (AudioChannels.ContainsKey(id))
return AudioChannels[id];
else return null;
}

public void AddUIWidget(UIWidget widget)
{
UIWidgets.Add(widget);
}

public void RemoveUIWidget(UIWidget widget)
{
UIWidgets.Remove(widget);
}

internal void InternalCreate()
{
SceneCamera = new Camera(Game.GameWnd.WindowSize.Width, Game.GameWnd.WindowSize.Height);
Expand Down

0 comments on commit 2ede682

Please sign in to comment.