Advertisement
xxeell

Mod_Manager

Oct 17th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ElementsCore
  5. {
  6.     public class ModuleManager<T>
  7.     {
  8.         private Dictionary<T, BaseModule<T>> modules;
  9.         private BaseModule<T> current_mod;
  10.  
  11.         public ModuleManager()
  12.         {
  13.             modules = new Dictionary<T, BaseModule<T>>();
  14.             current_mod = null;
  15.         }
  16.  
  17.         public void AddModule(T key, BaseModule<T> mod)
  18.         {
  19.             modules.Add(key, mod);            
  20.         }
  21.  
  22.         public void SetActiveModule(T key)
  23.         {
  24.             if (current_mod != null) current_mod.Close();
  25.  
  26.             if (!modules.Keys.Contains(key)) return;
  27.  
  28.             current_mod = modules[key];
  29.  
  30.             if (current_mod != null)
  31.             {
  32.                 current_mod.SetManager(this);
  33.                 current_mod.Init();
  34.             }
  35.         }
  36.  
  37.         public bool KeyDown(KeyCommand command)
  38.         {
  39.             if (current_mod == null) return false;
  40.             return current_mod.KeyDown(command);
  41.         }
  42.  
  43.         public void Close()
  44.         {
  45.             if (current_mod != null) current_mod.Close();
  46.             modules.Clear();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement