protected override Material[] GenerateMasks(GraphicRequestRGB req, PatternDef pattern)
        {
            Texture2D mainTex = ContentFinder <Texture2D> .Get(req.path);

            Texture2D maskTex = ContentFinder <Texture2D> .Get(req.path + MaskSuffix, false);

            masks = Enumerable.Repeat(maskTex, MatCount).ToArray();
            var mats = new Material[MatCount];
            MaterialRequestRGB mReq = new MaterialRequestRGB()
            {
                mainTex          = mainTex,
                shader           = req.shader,
                properties       = pattern.properties,
                color            = pattern.properties.colorOne ?? req.color,
                colorTwo         = pattern.properties.colorTwo ?? req.colorTwo,
                colorThree       = pattern.properties.colorThree ?? req.colorThree,
                tiles            = req.tiles,
                isSkin           = pattern is SkinDef,
                maskTex          = maskTex,
                patternTex       = pattern?[Rot8.North],
                shaderParameters = req.shaderParameters
            };

            mats[0] = MaterialPoolExpanded.MatFrom(mReq);
            return(mats);
        }
Esempio n. 2
0
        public override void Init(GraphicRequestRGB req, bool cacheResults = true)
        {
            base.Init(req);
            if (req.path.NullOrEmpty())
            {
                throw new ArgumentNullException("folderPath");
            }
            if (req.shader == null)
            {
                throw new ArgumentNullException("shader");
            }
            mainTex = ContentFinder <Texture2D> .Get(req.path);

            if (mainTex is null)
            {
                Log.Error($"{VehicleHarmony.LogLabel} Graphic_Cannon cannot init: No texture found at path " + req.path);
                graphicPath = BaseContent.BadGraphic.path;
                material    = BaseContent.BadMat;
                return;
            }
            else
            {
                foreach (PatternDef pattern in DefDatabase <PatternDef> .AllDefs)
                {
                    maskMatPatterns.Add(pattern, new Pair <string, Material[]>(req.path, GenerateMasks(req, pattern)));
                }
            }
        }
        public override void Init(GraphicRequestRGB req, bool cacheResults = true)
        {
            if (cacheResults is true)
            {
                masks           = new Texture2D[MatCount];
                maskMatPatterns = new Dictionary <PatternDef, Pair <string, Material[]> >();
            }
            data       = req.graphicData;
            path       = req.path;
            color      = req.color;
            colorTwo   = req.colorTwo;
            colorThree = req.colorThree;
            tiles      = req.tiles;
            drawSize   = req.drawSize;
            var files = ContentFinder <Texture2D> .GetAllInFolder(req.path);

            List <Texture2D> list = (from x in files
                                     where !x.name.EndsWith(MaskSuffix)
                                     orderby x.name
                                     select x).ToList();
            List <Texture2D> listM = (from x in files
                                      where x.name.EndsWith(MaskSuffix)
                                      orderby x.name
                                      select x).ToList();

            if (list.NullOrEmpty())
            {
                Log.Error("Collection cannot init: No textures found at path " + req.path);
                graphicPaths = new string[]
                {
                    BaseContent.BadGraphic.path
                };
                return;
            }
            graphicPaths = new string[list.Count];
            subGraphics  = new Graphic_Cannon[list.Count];
            subTextures  = list.ToArray();
            if (list.Count != listM.Count && !listM.NullOrEmpty())
            {
                Log.Error($"{VehicleHarmony.LogLabel} Could not apply masks for animation classes at path {req.path}. " +
                          $"Mask and texture count do not match up." +
                          $"\nMainTextures: {list.Count} Masks: {listM.Count}");
                graphicPaths = new string[]
                {
                    BaseContent.BadGraphic.path
                };
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                string fullPath = string.Concat(req.path, '/', list[i].name);
                graphicPaths[i] = fullPath;
                subGraphics[i]  = GraphicDatabaseRGB.Get <Graphic_Cannon>(fullPath, req.shader, req.drawSize, req.color, req.colorTwo, req.colorThree, req.tiles,
                                                                          req.displacement.x, req.displacement.y, DataRGB, req.shaderParameters) as Graphic_Cannon;
            }
        }
Esempio n. 4
0
 private static T GetInner <T>(GraphicRequestRGB req) where T : Graphic_RGB, new()
 {
     if (!allGraphics.TryGetValue(req, out Graphic_RGB graphic))
     {
         graphic = Activator.CreateInstance <T>();
         graphic.Init(req);
         allGraphics.Add(req, graphic);
     }
     return((T)graphic);
 }
Esempio n. 5
0
        public static Graphic_RGB Get(Type graphicClass, string path, Shader shader, Vector2 drawSize, Color color, Color colorTwo, Color colorThree, float tiles = 1, float displacementX = 0, float displacementY = 0, GraphicDataRGB data = null, List <ShaderParameter> shaderParameters = null)
        {
            GraphicRequestRGB graphicRequest = new GraphicRequestRGB(graphicClass, path, shader, drawSize, color, colorTwo, colorThree, tiles, new Vector2(displacementX, displacementY), data, 0, shaderParameters);

            if (graphicRequest.graphicClass == typeof(Graphic_Vehicle))
            {
                return(GetInner <Graphic_Vehicle>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_Cannon))
            {
                return(GetInner <Graphic_Cannon>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_CannonAnimate))
            {
                return(GetInner <Graphic_CannonAnimate>(graphicRequest));
            }
            try
            {
                return((Graphic_RGB)GenGeneric.InvokeStaticGenericMethod(typeof(GraphicDatabaseRGB), graphicRequest.graphicClass, "GetInner", new object[]
                {
                    graphicRequest
                }));
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Exception getting ",
                    graphicClass,
                    " at ",
                    path,
                    ": ",
                    ex.ToString()
                }));
            }
            return(null);
        }
Esempio n. 6
0
        public override void Init(GraphicRequestRGB req, bool cacheResults = true)
        {
            base.Init(req);
            textureArray    = new Texture2D[MatCount];
            textureArray[0] = ContentFinder <Texture2D> .Get(req.path + "_north", false);

            textureArray[0] ??= ContentFinder <Texture2D> .Get(req.path, false);

            textureArray[1] = ContentFinder <Texture2D> .Get(req.path + "_east", false);

            textureArray[2] = ContentFinder <Texture2D> .Get(req.path + "_south", false);

            textureArray[3] = ContentFinder <Texture2D> .Get(req.path + "_west", false);

            textureArray[4] = ContentFinder <Texture2D> .Get(req.path + "_northEast", false);

            textureArray[5] = ContentFinder <Texture2D> .Get(req.path + "_southEast", false);

            textureArray[6] = ContentFinder <Texture2D> .Get(req.path + "_southWest", false);

            textureArray[7] = ContentFinder <Texture2D> .Get(req.path + "_northWest", false);

            if (textureArray[0] is null)
            {
                if (textureArray[2] != null)
                {
                    textureArray[0]             = textureArray[2];
                    drawRotatedExtraAngleOffset = 180f;
                }
                else if (textureArray[1] != null)
                {
                    textureArray[0]             = textureArray[1];
                    drawRotatedExtraAngleOffset = -90f;
                }
                else if (textureArray[3] != null)
                {
                    textureArray[0]             = textureArray[3];
                    drawRotatedExtraAngleOffset = 90f;
                }
            }
            if (textureArray[0] is null)
            {
                Log.Error("Failed to find any textures at " + req.path + " while constructing " + this.ToStringSafe());
                return;
            }
            if (textureArray[2] is null)
            {
                textureArray[2] = textureArray[0];
            }
            if (textureArray[1] is null)
            {
                if (textureArray[3] != null)
                {
                    textureArray[1] = textureArray[3];
                    eastFlipped     = DataAllowsFlip;
                }
                else
                {
                    textureArray[1] = textureArray[0];
                }
            }
            if (textureArray[3] is null)
            {
                if (textureArray[1] != null)
                {
                    textureArray[3] = textureArray[1];
                    westFlipped     = DataAllowsFlip;
                }
                else
                {
                    textureArray[3] = textureArray[0];
                }
            }

            if (textureArray[4] is null)
            {
                textureArray[4]     = textureArray[0];
                eastDiagonalRotated = DataAllowsFlip;
            }
            if (textureArray[5] is null)
            {
                textureArray[5]     = textureArray[2];
                eastDiagonalRotated = DataAllowsFlip;
            }
            if (textureArray[6] is null)
            {
                textureArray[6]     = textureArray[2];
                westDiagonalRotated = DataAllowsFlip;
            }
            if (textureArray[7] is null)
            {
                textureArray[7]     = textureArray[0];
                westDiagonalRotated = DataAllowsFlip;
            }

            foreach (PatternDef pattern in DefDatabase <PatternDef> .AllDefs)
            {
                maskMatPatterns.Add(pattern, new Pair <string, Material[]>(req.path, GenerateMasks(req, pattern)));
            }
        }