Exemplo n.º 1
0
 //private List<BindingExpression> _bindingExpressions = new List<BindingExpression>();
 /// <summary>
 /// Constructor for ModListControl
 /// </summary>
 public ModListControl()
 {
     InitializeComponent();
     _instanceManager = TorchBase.Instance.Managers.GetManager <InstanceManager>();
     _instanceManager.InstanceLoaded += _instanceManager_InstanceLoaded;
     _config = TorchBase.Instance.Config;
     //var mods = _instanceManager.DedicatedConfig?.Mods;
     //if( mods != null)
     //    DataContext = new ObservableCollection<MyObjectBuilder_Checkpoint.ModItem>();
     DataContext = _instanceManager.DedicatedConfig?.Mods;
     UgcServiceTypeBox.ItemsSource = new[]
     {
         new KeyValuePair <string, string>("Steam", "steam"),
         new KeyValuePair <string, string>("Mod.Io", "mod.io")
     };
     // Gets called once all children are loaded
     //Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(ApplyStyles));
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if a TorchBase instance already exists.</exception>
        protected TorchBase(ITorchConfig config)
        {
            RegisterCoreAssembly(GetType().Assembly);
            if (Instance != null)
            {
                throw new InvalidOperationException("A TorchBase instance already exists.");
            }

            Instance = this;
            Config   = config;

            var versionString = Assembly.GetEntryAssembly()
                                .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                .InformationalVersion;

            if (!InformationalVersion.TryParse(versionString, out InformationalVersion version))
            {
                throw new TypeLoadException("Unable to parse the Torch version from the assembly.");
            }

            TorchVersion = version;

            RunArgs = new string[0];

            Managers = new DependencyManager();

            Plugins = new PluginManager(this);

            var sessionManager = new TorchSessionManager(this);

            sessionManager.AddFactory((x) => Sync.IsServer ? new ChatManagerServer(this) : new ChatManagerClient(this));
            sessionManager.AddFactory((x) => Sync.IsServer ? new CommandManager(this) : null);
            sessionManager.AddFactory((x) => new EntityManager(this));

            Managers.AddManager(sessionManager);
            Managers.AddManager(new PatchManager(this));
            Managers.AddManager(new FilesystemManager(this));
            Managers.AddManager(new UpdateManager(this));
            Managers.AddManager(new EventManager(this));
            Managers.AddManager(Plugins);
            TorchAPI.Instance = this;

            GameStateChanged += (game, state) =>
            {
                if (state == TorchGameState.Created)
                {
                    // If the attached assemblies change (MySandboxGame.ctor => MySandboxGame.ParseArgs => MyPlugins.RegisterFromArgs)
                    // attach assemblies to object factories again.
                    ObjectFactoryInitPatch.ForceRegisterAssemblies();
                    // safe to commit here; all important static ctors have run
                    PatchManager.CommitInternal();
                }
            };

            sessionManager.SessionStateChanged += (session, state) =>
            {
                switch (state)
                {
                case TorchSessionState.Loading:
                    SessionLoading?.Invoke();
                    break;

                case TorchSessionState.Loaded:
                    SessionLoaded?.Invoke();
                    break;

                case TorchSessionState.Unloading:
                    SessionUnloading?.Invoke();
                    break;

                case TorchSessionState.Unloaded:
                    SessionUnloaded?.Invoke();
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(state), state, null);
                }
            };
        }