Ejemplo n.º 1
0
        public SkinManager(Storage storage, DatabaseContextFactory contextFactory, GameHost host, IResourceStore <byte[]> resources, AudioManager audio)
        {
            this.audio     = audio;
            this.host      = host;
            this.resources = resources;

            skinStore = new SkinStore(contextFactory, storage);
            userFiles = new FileStore(contextFactory, storage).Store;

            skinModelManager = new SkinModelManager(storage, contextFactory, skinStore, host, this);

            DefaultLegacySkin = new DefaultLegacySkin(this);
            DefaultSkin       = new DefaultSkin(this);

            CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = GetSkin(skin.NewValue);

            CurrentSkin.Value         = DefaultSkin;
            CurrentSkin.ValueChanged += skin =>
            {
                if (skin.NewValue.SkinInfo != CurrentSkinInfo.Value)
                {
                    throw new InvalidOperationException($"Setting {nameof(CurrentSkin)}'s value directly is not supported. Use {nameof(CurrentSkinInfo)} instead.");
                }

                SourceChanged?.Invoke();
            };
        }
Ejemplo n.º 2
0
        public SkinManager(Storage storage, RealmAccess realm, GameHost host, IResourceStore <byte[]> resources, AudioManager audio, Scheduler scheduler)
        {
            this.realm     = realm;
            this.audio     = audio;
            this.scheduler = scheduler;
            this.host      = host;
            this.resources = resources;

            userFiles = new StorageBackedResourceStore(storage.GetStorageForDirectory("files"));

            skinModelManager = new SkinModelManager(storage, realm, this);

            var defaultSkins = new[]
            {
                DefaultLegacySkin = new DefaultLegacySkin(this),
                DefaultSkin       = new DefaultSkin(this),
            };

            // Ensure the default entries are present.
            realm.Write(r =>
            {
                foreach (var skin in defaultSkins)
                {
                    if (r.Find <SkinInfo>(skin.SkinInfo.ID) == null)
                    {
                        r.Add(skin.SkinInfo.Value);
                    }
                }
            });

            CurrentSkinInfo.ValueChanged += skin =>
            {
                CurrentSkin.Value = skin.NewValue.PerformRead(GetSkin);
            };

            CurrentSkin.Value         = DefaultSkin;
            CurrentSkin.ValueChanged += skin =>
            {
                if (!skin.NewValue.SkinInfo.Equals(CurrentSkinInfo.Value))
                {
                    throw new InvalidOperationException($"Setting {nameof(CurrentSkin)}'s value directly is not supported. Use {nameof(CurrentSkinInfo)} instead.");
                }

                SourceChanged?.Invoke();
            };
        }
Ejemplo n.º 3
0
        public SkinManager(Storage storage, RealmContextFactory contextFactory, GameHost host, IResourceStore <byte[]> resources, AudioManager audio, Scheduler scheduler)
        {
            this.contextFactory = contextFactory;
            this.audio          = audio;
            this.scheduler      = scheduler;
            this.host           = host;
            this.resources      = resources;

            userFiles = new StorageBackedResourceStore(storage.GetStorageForDirectory("files"));

            skinModelManager = new SkinModelManager(storage, contextFactory, host, this);

            var defaultSkins = new[]
            {
                DefaultLegacySkin = new DefaultLegacySkin(this),
                DefaultSkin       = new DefaultSkin(this),
            };

            // Ensure the default entries are present.
            using (var context = contextFactory.CreateContext())
                using (var transaction = context.BeginWrite())
                {
                    foreach (var skin in defaultSkins)
                    {
                        if (context.Find <SkinInfo>(skin.SkinInfo.ID) == null)
                        {
                            context.Add(skin.SkinInfo.Value);
                        }
                    }

                    transaction.Commit();
                }

            CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = skin.NewValue.PerformRead(GetSkin);

            CurrentSkin.Value         = DefaultSkin;
            CurrentSkin.ValueChanged += skin =>
            {
                if (!skin.NewValue.SkinInfo.Equals(CurrentSkinInfo.Value))
                {
                    throw new InvalidOperationException($"Setting {nameof(CurrentSkin)}'s value directly is not supported. Use {nameof(CurrentSkinInfo)} instead.");
                }

                SourceChanged?.Invoke();
            };
        }