예제 #1
0
        public void RemoveItem(string modFileName, object id)
        {
            // Setup
            var gameItemKey = new GameItemKey(modFileName, id);

            if (!gameItemsByIdAndFile.ContainsKey(gameItemKey))
            {
                return;
            }

            var item = gameItemsByIdAndFile[gameItemKey];

            var tuples = recordItemRegistry[modFileName];
            var tuple  = (from t in tuples
                          where t.Item2 == item
                          select t).First();
            var record = tuple.Item1;

            var modFile = modFiles[modFileName];


            item.IdChanged -= OnIdChange;

            // Remove corresponding record from mod file.
            modFile.RemoveRecord(record);

            // Remove item from Record <-> TES3GameItem relationship.
            tuples.Remove(tuple);

            // Remove from versions caches.
            var versions = gameItemVersionsById[item.Id];
            GameItemVersion <TES3GameItem> version = null;

            for (var i = 0; i < versions.Count; ++i)
            {
                if (versions[i].ModFileName == modFileName)
                {
                    version = versions[i];
                    versions.RemoveAt(i);
                    break;
                }
            }
            gameItemVersionsByType[item.GetType()].Remove(version);

            // Remove from type registry.
            gameItemsByTypeAndFile[new TypeKey(modFileName, item.GetType())].Remove(item);

            // Remove direct key.
            gameItemsByIdAndFile.Remove(gameItemKey);
        }
예제 #2
0
        void HandleCommonCache(string modFileName, TES3GameItem item)
        {
            var key = new GameItemKey(modFileName, item.Id);

            if (gameItemsByIdAndFile.ContainsKey(key))
            {
                throw new InvalidOperationException($"Key already present for ModFile {modFileName}: {item.Id}({item.GetType()}); Current is {gameItemsByIdAndFile[key]}");
            }
            gameItemsByIdAndFile.Add(key, item);


            var version = new GameItemVersion <TES3GameItem>(modFileName, item);

            gameItemVersionsById[item.Id].Add(version);
            gameItemVersionsByType[item.GetType()].Add(version);
            gameItemsByTypeAndFile[new TypeKey(modFileName, item.GetType())].Add(item);

            gameItemOwnership.Add(item, modFileName);

            item.IdChanged += OnIdChange;
        }