Esempio n. 1
0
 internal static object GetIdentifier(RecordIdentifierContext context)
 {
     if (CellUtils.IsInterior(context.record))
     {
         return(CellUtils.GetName(context.record));
     }
     else
     {
         return(CellUtils.GetGridKey(context.record));
     }
 }
Esempio n. 2
0
        public void Load(ModFile modFile)
        {
            if (modFiles.ContainsKey(modFile.Name))
            {
                throw new ArgumentException($"Mod file already loaded: {modFile.Name}");
            }

            // Cache mod file.
            modFiles.Add(modFile.Name, modFile);

            // Create Record <-> TES3GameItem relationship.
            var regItems = new List <Tuple <Record, TES3GameItem> >();

            recordItemRegistry.Add(modFile.Name, regItems);


            DialogueTopic currentTopic = null;
            IDictionary <string, DialogueResponse> currentResponses = null;

            foreach (var record in modFile)
            {
                // Create Item
                TES3GameItem item;
                if (record.Name == "CELL")
                {
                    if (CellUtils.IsInterior(record))
                    {
                        item = new InteriorCell(record);
                    }
                    else
                    {
                        item = new ExteriorCell(record);
                    }
                }
                else
                {
                    if (!GameItemConstructors.ContainsKey(record.Name))
                    {
                        throw new ArgumentException($"Unrecognized record type: {record.Name}");
                    }

                    var constructor = GameItemConstructors[record.Name];
                    item = (TES3GameItem)constructor.Invoke(new Record[] { record });
                }


                // Cache individual Record <-> TES3GameItem relationship.
                regItems.Add(new Tuple <Record, TES3GameItem>(record, item));

                if (item.GetType() == typeof(DialogueTopic))
                {
                    if (currentTopic != null)
                    {
                        var dialogue = new Dialogue(modFile.Name, currentTopic, currentResponses, OnAddDialogueResponse, OnRemoveDialogueResponse);
                        dialogueVersionsById[currentTopic.Name].Add(new GameItemVersion <Dialogue>(modFile.Name, dialogue));
                        dialogueByModFile[modFile.Name].Add(dialogue);
                        dialogueByIdAndFile.Add(new GameItemKey(modFile.Name, currentTopic.Name), new Tuple <Record, Dialogue>(record, dialogue));
                    }

                    currentTopic     = (DialogueTopic)item;
                    currentResponses = new Dictionary <string, DialogueResponse>();
                    item.IdChanged  += OnIdChange;
                }
                else if (item.GetType() == typeof(DialogueResponse))
                {
                    if (currentTopic == null)
                    {
                        throw new InvalidOperationException();
                    }

                    var dialogueItem = (DialogueResponse)item;
                    currentResponses.Add(dialogueItem.Identifier, dialogueItem);
                }
                else
                {
                    if (currentTopic != null)
                    {
                        var dialogue = new Dialogue(modFile.Name, currentTopic, currentResponses, OnAddDialogueResponse, OnRemoveDialogueResponse);
                        dialogueVersionsById[currentTopic.Name].Add(new GameItemVersion <Dialogue>(modFile.Name, dialogue));
                        dialogueByModFile[modFile.Name].Add(dialogue);
                        dialogueByIdAndFile.Add(new GameItemKey(modFile.Name, currentTopic.Name), new Tuple <Record, Dialogue>(record, dialogue));
                        currentTopic     = null;
                        currentResponses = null;
                    }

                    // Handle common caching.
                    HandleCommonCache(modFile.Name, item);
                }
            }
        }