Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ElementsCore
- {
- public class ModuleManager<T>
- {
- private Dictionary<T, BaseModule<T>> modules;
- private BaseModule<T> current_mod;
- public ModuleManager()
- {
- modules = new Dictionary<T, BaseModule<T>>();
- current_mod = null;
- }
- public void AddModule(T key, BaseModule<T> mod)
- {
- modules.Add(key, mod);
- }
- public void SetActiveModule(T key)
- {
- if (current_mod != null) current_mod.Close();
- if (!modules.Keys.Contains(key)) return;
- current_mod = modules[key];
- if (current_mod != null)
- {
- current_mod.SetManager(this);
- current_mod.Init();
- }
- }
- public bool KeyDown(KeyCommand command)
- {
- if (current_mod == null) return false;
- return current_mod.KeyDown(command);
- }
- public void Close()
- {
- if (current_mod != null) current_mod.Close();
- modules.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement