private static void ConvertFieldIDs(List <Field> fields, NewIDs newIDs)
        {
            foreach (var field in fields)
            {
                int oldID = Tools.StringToInt(field.value);
                switch (field.type)
                {
                case FieldType.Actor:
                    if (newIDs.actor.ContainsKey(oldID))
                    {
                        field.value = newIDs.actor[oldID].ToString();
                    }
                    break;

                case FieldType.Item:
                    if (newIDs.item.ContainsKey(oldID))
                    {
                        field.value = newIDs.item[oldID].ToString();
                    }
                    break;

                case FieldType.Location:
                    if (newIDs.location.ContainsKey(oldID))
                    {
                        field.value = newIDs.location[oldID].ToString();
                    }
                    break;
                }
            }
        }
Esempio n. 2
0
 private static void ConvertFieldIDs(List<Field> fields, NewIDs newIDs)
 {
     foreach (var field in fields) {
         int oldID = Tools.StringToInt(field.value);
         switch (field.type) {
         case FieldType.Actor:
             if (newIDs.actor.ContainsKey(oldID)) field.value = newIDs.actor[oldID].ToString();
             break;
         case FieldType.Item:
             if (newIDs.item.ContainsKey(oldID)) field.value = newIDs.item[oldID].ToString();
             break;
         case FieldType.Location:
             if (newIDs.location.ContainsKey(oldID)) field.value = newIDs.location[oldID].ToString();
             break;
         }
     }
 }
        /// <summary>
        /// Merges a source database into a destination database by first determining new IDs,
        /// then assigning those IDs as it copies assets over.
        /// </summary>
        /// <param name="destination">Destination database.</param>
        /// <param name="source">Source database.</param>
        private static void MergeAssignUniqueIDs(DialogueDatabase destination, DialogueDatabase source,
                                                 bool mergeProperties, bool mergeActors, bool mergeItems, bool mergeLocations,
                                                 bool mergeVariables, bool mergeConversations)
        {
            if (mergeProperties)
            {
                MergeDatabaseProperties(destination, source);
            }
            NewIDs newIDs = new NewIDs();

            GetNewActorIDs(destination, source, newIDs);
            GetNewItemIDs(destination, source, newIDs);
            GetNewLocationIDs(destination, source, newIDs);
            GetNewVariableIDs(destination, source, newIDs);
            GetNewConversationIDs(destination, source, newIDs);
            if (mergeActors)
            {
                MergeActors(destination, source, newIDs);
            }
            if (mergeItems)
            {
                MergeItems(destination, source, newIDs);
            }
            if (mergeLocations)
            {
                MergeLocations(destination, source, newIDs);
            }
            if (mergeVariables)
            {
                MergeVariables(destination, source, newIDs);
            }
            if (mergeConversations)
            {
                MergeConversations(destination, source, newIDs);
            }
        }
        private static void GetNewActorIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
        {
            int highestID = 0;

            foreach (var actor in destination.actors)
            {
                highestID = Mathf.Max(actor.id, highestID);
                if (actor.IsPlayer)
                {
                    newIDs.destinationHasPlayerActor = true;
                }
            }
            int newID = highestID + 1;

            foreach (var actor in source.actors)
            {
                if (!(actor.IsPlayer && newIDs.destinationHasPlayerActor))
                {
                    if (destination.actors.Find(x => string.Equals(x.Name, actor.Name)) == null)
                    {
                        newIDs.actor[actor.id] = newID;
                        newID++;
                    }
                }
            }
        }
Esempio n. 5
0
 private static void GetNewItemIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     int highestID = 0;
     foreach (var item in destination.items) {
         highestID = Mathf.Max(item.id, highestID);
     }
     int newID = highestID + 1;
     foreach (var item in source.items) {
         if (destination.items.Find(x => string.Equals(x.Name, item.Name)) == null) {
             newIDs.item[item.id] = newID;
             newID++;
         }
     }
 }
 private static void MergeVariables(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var variable in source.variables)
     {
         if (newIDs.variable.ContainsKey(variable.id))
         {
             Variable newVariable = new Variable(variable);
             newVariable.id = newIDs.variable[variable.id];
             ConvertFieldIDs(newVariable.fields, newIDs);
             destination.variables.Add(newVariable);
         }
     }
 }
 private static void MergeItems(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var item in source.items)
     {
         if (newIDs.item.ContainsKey(item.id))
         {
             Item newItem = new Item(item);
             newItem.id = newIDs.item[item.id];
             ConvertFieldIDs(newItem.fields, newIDs);
             destination.items.Add(newItem);
         }
     }
 }
        private static void GetNewVariableIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
        {
            int highestID = 0;

            foreach (var variable in destination.variables)
            {
                highestID = Mathf.Max(variable.id, highestID);
                if (string.Equals(variable.Name, "Alert"))
                {
                    newIDs.destinationHasAlertVariable = true;
                }
            }
            int newID = highestID + 1;

            foreach (var variable in source.variables)
            {
                if (!(string.Equals(variable.Name, "Alert") && newIDs.destinationHasAlertVariable))
                {
                    if (destination.variables.Find(x => string.Equals(x.Name, variable.Name)) == null)
                    {
                        newIDs.variable[variable.id] = newID;
                        newID++;
                    }
                }
            }
        }
