DataStore.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using fun.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. using Environment = fun.Core.Environment;
  6. namespace fun.IO.Data
  7. {
  8. internal sealed class DataStore : IEnvironmentDataStore
  9. {
  10. private List<Assembly> assemblys;
  11. private List<Environment> environments;
  12. private Environment currEnvironment;
  13. private Entity currEntity;
  14. private Element currElement;
  15. public Environment[] Envionments { get { return environments.ToArray(); } }
  16. public Assembly[] Assemblys { get { return assemblys.ToArray(); } }
  17. public Element Element { get { return currElement; } }
  18. public DataStore()
  19. {
  20. assemblys = new List<Assembly>();
  21. environments = new List<Environment>();
  22. }
  23. public void PushEnvironment()
  24. {
  25. currEnvironment = new Environment();
  26. }
  27. public void AddPushedEnvirionment()
  28. {
  29. environments.Add(currEnvironment);
  30. }
  31. public void DepushEnvironment()
  32. {
  33. currEnvironment = null;
  34. }
  35. public void PushEntity(string name)
  36. {
  37. currEntity = new Entity(name, currEnvironment);
  38. }
  39. public void DepushEntity()
  40. {
  41. currEntity = null;
  42. }
  43. public void AddPushedEntity()
  44. {
  45. currEnvironment.AddEntity(currEntity);
  46. }
  47. public void AddEntity(string name)
  48. {
  49. var entity = new Entity(name, currEnvironment);
  50. currEnvironment.AddEntity(entity);
  51. }
  52. public void PushElement(Type type)
  53. {
  54. currEntity.AddElement(type);
  55. currElement = currEntity.GetElement(type);
  56. }
  57. public void DepushElement()
  58. {
  59. currElement = null;
  60. }
  61. public void AddLibary(Assembly assembly)
  62. {
  63. assemblys.Add(assembly);
  64. }
  65. }
  66. }