Esempio n. 1
0
        public override void Execute(ModScriptDatabaseHelper database)
        {
            VltCollection srcCollection = GetCollection(database, ClassName, SourceCollectionName);
            VltCollection dstCollection = GetCollection(database, ClassName, DestinationCollectionName);
            Dictionary <VltClassField, VLTBaseType> values = new Dictionary <VltClassField, VLTBaseType>();

            if ((Options & CopyOptions.Base) != 0)
            {
                foreach (var baseField in srcCollection.Class.BaseFields)
                {
                    values.Add(baseField,
                               ValueCloningUtils.CloneValue(database.Database, srcCollection.GetRawValue(baseField.Name), srcCollection.Class,
                                                            baseField, dstCollection));
                }
            }

            if ((Options & CopyOptions.Optional) != 0)
            {
                foreach (var(key, value) in srcCollection.GetData())
                {
                    var field = srcCollection.Class[key];

                    if (!field.IsInLayout)
                    {
                        values.Add(field, ValueCloningUtils.CloneValue(database.Database, value, srcCollection.Class, field, dstCollection));
                    }
                }
            }

            // base will always overwrite
            // optional by itself will copy anything that doesn't exist
            // optional + overwrite will copy nonexistent fields and overwrite the other ones(optional only)
            if ((Options & CopyOptions.Base) != 0)
            {
                foreach (var(key, value) in values)
                {
                    if (key.IsInLayout)
                    {
                        dstCollection.SetRawValue(key.Name, value);
                    }
                }
            }

            if ((Options & CopyOptions.Optional) != 0)
            {
                foreach (var(field, value) in values)
                {
                    if (!field.IsInLayout && (!dstCollection.HasEntry(field.Name) || (Options & CopyOptions.OverwriteOptional) != 0))
                    {
                        dstCollection.SetRawValue(field.Name, value);
                    }
                }
            }
        }
Esempio n. 2
0
 private static IEnumerable <string> CollectStrings(VltCollection collection)
 {
     return(collection.GetData().Values.OfType <IReferencesStrings>().SelectMany(r => r.GetStrings()));
 }