// Token: 0x06000055 RID: 85 RVA: 0x00004BB0 File Offset: 0x00002DB0
        public static tk2dSpriteAnimationClip BuildAnimation(AIAnimator aiAnimator, string name, string spriteDirectory, int fps)
        {
            tk2dSpriteCollectionData tk2dSpriteCollectionData = aiAnimator.GetComponent <tk2dSpriteCollectionData>();
            bool flag = !tk2dSpriteCollectionData;

            if (flag)
            {
                tk2dSpriteCollectionData = SpriteBuilder.ConstructCollection(aiAnimator.gameObject, aiAnimator.name + "_collection");
            }
            string[]   resourceNames = ResourceExtractor.GetResourceNames();
            List <int> list          = new List <int>();

            for (int i = 0; i < resourceNames.Length; i++)
            {
                bool flag2 = resourceNames[i].StartsWith(spriteDirectory.Replace('/', '.'), StringComparison.OrdinalIgnoreCase);
                if (flag2)
                {
                    list.Add(SpriteBuilder.AddSpriteToCollection(resourceNames[i], tk2dSpriteCollectionData));
                }
            }
            bool flag3 = list.Count == 0;

            if (flag3)
            {
                Tools.PrintError <string>("No sprites found for animation " + name, "FF0000");
            }
            tk2dSpriteAnimationClip tk2dSpriteAnimationClip = SpriteBuilder.AddAnimation(aiAnimator.spriteAnimator, tk2dSpriteCollectionData, list, name, tk2dSpriteAnimationClip.WrapMode.Loop);

            tk2dSpriteAnimationClip.fps = (float)fps;
            return(tk2dSpriteAnimationClip);
        }
        // Token: 0x0600002E RID: 46 RVA: 0x000035EC File Offset: 0x000017EC
        public static List <Texture2D> GetTexturesFromDirectory(string directoryPath)
        {
            bool             flag = !Directory.Exists(directoryPath);
            List <Texture2D> result;

            if (flag)
            {
                Tools.PrintError <string>(directoryPath + " not found.", "FF0000");
                result = null;
            }
            else
            {
                List <Texture2D> list = new List <Texture2D>();
                foreach (string text in Directory.GetFiles(directoryPath))
                {
                    bool flag2 = !text.EndsWith(".png");
                    if (!flag2)
                    {
                        Texture2D item = ResourceExtractor.BytesToTexture(File.ReadAllBytes(text), Path.GetFileName(text).Replace(".png", ""));
                        list.Add(item);
                    }
                }
                result = list;
            }
            return(result);
        }