Esempio n. 9
0
 private static void MergeItems(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var item in source.items) {
         if (newIDs.item.ContainsKey(item.id)) {
             Item newItem = new Item(item);
             newItem.id = newIDs.item[item.id];
             ConvertFieldIDs(newItem.fields, newIDs);
             destination.items.Add(newItem);
         }
     }
 }
Esempio n. 10
0
 private static void MergeConversations(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var conversation in source.conversations) {
         if (newIDs.conversation.ContainsKey(conversation.id)) {
             Conversation newConversation = new Conversation(conversation);
             newConversation.id = newIDs.conversation[conversation.id];
             ConvertFieldIDs(newConversation.fields, newIDs);
             foreach (DialogueEntry newEntry in newConversation.dialogueEntries) {
                 newEntry.conversationID = newConversation.id;
                 foreach (var newLink in newEntry.outgoingLinks) {
                     if (newIDs.conversation.ContainsKey(newLink.originConversationID)) newLink.originConversationID = newIDs.conversation[newLink.originConversationID];
                     if (newIDs.conversation.ContainsKey(newLink.destinationConversationID)) newLink.destinationConversationID = newIDs.conversation[newLink.destinationConversationID];
                 }
             }
             destination.conversations.Add(newConversation);
         }
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Merges a source database into a destination database by first determining new IDs, 
        /// then assigning those IDs as it copies assets over.
        /// </summary>
        /// <param name="destination">Destination database.</param>
        /// <param name="source">Source database.</param>
        private static void MergeAssignUniqueIDs(DialogueDatabase destination, DialogueDatabase source,
		                                         bool mergeProperties, bool mergeActors, bool mergeItems, bool mergeLocations, 
		                                         bool mergeVariables, bool mergeConversations)
        {
            if (mergeProperties) MergeDatabaseProperties(destination, source);
            NewIDs newIDs = new NewIDs();
            GetNewActorIDs(destination, source, newIDs);
            GetNewItemIDs(destination, source, newIDs);
            GetNewLocationIDs(destination, source, newIDs);
            GetNewVariableIDs(destination, source, newIDs);
            GetNewConversationIDs(destination, source, newIDs);
            if (mergeActors) MergeActors(destination, source, newIDs);
            if (mergeItems) MergeItems(destination, source, newIDs);
            if (mergeLocations) MergeLocations(destination, source, newIDs);
            if (mergeVariables) MergeVariables(destination, source, newIDs);
            if (mergeConversations) MergeConversations(destination, source, newIDs);
        }
Esempio n. 12
0
 private static void MergeActors(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var actor in source.actors) {
         if (newIDs.actor.ContainsKey(actor.id)) {
             Actor newActor = new Actor(actor);
             newActor.id = newIDs.actor[actor.id];
             ConvertFieldIDs(newActor.fields, newIDs);
             destination.actors.Add(newActor);
         }
     }
 }
Esempio n. 13
0
 private static void GetNewVariableIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     int highestID = 0;
     foreach (var variable in destination.variables) {
         highestID = Mathf.Max(variable.id, highestID);
         if (string.Equals(variable.Name, "Alert")) newIDs.destinationHasAlertVariable = true;
     }
     int newID = highestID + 1;
     foreach (var variable in source.variables) {
         if (!(string.Equals(variable.Name, "Alert") && newIDs.destinationHasAlertVariable)) {
             if (destination.variables.Find(x => string.Equals(x.Name, variable.Name)) == null) {
                 newIDs.variable[variable.id] = newID;
                 newID++;
             }
         }
     }
 }
Esempio n. 14
0
 private static void GetNewLocationIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     int highestID = 0;
     foreach (var location in destination.locations) {
         highestID = Mathf.Max(location.id, highestID);
     }
     int newID = highestID + 1;
     foreach (var location in source.locations) {
         if (destination.locations.Find(x => string.Equals(x.Name, location.Name)) == null) {
             newIDs.location[location.id] = newID;
             newID++;
         }
     }
 }
        private static void GetNewItemIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
        {
            int highestID = 0;

            foreach (var item in destination.items)
            {
                highestID = Mathf.Max(item.id, highestID);
            }
            int newID = highestID + 1;

            foreach (var item in source.items)
            {
                if (destination.items.Find(x => string.Equals(x.Name, item.Name)) == null)
                {
                    newIDs.item[item.id] = newID;
                    newID++;
                }
            }
        }
        private static void GetNewLocationIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
        {
            int highestID = 0;

            foreach (var location in destination.locations)
            {
                highestID = Mathf.Max(location.id, highestID);
            }
            int newID = highestID + 1;

            foreach (var location in source.locations)
            {
                if (destination.locations.Find(x => string.Equals(x.Name, location.Name)) == null)
                {
                    newIDs.location[location.id] = newID;
                    newID++;
                }
            }
        }
