예제 #1
0
        public IObjectDefinition ProcessObjectDefinition(
            IManifestEntry manifestEntry,
            DirectoryInfo di,
            FileInfo fi,
            IReferenceFinderService referenceFinderService,
            ObjectType?objectTypeOverride = null)
        {
            var csvText        = File.ReadAllText(fi.FullName);
            var itemCollection = new ItemCollectionObjectDefinition(ObjectType.ItemCollectionDef, csvText, fi.FullName);

            itemCollection.AddMetaData();
            return(itemCollection);
        }
        public static object ProcessFile(
            IManifestEntry manifestEntry,
            DirectoryInfo di,
            string filename,
            string fileData,
            string hostDirectory,
            IReferenceFinderService referenceFinderService,
            ILogger logger)
        {
            var fi = new FileInfo(filename);

            if (fi.Extension == ".json")
            {
                var commasAdded = StreamingAssetProcessor.Regex.Replace(fileData, "$1,\n$2");

                // Handle json object definition...
                IObjectDefinition objectDefinition = null;
                dynamic           jsonData         = JsonConvert.DeserializeObject(
                    commasAdded,
                    new JsonSerializerSettings
                {
                    Error = (sender, args) =>
                    {
                        logger.Warn($"Error deserializing [{fi.FullName}]", args.ErrorContext.Error);
                        args.ErrorContext.Handled = true;
                    }
                });

                if (jsonData == null)
                {
                    return(null);
                }

                var description = ObjectDefinitionDescription.CreateDefault(jsonData.Description);

                var directoryMarkers = new List <string>()
                {
                    "conversationbuckets", "contracts", "events"
                };

                directoryMarkers.ForEach(
                    s =>
                {
                    if (di.FullName.Split('\\').Any(part => part.ToLower() == s.ToLower()))
                    {
                        hostDirectory = s;
                    }
                });

                if (manifestEntry.Manifest.Mod.IsBattleTech && streamingAssetsDirectoryToObjectTypes.ContainsKey(hostDirectory.ToLower()))
                {
                    var objectType = streamingAssetsDirectoryToObjectTypes[hostDirectory.ToLower()];
                    var objectDefinitionProcessor =
                        ObjectDefinitionProcessorFactory.ObjectDefinitionProcessorFactorySingleton.Get(objectType);

                    return(objectDefinitionProcessor.ProcessObjectDefinition(
                               manifestEntry,
                               di,
                               fi,
                               referenceFinderService,
                               objectType));
                }

                // infer the object type from the current sub-directory.
                switch (hostDirectory.ToLower())
                {
                case "abilities":
                case "constants":
                case "milestones":
                case "events":
                case "cast":
                case "behaviorvariables":
                case "buildings":
                case "hardpoints":
                case "factions":
                case "lifepathnode":
                case "campaign":
                    objectDefinition = new ObjectDefinition(
                        ObjectType.StreamingAssetsData,
                        description,
                        jsonData,
                        fi.FullName,
                        referenceFinderService);
                    break;

                case "pilot":
                    objectDefinition = new PilotObjectDefinition(
                        ObjectType.PilotDef,
                        description,
                        jsonData,
                        fi.FullName,
                        referenceFinderService);
                    break;

                case "simgameconstants":
                    objectDefinition = new SimGameConstantsObjectDefinition(
                        ObjectType.SimGameConstants,
                        ObjectDefinitionDescription.CreateDefault(jsonData.Description),
                        jsonData,
                        fi.FullName,
                        referenceFinderService);
                    break;

                    /*throw new InvalidProgramException(
                     *                              $"Unknown streaming assets folder type detected [{hostDirectory}]");*/
                }

                return(objectDefinition);
            }

            if (di.FullName.ToLower().Contains("emblems"))
            {
                hostDirectory = "emblems";
            }
            else if (di.FullName.ToLower().Contains("sprites"))
            {
                hostDirectory = "sprites";
            }
            else if (di.FullName.ToLower().Contains("conversationBuckets"))
            {
                hostDirectory = "conversationBuckets";
            }

            var identifier = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);

            switch (hostDirectory.ToLower())
            {
            case "assetbundles":
                var assetBundleDefinition = ObjectDefinitionFactory.ObjectDefinitionFactorySingleton.Get(
                    ObjectType.AssetBundle,
                    new ObjectDefinitionDescription(fi.Name, fi.Name, null),
                    null,
                    fi.FullName,
                    referenceFinderService);
                return(assetBundleDefinition);

            case "mechportraits":
                var objectDefinition = ObjectDefinitionFactory.ObjectDefinitionFactorySingleton.Get(
                    ObjectType.Sprite,
                    new ObjectDefinitionDescription(identifier, identifier, null),
                    null,
                    fi.FullName,
                    referenceFinderService);
                return(objectDefinition);

            case "itemcollections":
                var itemCollection = new ItemCollectionObjectDefinition(
                    ObjectType.ItemCollectionDef,
                    fileData,
                    fi.FullName);
                itemCollection.AddMetaData();
                return(itemCollection);

            case "emblems":
                var texIdentifier            = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);
                var resourceObjectDefinition = ObjectDefinitionFactory.ObjectDefinitionFactorySingleton.Get(
                    ObjectType.Texture2D,
                    new ObjectDefinitionDescription(texIdentifier, texIdentifier, null),
                    null,
                    fi.FullName,
                    referenceFinderService);
                return(resourceObjectDefinition);

            case "sprites":
                var spriteIdentifier = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);
                var spriteObject     = ObjectDefinitionFactory.ObjectDefinitionFactorySingleton.Get(
                    ObjectType.Sprite,
                    new ObjectDefinitionDescription(spriteIdentifier, spriteIdentifier, null),
                    null,
                    fi.FullName,
                    referenceFinderService);
                return(spriteObject);

            default:
                if (manifestEntry.Manifest.Mod.IsBattleTech)
                {
                    return(null);
                }

                IResourceDefinition resourceDefinition;

                // Handle resource file style definition...
                switch (fi.Name)
                {
                default:
                    resourceDefinition = new ResourceDefinition(
                        ObjectType.UnhandledResource,
                        fi.FullName,
                        fi.Name,
                        identifier);
                    resourceDefinition.AddMetaData();
                    break;
                }

                return(resourceDefinition);
            }
        }