Example #3
0
        public static tk2dSpriteAnimationClip BuildAnimation(AIAnimator aiAnimator, string name, string spriteDirectory, int fps)
        {
            tk2dSpriteCollectionData collection = aiAnimator.GetComponent <tk2dSpriteCollectionData>();

            if (!collection)
            {
                collection = SpriteBuilder.ConstructCollection(aiAnimator.gameObject, $"{aiAnimator.name}_collection");
            }

            string[]   resources = ResourceExtractor.GetResourceNames();
            List <int> indices   = new List <int>();

            for (int i = 0; i < resources.Length; i++)
            {
                if (resources[i].StartsWith(spriteDirectory.Replace('/', '.'), StringComparison.OrdinalIgnoreCase))
                {
                    indices.Add(SpriteBuilder.AddSpriteToCollection(resources[i], collection));
                }
            }
            if (indices.Count == 0)
            {
                Tools.PrintError($"No sprites found for animation {name}");
            }
            tk2dSpriteAnimationClip clip = SpriteBuilder.AddAnimation(aiAnimator.spriteAnimator, collection, indices, name, tk2dSpriteAnimationClip.WrapMode.Loop);

            clip.fps = fps;
            return(clip);
        }
        // Token: 0x06000037 RID: 55 RVA: 0x00003918 File Offset: 0x00001B18
        public static Texture2D GetTextureFromResource(string resourceName)
        {
            byte[]    array = ResourceExtractor.ExtractEmbeddedResource(resourceName);
            bool      flag  = array == null;
            Texture2D result;

            if (flag)
            {
                Tools.PrintError <string>("No bytes found in " + resourceName, "FF0000");
                result = null;
            }
            else
            {
                Texture2D texture2D = new Texture2D(1, 1, TextureFormat.RGBAFloat, false);
                texture2D.LoadImage(array);
                texture2D.filterMode = FilterMode.Point;
                string text  = resourceName.Substring(0, resourceName.LastIndexOf('.'));
                bool   flag2 = text.LastIndexOf('.') >= 0;
                if (flag2)
                {
                    text = text.Substring(text.LastIndexOf('.') + 1);
                }
                texture2D.name = text;
                result         = texture2D;
            }
            return(result);
        }
        public static RoomData BuildFromResource(string roomPath)
        {
            var      texture  = ResourceExtractor.GetTextureFromResource(roomPath);
            RoomData roomData = ExtractRoomDataFromResource(roomPath);

            roomData.room = Build(texture, roomData);
            return(roomData);
        }
		// Token: 0x06000033 RID: 51 RVA: 0x00004234 File Offset: 0x00002434
		public static string[] GetLinesFromEmbeddedResource(string filePath)
		{
			string text = ResourceExtractor.BytesToString(ResourceExtractor.ExtractEmbeddedResource(filePath));
			return text.Split(new char[]
			{
				'\n'
			});
		}
		// Token: 0x06000034 RID: 52 RVA: 0x00004264 File Offset: 0x00002464
		public static string[] GetLinesFromFile(string filePath)
		{
			string text = ResourceExtractor.BytesToString(File.ReadAllBytes(filePath));
			return text.Split(new char[]
			{
				'\n'
			});
		}
        // Token: 0x0600003C RID: 60 RVA: 0x00003AD8 File Offset: 0x00001CD8
        public static RoomFactory.RoomData BuildFromResource(string roomPath)
        {
            Texture2D textureFromResource = ResourceExtractor.GetTextureFromResource(roomPath);

            RoomFactory.RoomData roomData = RoomFactory.ExtractRoomDataFromResource(roomPath);
            roomData.room = RoomFactory.Build(textureFromResource, roomData);
            return(roomData);
        }
        // Token: 0x0600003B RID: 59 RVA: 0x00003A94 File Offset: 0x00001C94
        public static RoomFactory.RoomData BuildFromFile(string roomPath)
        {
            Texture2D textureFromFile = ResourceExtractor.GetTextureFromFile(roomPath, ".room");

            textureFromFile.name = Path.GetFileName(roomPath);
            RoomFactory.RoomData roomData = RoomFactory.ExtractRoomDataFromFile(roomPath);
            roomData.room = RoomFactory.Build(textureFromFile, roomData);
            return(roomData);
        }
        public static RoomData BuildFromFile(string roomPath)
        {
            var texture = ResourceExtractor.GetTextureFromFile(roomPath, ".room");

            texture.name = Path.GetFileName(roomPath);
            RoomData roomData = ExtractRoomDataFromFile(roomPath);

            roomData.room = Build(texture, roomData);
            return(roomData);
        }
Example #11
0
        /// <summary>
        /// Returns an object with a tk2dSprite component with the
        /// texture of a file in the sprites folder
        /// </summary>
        public static GameObject SpriteFromFile(string spriteName, GameObject obj = null, bool copyFromExisting = true)
        {
            string filename = spriteName.Replace(".png", "");

            var texture = ResourceExtractor.GetTextureFromFile(filename);

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

            return(SpriteFromTexture(texture, spriteName, obj, copyFromExisting));
        }
Example #12
0
        // private static string [] m_AssetBundleNames = new string[] { "shared_auto_001", "shared_auto_002", "brave_resources_001" };
        public static PrototypeDungeonRoom BuildFromResource2(string roomPath, bool setRoomCategory = false, bool autoAssignToFloor = false, bool defineFullPath = false, bool assignDecorationSettings = false)
        {
            string RoomPath = (roomPath);

            if (defineFullPath)
            {
                RoomPath = roomPath;
            }
            Texture2D texture  = ResourceExtractor.GetTextureFromResource(RoomPath);
            RoomData  roomData = ExtractRoomDataFromResource(RoomPath);

            return(Build(texture, roomData, setRoomCategory, autoAssignToFloor, assignDecorationSettings, roomData.weight));
        }
Example #13
0
        /// <summary>
        /// Adds a sprite (from a resource) to a collection
        /// </summary>
        /// <returns>The spriteID of the defintion in the collection</returns>
        public static int AddSpriteToCollection(string resourcePath, tk2dSpriteCollectionData collection)
        {
            string extension = !resourcePath.EndsWith(".png") ? ".png" : "";

            resourcePath += extension;
            var texture = ResourceExtractor.GetTextureFromResource(resourcePath); //Get Texture

            var definition = ConstructDefinition(texture);                        //Generate definition

            definition.name = texture.name;                                       //naming the definition is actually extremely important

            return(AddSpriteToCollection(definition, collection));
        }
Example #14
0
        /// <summary>
        /// Returns an object with a tk2dSprite component with the
        /// texture of an embedded resource
        /// </summary>
        public static GameObject SpriteFromResource(string spriteName, GameObject obj = null, bool copyFromExisting = true)
        {
            string extension    = !spriteName.EndsWith(".png") ? ".png" : "";
            string resourcePath = spriteName + extension;

            var texture = ResourceExtractor.GetTextureFromResource(resourcePath);

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

            return(SpriteFromTexture(texture, resourcePath, obj, copyFromExisting));
        }
        // Token: 0x0600002F RID: 47 RVA: 0x00003694 File Offset: 0x00001894
        public static Texture2D GetTextureFromFile(string fileName, string extension = ".png")
        {
            fileName = fileName.Replace(extension, "");
            string    text = Path.Combine(ResourceExtractor.spritesDirectory, fileName + extension);
            bool      flag = !File.Exists(text);
            Texture2D result;

            if (flag)
            {
                Tools.PrintError <string>(text + " not found.", "FF0000");
                result = null;
            }
            else
            {
                Texture2D texture2D = ResourceExtractor.BytesToTexture(File.ReadAllBytes(text), fileName);
                result = texture2D;
            }
            return(result);
        }
Example #16
0
        public static IEnumerable <RoomData> BuildFromZipFile(string zipFilePath)
        {
            if (!ZipFile.IsZipFile(zipFilePath))
            {
                Tools.Log($"Not a valid zip file!");
                yield break;
            }
            using (var zipFile = ZipFile.Read(zipFilePath))
            {
                //Tools.PrintNoID("did it work?");
                foreach (var entry in zipFile.Entries)
                {
                    var fileName  = Path.GetFileNameWithoutExtension(entry.FileName);
                    var extension = Path.GetExtension(entry.FileName);
                    if (!string.Equals(extension, ".room", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    byte[] zipData;
                    int    capacity = (int)entry.UncompressedSize;
                    if (capacity < 0)
                    {
                        continue;
                    }

                    using (var ms = new MemoryStream(capacity))
                    {
                        entry.Extract(ms);
                        zipData = ms.ToArray();
                    }

                    var texture  = ResourceExtractor.BytesToTexture(zipData, fileName);
                    var roomData = ExtractRoomDataFromBytes(zipData);
                    roomData.room = Build(texture, roomData);

                    yield return(roomData);
                }
            }
        }
Example #17
0
        // Token: 0x0600009A RID: 154 RVA: 0x00008084 File Offset: 0x00006284
        public GameObject Build()
        {
            GameObject result;

            try
            {
                Texture2D  textureFromResource = ResourceExtractor.GetTextureFromResource(this.spritePath);
                GameObject gameObject          = SpriteBuilder.SpriteFromResource(this.spritePath, null);
                string     text = (this.modID + ":" + this.name).ToLower().Replace(" ", "_");
                gameObject.name = text;
                tk2dSprite component = gameObject.GetComponent <tk2dSprite>();
                component.IsPerpendicular = true;
                component.PlaceAtPositionByAnchor(this.offset, tk2dBaseSprite.Anchor.LowerCenter);
                Transform transform = new GameObject("talkpoint").transform;
                transform.position = gameObject.transform.position + this.talkPointOffset;
                transform.SetParent(gameObject.transform);
                bool flag  = !this.usesCustomColliderOffsetAndSize;
                bool flag2 = flag;
                bool flag3 = flag2;
                if (flag3)
                {
                    IntVector2 intVector = new IntVector2(textureFromResource.width, textureFromResource.height);
                    this.colliderOffset = new IntVector2(0, 0);
                    this.colliderSize   = new IntVector2(intVector.x, intVector.y / 2);
                }
                SpeculativeRigidbody speculativeRigidbody = component.SetUpSpeculativeRigidbody(this.colliderOffset, this.colliderSize);
                ShrineFactory.CustomShrineController customShrineController = gameObject.AddComponent <ShrineFactory.CustomShrineController>();
                customShrineController.ID             = text;
                customShrineController.roomStyles     = this.roomStyles;
                customShrineController.isBreachShrine = true;
                customShrineController.offset         = this.offset;
                customShrineController.pixelColliders = speculativeRigidbody.specRigidbody.PixelColliders;
                customShrineController.factory        = this;
                customShrineController.OnAccept       = this.OnAccept;
                customShrineController.OnDecline      = this.OnDecline;
                customShrineController.CanUse         = this.CanUse;
                customShrineController.text           = this.text;
                customShrineController.acceptText     = this.acceptText;
                customShrineController.declineText    = this.declineText;
                bool flag4 = this.interactableComponent == null;
                bool flag5 = flag4;
                bool flag6 = flag5;
                if (flag6)
                {
                    SimpleShrine simpleShrine = gameObject.AddComponent <SimpleShrine>();
                    simpleShrine.isToggle    = this.isToggle;
                    simpleShrine.OnAccept    = this.OnAccept;
                    simpleShrine.OnDecline   = this.OnDecline;
                    simpleShrine.CanUse      = this.CanUse;
                    simpleShrine.text        = this.text;
                    simpleShrine.acceptText  = this.acceptText;
                    simpleShrine.declineText = this.declineText;
                    simpleShrine.talkPoint   = transform;
                }
                else
                {
                    gameObject.AddComponent(this.interactableComponent);
                }
                gameObject.name = text;
                bool flag7 = !this.isBreachShrine;
                bool flag8 = flag7;
                bool flag9 = flag8;
                if (flag9)
                {
                    bool flag10 = !this.room;
                    bool flag11 = flag10;
                    bool flag12 = flag11;
                    if (flag12)
                    {
                        this.room = RoomFactory.CreateEmptyRoom(12, 12);
                    }
                    ShrineFactory.RegisterShrineRoom(gameObject, this.room, text, this.offset, this.RoomWeight);
                }
                ShrineFactory.registeredShrines.Add(text, gameObject);
                FakePrefab.MarkAsFakePrefab(gameObject);
                result = gameObject;
            }
            catch (Exception e)
            {
                Tools.PrintException(e, "FF0000");
                result = null;
            }
            return(result);
        }
Example #18
0
        ///maybe add some value proofing here (name != null, collider != IntVector2.Zero)
        public GameObject Build()
        {
            try
            {
                //Get texture and create sprite
                Texture2D tex    = ResourceExtractor.GetTextureFromResource(spritePath);
                var       shrine = GungeonAPI.SpriteBuilder.SpriteFromResource(spritePath, null, false);

                //Add (hopefully) unique ID to shrine for tracking
                string ID = $"{modID}:{name}".ToLower().Replace(" ", "_");
                shrine.name = ID;

                //Position sprite
                var shrineSprite = shrine.GetComponent <tk2dSprite>();
                shrineSprite.IsPerpendicular = true;
                shrineSprite.PlaceAtPositionByAnchor(offset, tk2dBaseSprite.Anchor.LowerCenter);

                //Add speech bubble origin
                var talkPoint = new GameObject("talkpoint").transform;
                talkPoint.position = shrine.transform.position + talkPointOffset;
                talkPoint.SetParent(shrine.transform);

                //Set up collider
                if (!usesCustomColliderOffsetAndSize)
                {
                    IntVector2 spriteDimensions = new IntVector2(tex.width, tex.height);
                    colliderOffset = new IntVector2(0, 0);
                    colliderSize   = new IntVector2(spriteDimensions.x, spriteDimensions.y / 2);
                }
                var body = ItemAPI.SpriteBuilder.SetUpSpeculativeRigidbody(shrineSprite, colliderOffset, colliderSize);

                //if (!string.IsNullOrEmpty(shadowSpritePath))
                //{
                //    var shadow = ((GameObject)UnityEngine.Object.Instantiate(ResourceCache.Acquire("DefaultShadowSprite"))).GetComponent<tk2dSprite>();
                //    var shadowSprite = ItemAPI.SpriteBuilder.SpriteFromResource(shadowSpritePath, null, false).GetComponent<tk2dSprite>();
                //    Tools.Print($"Shadow material: {shadow.renderer.material.name}");
                //    Tools.Print($"\tShadow color: {shadow.color}");
                //    Tools.Print($"\tShadow material: {shadowSprite.renderer.material.name}");
                //    Tools.Print($"\tShadow color: {shadowSprite.color}");
                //    Tools.ExportTexture(shadow.renderer.material.mainTexture.GetReadable());
                //    //Tools.ExportTexture(shadowSprite.renderer.material.mainTexture.GetReadable());

                //    shrineSprite.AttachRenderer(shadow);
                //    shadow.PlaceAtPositionByAnchor(shrineSprite.WorldBottomCenter, tk2dBaseSprite.Anchor.UpperCenter);
                //    //shadow.color = new Color(1, 1, 1, .5f);
                //    //shadow.HeightOffGround = -0.1f;
                //    //shadow.renderer.material = defaultSprite.renderer.material;
                //    DepthLookupManager.ProcessRenderer(shadow.GetComponent<Renderer>(), DepthLookupManager.GungeonSortingLayer.BACKGROUND);

                //    //Tools.LogPropertiesAndFields(defaultSprite);

                //}

                var data = shrine.AddComponent <CustomShrineController>();
                data.ID             = ID;
                data.roomStyles     = roomStyles;
                data.isBreachShrine = true;
                data.offset         = offset;
                data.pixelColliders = body.specRigidbody.PixelColliders;
                data.factory        = this;
                data.OnAccept       = OnAccept;
                data.OnDecline      = OnDecline;
                data.CanUse         = CanUse;
                data.text           = text;
                data.acceptText     = acceptText;
                data.declineText    = declineText;

                if (interactableComponent == null)
                {
                    var simpInt = shrine.AddComponent <SimpleShrine>();
                    simpInt.isToggle    = this.isToggle;
                    simpInt.OnAccept    = this.OnAccept;
                    simpInt.OnDecline   = this.OnDecline;
                    simpInt.CanUse      = CanUse;
                    simpInt.text        = this.text;
                    simpInt.acceptText  = this.acceptText;
                    simpInt.declineText = this.declineText;
                    simpInt.talkPoint   = talkPoint;
                }
                else
                {
                    shrine.AddComponent(interactableComponent);
                }


                shrine.name = ID;
                if (!isBreachShrine)
                {
                    if (!room)
                    {
                        room = RoomFactory.CreateEmptyRoom();
                    }
                    RegisterShrineRoom(shrine, room, ID, offset);
                }
                registeredShrines.Add(ID, shrine);
                FakePrefab.MarkAsFakePrefab(shrine);
                Tools.Print("Added shrine: " + ID);
                return(shrine);
            }
            catch (Exception e)
            {
                Tools.PrintException(e);
                return(null);
            }
        }
Example #19
0
 public static RoomData ExtractRoomDataFromResource(string path)
 {
     byte[] data = ResourceExtractor.ExtractEmbeddedResource(path);
     return(ExtractRoomDataFromBytes(data));
 }
Example #20
0
        public static RoomData ExtractRoomDataFromBytes(byte[] data)
        {
            string stringData = ResourceExtractor.BytesToString(data);

            return(ExtractRoomData(stringData));
        }
        public static RoomData ExtractRoomDataFromFile(string path)
        {
            string data = ResourceExtractor.BytesToString(File.ReadAllBytes(path));

            return(ExtractRoomData(data));
        }
        public static RoomData ExtractRoomDataFromResource(string path)
        {
            string data = ResourceExtractor.BytesToString(ResourceExtractor.ExtractEmbeddedResource(path));

            return(ExtractRoomData(data));
        }
        // Token: 0x06000017 RID: 23 RVA: 0x00003680 File Offset: 0x00001880
        public GameObject Build()
        {
            GameObject result;

            try
            {
                Texture2D  textureFromResource = ResourceExtractor.GetTextureFromResource(this.spritePath);
                GameObject gameObject          = SpriteBuilder.SpriteFromResource(this.spritePath, null);
                string     text = (this.modID + ":" + this.name).ToLower().Replace(" ", "_");
                //string roomPath = this.roomPath;
                gameObject.name = text;
                tk2dSprite component = gameObject.GetComponent <tk2dSprite>();
                component.IsPerpendicular = true;
                component.PlaceAtPositionByAnchor(this.offset, tk2dBaseSprite.Anchor.LowerCenter);
                Transform transform = new GameObject("talkpoint").transform;
                transform.position = gameObject.transform.position + this.talkPointOffset;
                transform.SetParent(gameObject.transform);
                bool flag  = !this.usesCustomColliderOffsetAndSize;
                bool flag2 = flag;
                if (flag2)
                {
                    IntVector2 intVector = new IntVector2(textureFromResource.width, textureFromResource.height);
                    this.colliderOffset = new IntVector2(0, 0);
                    this.colliderSize   = new IntVector2(intVector.x, intVector.y / 2);
                }
                SpeculativeRigidbody speculativeRigidbody = component.SetUpSpeculativeRigidbody(this.colliderOffset, this.colliderSize);

                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.PlayerBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });
                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.EnemyBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });
                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.BulletBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });
                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.EnemyBulletBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });
                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.BeamBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });

                OldShrineFactory.CustomShrineController customShrineController = gameObject.AddComponent <OldShrineFactory.CustomShrineController>();
                customShrineController.ID             = text;
                customShrineController.roomStyles     = this.roomStyles;
                customShrineController.isBreachShrine = true;
                customShrineController.offset         = this.offset;
                customShrineController.pixelColliders = speculativeRigidbody.specRigidbody.PixelColliders;
                customShrineController.factory        = this;
                customShrineController.OnAccept       = this.OnAccept;
                customShrineController.OnDecline      = this.OnDecline;
                customShrineController.CanUse         = this.CanUse;
                bool flag3 = this.interactableComponent != null;
                bool flag4 = flag3;
                IPlayerInteractable item;
                if (flag4)
                {
                    item = (gameObject.AddComponent(this.interactableComponent) as IPlayerInteractable);
                }
                else
                {
                    SimpleShrine simpleShrine = gameObject.AddComponent <SimpleShrine>();
                    simpleShrine.isToggle    = this.isToggle;
                    simpleShrine.OnAccept    = this.OnAccept;
                    simpleShrine.OnDecline   = this.OnDecline;
                    simpleShrine.CanUse      = this.CanUse;
                    simpleShrine.text        = this.text;
                    simpleShrine.acceptText  = this.acceptText;
                    simpleShrine.declineText = this.declineText;
                    simpleShrine.talkPoint   = transform;
                    item = simpleShrine;
                }
                GameObject gameObject2 = ShrineFakePrefab.Clone(gameObject);
                gameObject2.GetComponent <OldShrineFactory.CustomShrineController>().Copy(customShrineController);
                gameObject2.name = text;
                bool flag5 = this.isBreachShrine;
                bool flag6 = flag5;
                if (flag6)
                {
                    bool flag7 = !RoomHandler.unassignedInteractableObjects.Contains(item);
                    bool flag8 = flag7;
                    if (flag8)
                    {
                        RoomHandler.unassignedInteractableObjects.Add(item);
                    }
                }
                else
                {
                    bool flag9  = !this.room;
                    bool flag10 = flag9;
                    if (flag10)
                    {
                        this.room = RoomFactory.CreateEmptyRoom(12, 12);
                    }
                    OldShrineFactory.RegisterShrineRoom(gameObject2, this.room, text, this.offset, this.RoomWeight);
                }
                OldShrineFactory.builtShrines.Add(text, gameObject2);
                result = gameObject;
            }
            catch (Exception e)
            {
                Tools.PrintException(e, "FF0000");
                result = null;
            }
            return(result);
        }