Esempio n. 17
0
 private static void MergeLocations(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var location in source.locations) {
         if (newIDs.location.ContainsKey(location.id)) {
             Location newLocation = new Location(location);
             newLocation.id = newIDs.location[location.id];
             ConvertFieldIDs(newLocation.fields, newIDs);
             destination.locations.Add(newLocation);
         }
     }
 }
        private static void GetNewConversationIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
        {
            int highestID = 0;

            foreach (var conversation in destination.conversations)
            {
                highestID = Mathf.Max(conversation.id, highestID);
            }
            int newID = highestID + 1;

            foreach (var conversation in source.conversations)
            {
                newIDs.conversation[conversation.id] = newID;
                newID++;
            }
        }
Esempio n. 19
0
 private static void MergeVariables(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var variable in source.variables) {
         if (newIDs.variable.ContainsKey(variable.id)) {
             Variable newVariable = new Variable(variable);
             newVariable.id = newIDs.variable[variable.id];
             ConvertFieldIDs(newVariable.fields, newIDs);
             destination.variables.Add(newVariable);
         }
     }
 }
 private static void MergeActors(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var actor in source.actors)
     {
         if (newIDs.actor.ContainsKey(actor.id))
         {
             Actor newActor = new Actor(actor);
             newActor.id = newIDs.actor[actor.id];
             ConvertFieldIDs(newActor.fields, newIDs);
             destination.actors.Add(newActor);
         }
     }
 }
Esempio n. 21
0
 private static void GetNewActorIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     int highestID = 0;
     foreach (var actor in destination.actors) {
         highestID = Mathf.Max(actor.id, highestID);
         if (actor.IsPlayer) newIDs.destinationHasPlayerActor = true;
     }
     int newID = highestID + 1;
     foreach (var actor in source.actors) {
         if (!(actor.IsPlayer && newIDs.destinationHasPlayerActor)) {
             if (destination.actors.Find(x => string.Equals(x.Name, actor.Name)) == null) {
                 newIDs.actor[actor.id] = newID;
                 newID++;
             }
         }
     }
 }
 private static void MergeLocations(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var location in source.locations)
     {
         if (newIDs.location.ContainsKey(location.id))
         {
             Location newLocation = new Location(location);
             newLocation.id = newIDs.location[location.id];
             ConvertFieldIDs(newLocation.fields, newIDs);
             destination.locations.Add(newLocation);
         }
     }
 }
Esempio n. 23
0
 private static void MergeConversations(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var conversation in source.conversations)
     {
         if (newIDs.conversation.ContainsKey(conversation.id))
         {
             Conversation newConversation = new Conversation(conversation);
             newConversation.id = newIDs.conversation[conversation.id];
             ConvertFieldIDs(newConversation.fields, newIDs);
             foreach (DialogueEntry newEntry in newConversation.dialogueEntries)
             {
                 newEntry.conversationID = newConversation.id;
                 foreach (var newLink in newEntry.outgoingLinks)
                 {
                     if (newIDs.conversation.ContainsKey(newLink.originConversationID))
                     {
                         newLink.originConversationID = newIDs.conversation[newLink.originConversationID];
                     }
                     if (newIDs.conversation.ContainsKey(newLink.destinationConversationID))
                     {
                         newLink.destinationConversationID = newIDs.conversation[newLink.destinationConversationID];
                     }
                 }
             }
             destination.conversations.Add(newConversation);
         }
     }
 }
 private static void MergeConversations(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     foreach (var conversation in source.conversations)
     {
         if (newIDs.conversation.ContainsKey(conversation.id))
         {
             Conversation newConversation = new Conversation(conversation);
             newConversation.id = newIDs.conversation[conversation.id];
             var existingByTitle = destination.conversations.Find(c => string.Equals(c.Title, conversation.Title));
             if (existingByTitle != null)
             {
                 newConversation.Title = conversation.Title + " Copy";
             }
             ConvertFieldIDs(newConversation.fields, newIDs);
             foreach (DialogueEntry newEntry in newConversation.dialogueEntries)
             {
                 newEntry.conversationID = newConversation.id;
                 foreach (var newLink in newEntry.outgoingLinks)
                 {
                     if (newIDs.conversation.ContainsKey(newLink.originConversationID))
                     {
                         newLink.originConversationID = newIDs.conversation[newLink.originConversationID];
                     }
                     if (newIDs.conversation.ContainsKey(newLink.destinationConversationID))
                     {
                         newLink.destinationConversationID = newIDs.conversation[newLink.destinationConversationID];
                     }
                 }
             }
             destination.conversations.Add(newConversation);
         }
     }
 }
Esempio n. 25
0
 private static void GetNewConversationIDs(DialogueDatabase destination, DialogueDatabase source, NewIDs newIDs)
 {
     int highestID = 0;
     foreach (var conversation in destination.conversations) {
         highestID = Mathf.Max(conversation.id, highestID);
     }
     int newID = highestID + 1;
     foreach (var conversation in source.conversations) {
         newIDs.conversation[conversation.id] = newID;
         newID++;
     }
 }