예제 #3
0
        public static object ProcessFile(
            IManifestEntry manifestEntry,
            DirectoryInfo di,
            string filename,
            string fileData,
            string hostDirectory,
            IReferenceFinderService referenceFinderService)
        {
            var fi = new FileInfo(filename);

            if (fi.Extension == ".json")
            {
                // Handle json object definition...
                IObjectDefinition objectDefinition = null;
                dynamic           jsonData         = JsonConvert.DeserializeObject(fileData);
                var description = ObjectDefinitionDescription.CreateDefault(jsonData.Description);

                if (streamingAssetsDirectoryToObjectTypes.ContainsKey(hostDirectory.ToLower()))
                {
                    var objectType = streamingAssetsDirectoryToObjectTypes[hostDirectory.ToLower()];
                    var objectDefinitionProcessor =
                        ObjectDefinitionProcessorFactory.ObjectDefinitionProcessorFactorySingleton.Get(objectType);

                    return(objectDefinitionProcessor.ProcessObjectDefinition(
                               manifestEntry,
                               di,
                               fi,
                               referenceFinderService,
                               objectType));
                }

                // infer the object type from the current sub-directory.
                switch (hostDirectory.ToLower())
                {
                case "abilities":
                case "constants":
                case "milestones":
                case "events":
                case "cast":
                case "behaviorvariables":
                case "buildings":
                case "hardpoints":
                case "factions":
                case "lifepathnode":
                case "campaign":
                    objectDefinition = new ObjectDefinition(
                        ObjectType.StreamingAssetsData,
                        description,
                        jsonData,
                        fi.FullName,
                        referenceFinderService);
                    break;

                case "pilot":
                    objectDefinition = new PilotObjectDefinition(
                        ObjectType.PilotDef,
                        description,
                        jsonData,
                        fi.FullName,
                        referenceFinderService);
                    break;

                case "simgameconstants":
                    objectDefinition = new SimGameConstantsObjectDefinition(
                        ObjectType.SimGameConstants,
                        ObjectDefinitionDescription.CreateDefault(jsonData.Description),
                        jsonData,
                        fi.FullName,
                        referenceFinderService);
                    break;

                    /*throw new InvalidProgramException(
                     *                              $"Unknown streaming assets folder type detected [{hostDirectory}]");*/
                }

                return(objectDefinition);
            }

            switch (hostDirectory.ToLower())
            {
            case "itemcollections":
                var itemCollection = new ItemCollectionObjectDefinition(
                    ObjectType.ItemCollectionDef,
                    fileData,
                    fi.FullName);
                itemCollection.AddMetaData();
                return(itemCollection);

                break;

            default:
                if (manifestEntry.Manifest.Mod.IsBattleTech)
                {
                    return(null);
                }

                IResourceDefinition resourceDefinition;

                // Handle resource file style definition...
                switch (fi.Name)
                {
                default:
                    resourceDefinition = new ResourceDefinition(
                        ObjectType.UnhandledResource,
                        fi.FullName,
                        fi.Name,
                        fi.Name);
                    break;
                }

                return(resourceDefinition);

                // this.Resources.Add(resourceDefinition);

                // TBD: Add Note here -- throw new InvalidProgramException();
                break;
            }
        }