Example #24
0
        public static void GenerateRoomLayoutFromPNG(PrototypeDungeonRoom room, string filePath, PrototypeRoomPitEntry.PitBorderType PitBorderType = PrototypeRoomPitEntry.PitBorderType.FLAT, CoreDamageTypes DamageCellsType = CoreDamageTypes.None)
        {
            Texture2D m_TextureFromResource = ResourceExtractor.GetTextureFromResource(filePath);

            float DamageToPlayersPerTick = 0;
            float DamageToEnemiesPerTick = 0;
            float TickFrequency          = 0;
            bool  RespectsFlying         = true;
            bool  DamageCellsArePoison   = false;

            if (DamageCellsType == CoreDamageTypes.Fire)
            {
                DamageToPlayersPerTick = 0.5f;
                TickFrequency          = 1;
            }
            else if (DamageCellsType == CoreDamageTypes.Poison)
            {
                DamageCellsArePoison   = true;
                DamageToPlayersPerTick = 0.5f;
                TickFrequency          = 1;
            }

            if (m_TextureFromResource == null)
            {
                ETGModConsole.Log("GenerateRoomFromImage: Error! Requested Texture Resource is Null!");
                return;
            }

            Color WhitePixel      = new Color32(255, 255, 255, 255);    // Wall Cell
            Color PinkPixel       = new Color32(255, 0, 255, 255);      // Diagonal Wall Cell (North East)
            Color YellowPixel     = new Color32(255, 255, 0, 255);      // Diagonal Wall Cell (North West)
            Color HalfPinkPixel   = new Color32(127, 0, 127, 255);      // Diagonal Wall Cell (South East)
            Color HalfYellowPixel = new Color32(127, 127, 0, 255);      // Diagonal Wall Cell (South West)

            Color BluePixel = new Color32(0, 0, 255, 255);              // Floor Cell

            Color BlueHalfGreenPixel = new Color32(0, 127, 255, 255);   // Floor Cell (Ice Override)
            Color HalfBluePixel      = new Color32(0, 0, 127, 255);     // Floor Cell (Water Override)
            Color HalfRedPixel       = new Color32(0, 0, 127, 255);     // Floor Cell (Carpet Override)
            Color GreenHalfRBPixel   = new Color32(127, 255, 127, 255); // Floor Cell (Grass Override)
            Color HalfWhitePixel     = new Color32(127, 127, 127, 255); // Floor Cell (Bone Override)
            Color OrangePixel        = new Color32(255, 127, 0, 255);   // Floor Cell (Flesh Override)
            Color RedHalfGBPixel     = new Color32(255, 127, 127, 255); // Floor Cell (ThickGoop Override)

            Color GreenPixel = new Color32(0, 255, 0, 255);             // Damage Floor Cell

            Color RedPixel = new Color32(255, 0, 0, 255);               // Pit Cell

            int width       = room.Width;
            int height      = room.Height;
            int ArrayLength = (width * height);

            if (m_TextureFromResource.GetPixels32().Length != ArrayLength)
            {
                ETGModConsole.Log("GenerateRoomFromImage: Error! Image resolution doesn't match size of room!");
                return;
            }

            room.FullCellData = new PrototypeDungeonRoomCellData[ArrayLength];
            List <Vector2> m_Pits = new List <Vector2>();

            for (int X = 0; X < width; X++)
            {
                for (int Y = 0; Y < height; Y++)
                {
                    int                          ArrayPosition     = (Y * width + X);
                    Color?                       m_Pixel           = m_TextureFromResource.GetPixel(X, Y);
                    CellType                     cellType          = CellType.FLOOR;
                    DiagonalWallType             diagonalWallType  = DiagonalWallType.NONE;
                    CellVisualData.CellFloorType OverrideFloorType = CellVisualData.CellFloorType.Stone;
                    bool                         isDamageCell      = false;
                    bool                         cellDamagesPlayer = false;
                    if (m_Pixel.HasValue)
                    {
                        if (m_Pixel.Value == WhitePixel | m_Pixel.Value == PinkPixel |
                            m_Pixel.Value == YellowPixel | m_Pixel.Value == HalfPinkPixel |
                            m_Pixel.Value == HalfYellowPixel)
                        {
                            cellType = CellType.WALL;
                            if (m_Pixel.Value == PinkPixel)
                            {
                                diagonalWallType = DiagonalWallType.NORTHEAST;
                            }
                            else if (m_Pixel.Value == YellowPixel)
                            {
                                diagonalWallType = DiagonalWallType.NORTHWEST;
                            }
                            else if (m_Pixel.Value == HalfPinkPixel)
                            {
                                diagonalWallType = DiagonalWallType.SOUTHEAST;
                            }
                            else if (m_Pixel.Value == HalfYellowPixel)
                            {
                                diagonalWallType = DiagonalWallType.SOUTHWEST;
                            }
                        }
                        else if (m_Pixel.Value == RedPixel)
                        {
                            cellType = CellType.PIT;
                            m_Pits.Add(new Vector2(X, Y));
                        }
                        else if (m_Pixel.Value == BluePixel | m_Pixel.Value == GreenPixel |
                                 m_Pixel.Value == BlueHalfGreenPixel | m_Pixel.Value == HalfBluePixel |
                                 m_Pixel.Value == HalfRedPixel | m_Pixel.Value == GreenHalfRBPixel |
                                 m_Pixel.Value == HalfWhitePixel | m_Pixel.Value == OrangePixel |
                                 m_Pixel.Value == RedHalfGBPixel)
                        {
                            cellType = CellType.FLOOR;
                            if (m_Pixel.Value == GreenPixel)
                            {
                                isDamageCell = true;
                                if (DamageCellsType == CoreDamageTypes.Ice)
                                {
                                    cellDamagesPlayer = false;
                                }
                                else
                                {
                                    cellDamagesPlayer = true;
                                }
                            }
                            else if (m_Pixel.Value == BlueHalfGreenPixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Ice;
                            }
                            else if (m_Pixel.Value == HalfBluePixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Water;
                            }
                            else if (m_Pixel.Value == HalfRedPixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Carpet;
                            }
                            else if (m_Pixel.Value == GreenHalfRBPixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Grass;
                            }
                            else if (m_Pixel.Value == HalfWhitePixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Bone;
                            }
                            else if (m_Pixel.Value == OrangePixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Flesh;
                            }
                            else if (m_Pixel.Value == RedHalfGBPixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.ThickGoop;
                            }
                        }
                        else
                        {
                            cellType = CellType.FLOOR;
                        }
                    }
                    else
                    {
                        cellType = CellType.FLOOR;
                    }
                    if (DamageCellsType != CoreDamageTypes.None && isDamageCell)
                    {
                        room.FullCellData[ArrayPosition] = GenerateCellData(cellType, diagonalWallType, cellDamagesPlayer, DamageCellsArePoison, DamageCellsType, DamageToPlayersPerTick, DamageToEnemiesPerTick, TickFrequency, RespectsFlying);
                    }
                    else
                    {
                        room.FullCellData[ArrayPosition] = GenerateCellData(cellType, diagonalWallType, OverrideFloorType: OverrideFloorType);
                    }
                }
            }

            if (m_Pits.Count > 0)
            {
                room.pits = new List <PrototypeRoomPitEntry>()
                {
                    new PrototypeRoomPitEntry(m_Pits)
                    {
                        containedCells = m_Pits,
                        borderType     = PitBorderType
                    }
                };
            }
            room.OnBeforeSerialize();
            room.OnAfterDeserialize();
            room.UpdatePrecalculatedData();
        }
