public IComponent Create(LiveSplitState state) { // TODO: in LiveSplit 1.4, components will be IDisposable // this assumes the passed state is always the same one, until then return(_instance ?? (_instance = new SourceSplitComponent(state))); // return new SourceSplitComponent(state); }
public IComponent Create(LiveSplitState state) { // hack to prevent double loading string caller = new StackFrame(1).GetMethod().Name; bool createAsLayoutComponent = (caller == "LoadLayoutComponent" || caller == "AddComponent"); // if component is already loaded somewhere else if (_instance != null && !_instance.Disposed) { MessageBox.Show( "SourceSplit is already loaded in the " + (_instance.IsLayoutComponent ? "Layout Editor" : "Splits Editor") + "!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw new Exception("Component already loaded."); } return(_instance = new SourceSplitComponent(state, createAsLayoutComponent)); }
public IComponent Create(LiveSplitState state) { // hack to prevent double loading string caller = new StackFrame(1).GetMethod().Name; bool createAsLayoutComponent = (caller == "LoadLayoutComponent" || caller == "AddComponent"); // if component is already loaded somewhere else if (_instance != null && !_instance.Disposed) { MessageBox.Show( "SourceSplit is already loaded in the " + (_instance.IsLayoutComponent ? "Layout Editor" : "Splits Editor") + "!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw new Exception("Component already loaded."); } return (_instance = new SourceSplitComponent(state, createAsLayoutComponent)); }
public IComponent Create(LiveSplitState state) { // hack to prevent double loading string caller = new StackFrame(1).GetMethod().Name; bool createAsLayoutComponent = (caller == "LoadLayoutComponent" || caller == "AddComponent"); // if component is already loaded somewhere else // layout editor takes precedent because its just better & i can't figure out how to unload // components from layout editor >:( if (_instance != null && !_instance.Disposed) { void unloadSplitsInstance(bool fromLayout) { string msg = (fromLayout) ? "Deactivated SourceSplit from Splits Editor!" : "Cannot activate SourceSplit when it is already loaded in the Layout Editor!"; string source = fromLayout ? "Layout Editor" : "Splits Editor"; MessageBox.Show(msg, $"SourceSplit Warning | {source}", MessageBoxButtons.OK, MessageBoxIcon.Warning); Debug.WriteLine("unload splits instance"); state.Run.AutoSplitter.Component?.Dispose(); state.Run.AutoSplitter.Deactivate(); state.Settings.ActiveAutoSplitters.Remove(state.Run.GameName); } if (createAsLayoutComponent) { if (!_instance.IsLayoutComponent) { unloadSplitsInstance(true); } else { throw new Exception($"Component already loaded"); } } else { if (_instance.IsLayoutComponent) { unloadSplitsInstance(false); return(null); } else { _instance.Dispose(); } } } /* * // if component is already loaded somewhere else * if (_instance != null && !_instance.Disposed) * throw new Exception($">:( )\n(Component already loaded in the {(_instance.IsLayoutComponent ? "Layout Editor" : "Splits Editor")}"); */ return(_instance = new SourceSplitComponent(state, createAsLayoutComponent)); }