building.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. class House : BuildingBase
  2. {
  3. void House()
  4. {
  5. }
  6. }
  7. class BuildingBase : Building
  8. {
  9. static ref map<typename, ref TInputActionMap> m_BuildingTypeActionsMap = new map<typename, ref TInputActionMap>;
  10. TInputActionMap m_InputActionMap;
  11. bool m_ActionsInitialize;
  12. void BuildingBase()
  13. {
  14. m_ActionsInitialize = false;
  15. }
  16. void InitializeActions()
  17. {
  18. m_InputActionMap = m_BuildingTypeActionsMap.Get( this.Type() );
  19. if (!m_InputActionMap)
  20. {
  21. TInputActionMap iam = new TInputActionMap;
  22. m_InputActionMap = iam;
  23. SetActions();
  24. m_BuildingTypeActionsMap.Insert(this.Type(), m_InputActionMap);
  25. }
  26. }
  27. override void GetActions(typename action_input_type, out array<ActionBase_Basic> actions)
  28. {
  29. if (!m_ActionsInitialize)
  30. {
  31. m_ActionsInitialize = true;
  32. InitializeActions();
  33. }
  34. actions = m_InputActionMap.Get(action_input_type);
  35. }
  36. void SetActions()
  37. {
  38. //AddAction();
  39. }
  40. void AddAction(typename actionName)
  41. {
  42. ActionBase action = ActionManagerBase.GetAction(actionName);
  43. if (!action)
  44. {
  45. Debug.LogError("Action " + actionName + " dosn't exist!");
  46. return;
  47. }
  48. typename ai = action.GetInputType();
  49. if (!ai)
  50. {
  51. m_ActionsInitialize = false;
  52. return;
  53. }
  54. ref array<ActionBase_Basic> action_array = m_InputActionMap.Get( ai );
  55. if (!action_array)
  56. {
  57. action_array = new array<ActionBase_Basic>;
  58. m_InputActionMap.Insert(ai, action_array);
  59. }
  60. if ( LogManager.IsActionLogEnable() )
  61. {
  62. Debug.ActionLog(action.ToString() + " -> " + ai, this.ToString() , "n/a", "Add action" );
  63. }
  64. action_array.Insert(action);
  65. }
  66. void RemoveAction(typename actionName)
  67. {
  68. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  69. ActionBase action = player.GetActionManager().GetAction(actionName);
  70. typename ai = action.GetInputType();
  71. ref array<ActionBase_Basic> action_array = m_InputActionMap.Get( ai );
  72. if (action_array)
  73. {
  74. action_array.RemoveItem(action);
  75. }
  76. }
  77. };
  78. typedef House BuildingSuper;