Example #25
0
        ///maybe add some value proofing here (name != null, collider != IntVector2.Zero)
        public GameObject Build()
        {
            try
            {
                //Get texture and create sprite
                Texture2D tex    = ResourceExtractor.GetTextureFromResource(spritePath);
                var       shrine = SpecialItemPack.ItemAPI.SpriteBuilder.SpriteFromResource(spritePath, null, false);

                //Add (hopefully) unique ID to shrine for tracking
                string ID = $"{modID}:{name}".ToLower().Replace(" ", "_");
                shrine.name = ID;

                //Position sprite
                var sprite = shrine.GetComponent <tk2dSprite>();
                sprite.IsPerpendicular = true;
                sprite.PlaceAtPositionByAnchor(offset, tk2dBaseSprite.Anchor.LowerCenter);

                //Add speech bubble origin
                var talkPoint = new GameObject("talkpoint").transform;
                talkPoint.position = shrine.transform.position + talkPointOffset;
                talkPoint.SetParent(shrine.transform);

                //Set up collider
                if (!usesCustomColliderOffsetAndSize)
                {
                    IntVector2 spriteDimensions = new IntVector2(tex.width, tex.height);
                    colliderOffset = new IntVector2(0, 0);
                    colliderSize   = new IntVector2(spriteDimensions.x, spriteDimensions.y / 2);
                }
                var body = ItemAPI.SpriteBuilder.SetUpSpeculativeRigidbody(sprite, colliderOffset, colliderSize);

                var data = shrine.AddComponent <CustomShrineController>();
                data.ID             = ID;
                data.roomStyles     = roomStyles;
                data.isBreachShrine = true;
                data.offset         = offset;
                data.pixelColliders = body.specRigidbody.PixelColliders;
                data.factory        = this;
                data.OnAccept       = OnAccept;
                data.OnDecline      = OnDecline;
                data.CanUse         = CanUse;

                IPlayerInteractable interactable;
                //Register as interactable
                if (interactableComponent != null)
                {
                    interactable = shrine.AddComponent(interactableComponent) as IPlayerInteractable;
                }
                else
                {
                    var simpInt = shrine.AddComponent <SimpleInteractable>();
                    simpInt.isToggle    = this.isToggle;
                    simpInt.OnAccept    = this.OnAccept;
                    simpInt.OnDecline   = this.OnDecline;
                    simpInt.CanUse      = CanUse;
                    simpInt.text        = this.text;
                    simpInt.acceptText  = this.acceptText;
                    simpInt.declineText = this.declineText;
                    simpInt.talkPoint   = talkPoint;
                    interactable        = simpInt as IPlayerInteractable;
                }


                var prefab = FakePrefab.Clone(shrine);
                prefab.GetComponent <CustomShrineController>().Copy(data);
                prefab.name = ID;
                if (isBreachShrine)
                {
                    if (!RoomHandler.unassignedInteractableObjects.Contains(interactable))
                    {
                        RoomHandler.unassignedInteractableObjects.Add(interactable);
                    }
                }
                else
                {
                    if (!room)
                    {
                        room = RoomFactory.CreateEmptyRoom();
                    }
                    RegisterShrineRoom(prefab, room, ID, offset);
                }


                builtShrines.Add(ID, prefab);
                Tools.Print("Added shrine: " + ID);
                return(shrine);
            }
            catch (Exception e)
            {
                Tools.PrintException(e);
                return(null);
            }
        }