public void TestLogErrorCmdHardCodedValues()
        {
            Cel.ClearLog();
            CelesteScript script = RunScript("ScriptCommands\\Output\\LogErrorCmd\\TestLogErrorCmdHardCodedValues.cel");

            Assert.IsTrue(CelesteStack.GlobalScope.VariableExists("logError"));

            string errorString = "Error in script ScriptCommands\\Output\\LogErrorCmd\\TestLogErrorCmdHardCodedValues.cel";

            // This should definitely exist!
            using (StreamReader reader = Cel.LogReader)
            {
                Assert.AreEqual(errorString, reader.ReadLine());
                Assert.AreEqual("hello", reader.ReadLine());

                Assert.AreEqual(errorString, reader.ReadLine());
                Assert.AreEqual("True", reader.ReadLine());

                Assert.AreEqual(errorString, reader.ReadLine());
                Assert.AreEqual("1", reader.ReadLine());

                Assert.AreEqual(errorString, reader.ReadLine());
                Assert.AreEqual("-1", reader.ReadLine());
            }
        }
        public void TestLogWarningCmdVariables()
        {
            Cel.ClearLog();
            CelesteScript script = RunScript("ScriptCommands\\Output\\LogWarningCmd\\TestLogWarningCmdVariables.cel");

            Assert.IsTrue(CelesteStack.GlobalScope.VariableExists("logWarning"));

            string warningString = "Warning in script ScriptCommands\\Output\\LogWarningCmd\\TestLogWarningCmdVariables.cel";

            // This should definitely exist!
            using (StreamReader reader = Cel.LogReader)
            {
                Assert.AreEqual(warningString, reader.ReadLine());
                Assert.AreEqual("hello", reader.ReadLine());

                Assert.AreEqual(warningString, reader.ReadLine());
                Assert.AreEqual("True", reader.ReadLine());

                Assert.AreEqual(warningString, reader.ReadLine());
                Assert.AreEqual("10", reader.ReadLine());

                Assert.AreEqual(warningString, reader.ReadLine());
                Assert.AreEqual("-10", reader.ReadLine());

                Assert.AreEqual(warningString, reader.ReadLine());
                Assert.AreEqual("reference", reader.ReadLine());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Applies a Cel's pixels to the Frame, using its Layer's BlendMode & Alpha
        /// </summary>
        private void CelToFrame(Frame frame, Cel cel)
        {
            var opacity = (byte)((cel.Alpha * cel.Layer.Alpha) * 255);
            var pxLen   = frame.Bitmap.Pixels.Length;

            var blend = BlendModes[0];

            if (cel.Layer.BlendMode < BlendModes.Length)
            {
                blend = BlendModes[cel.Layer.BlendMode];
            }

            for (int sx = Math.Max(0, -cel.X), right = Math.Min(cel.Width, frame.Sprite.Width - cel.X); sx < right; sx++)
            {
                int dx = cel.X + sx;
                int dy = cel.Y * frame.Sprite.Width;

                for (int sy = Math.Max(0, -cel.Y), bottom = Math.Min(cel.Height, frame.Sprite.Height - cel.Y); sy < bottom; sy++, dy += frame.Sprite.Width)
                {
                    if (dx + dy >= 0 && dx + dy < pxLen)
                    {
                        blend(ref frame.Bitmap.Pixels[dx + dy], cel.Pixels[sx + sy * cel.Width], opacity);
                    }
                }
            }
        }
Beispiel #4
0
        public static bool ComputeWeightedCenter(this Cel cel, out Vector2 v)
        {
            var center     = Vector2.zero;
            var pixelCount = 0;

            for (var y = 0; y < cel.Height; ++y)
            {
                for (var x = 0; x < cel.Width; ++x)
                {
                    // tex coords relative to full texture boundaries
                    var texX = cel.X + x;
                    var texY = cel.Y + y;

                    var col = cel.GetPixel(x, y);
                    if (col.a > 0f)
                    {
                        center     += new Vector2(texX, texY);
                        pixelCount += 1;
                    }
                }
            }

            if (pixelCount > 0)
            {
                center /= pixelCount;
                v       = center;
                return(true);
            }

            v = default(Vector2);
            return(false);
        }
Beispiel #5
0
        public void GetTreeView(TreeNodeCollection nodes, UniverseSearchData searchData)
        {
            TreeNodeCollection clustNodes;

            if (searchData.Clusters)
            {
                nodes.Add(ClusterName, ClusterName);
                nodes[ClusterName].Tag = this;
                clustNodes             = nodes[ClusterName].Nodes;
            }
            else
            {
                clustNodes = nodes;
            }

            foreach (RegionData region in Regions)
            {
                region.GetTreeView(clustNodes, searchData);
            }

            foreach (SectorData sector in Sectors)
            {
                sector.GetTreeView(clustNodes, searchData);
            }

            foreach (CelestialbodyData Cel in Celestialbodys)
            {
                Cel.GetTreeView(clustNodes, searchData);
            }

            foreach (HighwayData highway in Highways)
            {
                highway.GetTreeView(clustNodes, searchData);
            }
        }
        /// <summary>
        /// Runs and returns the script at the inputted file path
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        protected CelesteScript RunScript(string filePath)
        {
            CelesteScript script = Cel.CreateScript(filePath);

            script.Compile();
            script.Run();

            return(script);
        }
Beispiel #7
0
        public Choice(String paragraf, int number, Vector2 position, Cel destination)
        {
            cel           = destination;
            this.text     = number.ToString() + ". ";
            text         += GetText(paragraf);
            this.position = position;
            Vector2 size = font.MeasureString(text);

            this.rectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y * 3 / 4);
        }
Beispiel #8
0
        //Transformacja
        public Choice(Choice wzorzec, int number, Vector2 position)
        {
            this.enable   = wzorzec.enable;
            this.cel      = wzorzec.cel;
            this.text     = number.ToString() + ". ";
            text         += wzorzec.text;
            this.position = position;
            Vector2 size = font.MeasureString(text);

            this.rectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y * 3 / 4);
        }
Beispiel #9
0
        protected override void Usuń()
        {
            Cel?.RemoveAt(IndeksDocelowy);

            if (Źródło != null)
            {
                Klocek.Rodzic = Źródło.KlocekPionowyZZawartością;

                Źródło.Insert(IndeksŹródłowy, Klocek);
            }
        }
Beispiel #10
0
        protected override void Dodaj()
        {
            Źródło?.RemoveAt(IndeksŹródłowy);

            if (Cel != null)
            {
                Klocek.Rodzic = Cel.KlocekPionowyZZawartością;

                Cel.Insert(IndeksDocelowy, Klocek);
            }
        }
Beispiel #11
0
        public void TestCelesteLoggingTestWriting()
        {
            // Reset the log
            Cel.ClearLog();
            Cel.LogOutputFilePath = Cel.ScriptDirectoryPath + "\\Log.txt";

            using (StreamWriter writer = Cel.LogWriter)
            {
                writer.WriteLine("test logging");
            }
        }
Beispiel #12
0
 //Mniejsza wersja
 public Choice(String paragraf, Cel destination, bool enable = true, bool directText = false)
 {
     this.enable = enable;
     cel         = destination;
     if (!directText)
     {
         text = GetText(paragraf);
     }
     else
     {
         text = paragraf;
     }
 }
Beispiel #13
0
        public void TestCelesteLoggingTestOverwriting()
        {
            // Reset the log
            Cel.ClearLog();
            Cel.LogOutputFilePath = Cel.ScriptDirectoryPath + "\\Log.txt";

            using (StreamWriter writer = Cel.LogWriter)
            {
                writer.WriteLine("test logging");
                writer.WriteLine(true);
                writer.WriteLine(10);
            }

            Cel.ClearLog();

            using (StreamReader reader = Cel.LogReader)
            {
                Assert.AreEqual(null, reader.ReadLine());
            }
        }
Beispiel #14
0
        public static IntRect GetBoundingBox(this Cel cel)
        {
            var minx = int.MaxValue;
            var miny = int.MaxValue;
            var maxx = int.MinValue;
            var maxy = int.MinValue;

            for (var y = 0; y < cel.Height; ++y)
            {
                for (var x = 0; x < cel.Width; ++x)
                {
                    var texX = cel.X + x;
                    var texY = cel.Y + y;
                    var col  = cel.GetPixel(texX, texY);
                    if (col.a > 0f)
                    {
                        minx = Mathf.Min(minx, texX);
                        miny = Mathf.Min(miny, texY);
                        maxx = Mathf.Max(maxx, texX);
                        maxy = Mathf.Max(maxy, texY);
                    }
                }
            }

            if (maxx == int.MinValue)
            {
                return(new IntRect());
            }

            /*
             * var texCenter = new Vector2((maxx + minx) / 2.0f, (maxy + miny) / 2.0f);
             * var texSize = new Vector2(maxx - minx, maxy - miny);
             *
             * var pivotInFrame = Vector2.Scale(ctx.ImportContext.Settings.PivotRelativePos, new Vector2(file.Width, file.Height));
             * var posWorld = (texCenter - pivotInFrame) / ctx.ImportContext.Settings.PixelsPerUnit;
             * var sizeWorld = texSize / ctx.ImportContext.Settings.PixelsPerUnit;
             *
             * return new Rect(posWorld, sizeWorld);
             */
            return(new IntRect(minx, miny, maxx - minx, maxy - miny));
        }
Beispiel #15
0
        public void GetParagraph(String text, String image, List <Choice> choices, Cel actual)
        {
            this.actual = actual;
            lastLine    = startPos;
            this.tekst  = WrapInitialText(text);
            if (image != "")
            {
                GetImage(image);
            }
            else
            {
                isImage = false;
            }
            float space = Choice.Font.MeasureString("I").Y * 1.5F * Game1.Skala.X;

            this.wybory = new List <Choice>();
            foreach (Choice wybor in choices)
            {
                wybory.Add(new Choice(wybor, wybory.Count() + 1, lastLine));
                lastLine.Y += space;
            }
        }
Beispiel #16
0
        public void rysujCel(int x, int y)
        {
            Cel cel = new Cel(x, y, Size);

            grid.Children.Add(cel.Rect);
        }
Beispiel #17
0
        private void Parse(Stream stream)
        {
            var reader = new BinaryReader(stream);

            // wrote these to match the documentation names so it's easier (for me, anyway) to parse
            byte BYTE() => reader.ReadByte();
            ushort WORD() => reader.ReadUInt16();
            short SHORT() => reader.ReadInt16();
            uint DWORD() => reader.ReadUInt32();
            long LONG() => reader.ReadInt32();
            string STRING() => Encoding.UTF8.GetString(BYTES(WORD()));

            byte[] BYTES(int number) => reader.ReadBytes(number);
            void SEEK(int number) => reader.BaseStream.Position += number;

            // Header
            {
                // file size
                DWORD();

                // Magic number (0xA5E0)
                var magic = WORD();
                if (magic != 0xA5E0)
                {
                    throw new Exception("File is not in .ase format");
                }

                // Frames / Width / Height / Color Mode
                frameCount = WORD();
                Width      = WORD();
                Height     = WORD();
                Mode       = (Modes)(WORD() / 8);

                // Other Info, Ignored
                DWORD();       // Flags
                WORD();        // Speed (deprecated)
                DWORD();       // Set be 0
                DWORD();       // Set be 0
                BYTE();        // Palette entry
                SEEK(3);       // Ignore these bytes
                WORD();        // Number of colors (0 means 256 for old sprites)
                BYTE();        // Pixel width
                BYTE();        // Pixel height
                SEEK(92);      // For Future
            }

            // temporary variables
            var       temp    = new byte[Width * Height * (int)Mode];
            var       palette = new Color[256];
            IUserData?last    = null;

            // Frames
            for (int i = 0; i < frameCount; i++)
            {
                var frame = new Frame(this);
                Frames.Add(frame);

                long frameStart, frameEnd;
                int  chunkCount;

                // frame header
                {
                    frameStart = reader.BaseStream.Position;
                    frameEnd   = frameStart + DWORD();
                    WORD();                  // Magic number (always 0xF1FA)
                    chunkCount     = WORD(); // Number of "chunks" in this frame
                    frame.Duration = WORD(); // Frame duration (in milliseconds)
                    SEEK(6);                 // For future (set to zero)
                }

                // chunks
                for (int j = 0; j < chunkCount; j++)
                {
                    long   chunkStart, chunkEnd;
                    Chunks chunkType;

                    // chunk header
                    {
                        chunkStart = reader.BaseStream.Position;
                        chunkEnd   = chunkStart + DWORD();
                        chunkType  = (Chunks)WORD();
                    }

                    // LAYER CHUNK
                    if (chunkType == Chunks.Layer)
                    {
                        // create layer
                        var layer = new Layer();

                        // get layer data
                        layer.Flag       = (Layer.Flags)WORD();
                        layer.Type       = (Layer.Types)WORD();
                        layer.ChildLevel = WORD();
                        WORD(); // width (unused)
                        WORD(); // height (unused)
                        layer.BlendMode = WORD();
                        layer.Alpha     = (BYTE() / 255f);
                        SEEK(3); // for future
                        layer.Name = STRING();

                        last = layer;
                        Layers.Add(layer);
                    }
                    // CEL CHUNK
                    else if (chunkType == Chunks.Cel)
                    {
                        var layer   = Layers[WORD()];
                        var x       = SHORT();
                        var y       = SHORT();
                        var alpha   = BYTE() / 255f;
                        var celType = WORD();
                        var width   = 0;
                        var height  = 0;
                        Color[]? pixels = null;
                        Cel?link = null;

                        SEEK(7);

                        // RAW or DEFLATE
                        if (celType == 0 || celType == 2)
                        {
                            width  = WORD();
                            height = WORD();

                            var count = width * height * (int)Mode;
                            if (count > temp.Length)
                            {
                                temp = new byte[count];
                            }

                            // RAW
                            if (celType == 0)
                            {
                                reader.Read(temp, 0, width * height * (int)Mode);
                            }
                            // DEFLATE
                            else
                            {
                                SEEK(2);

                                using var deflate = new DeflateStream(reader.BaseStream, CompressionMode.Decompress, true);
                                deflate.Read(temp, 0, count);
                            }

                            // get pixel data
                            pixels = new Color[width * height];
                            BytesToPixels(temp, pixels, Mode, palette);
                        }
                        // REFERENCE
                        else if (celType == 1)
                        {
                            var linkFrame = Frames[WORD()];
                            var linkCel   = linkFrame.Cels[frame.Cels.Count];

                            width  = linkCel.Width;
                            height = linkCel.Height;
                            pixels = linkCel.Pixels;
                            link   = linkCel;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }

                        var cel = new Cel(layer, pixels)
                        {
                            X      = x,
                            Y      = y,
                            Width  = width,
                            Height = height,
                            Alpha  = alpha,
                            Link   = link
                        };

                        // draw to frame if visible
                        if (cel.Layer.Visible)
                        {
                            CelToFrame(frame, cel);
                        }

                        last = cel;
                        frame.Cels.Add(cel);
                    }
                    // PALETTE CHUNK
                    else if (chunkType == Chunks.Palette)
                    {
                        var size  = DWORD();
                        var start = DWORD();
                        var end   = DWORD();
                        SEEK(8); // for future

                        for (int p = 0; p < (end - start) + 1; p++)
                        {
                            var hasName = WORD();
                            palette[start + p] = new Color(BYTE(), BYTE(), BYTE(), BYTE()).Premultiply();

                            if (Calc.IsBitSet(hasName, 0))
                            {
                                STRING();
                            }
                        }
                    }
                    // USERDATA
                    else if (chunkType == Chunks.UserData)
                    {
                        if (last != null)
                        {
                            var flags = (int)DWORD();

                            // has text
                            if (Calc.IsBitSet(flags, 0))
                            {
                                last.UserDataText = STRING();
                            }

                            // has color
                            if (Calc.IsBitSet(flags, 1))
                            {
                                last.UserDataColor = new Color(BYTE(), BYTE(), BYTE(), BYTE()).Premultiply();
                            }
                        }
                    }
                    // TAG
                    else if (chunkType == Chunks.FrameTags)
                    {
                        var count = WORD();
                        SEEK(8);

                        for (int t = 0; t < count; t++)
                        {
                            var tag = new Tag();
                            tag.From          = WORD();
                            tag.To            = WORD();
                            tag.LoopDirection = (Tag.LoopDirections)BYTE();
                            SEEK(8);
                            tag.Color = new Color(BYTE(), BYTE(), BYTE(), (byte)255).Premultiply();
                            SEEK(1);
                            tag.Name = STRING();
                            Tags.Add(tag);
                        }
                    }
                    // SLICE
                    else if (chunkType == Chunks.Slice)
                    {
                        var count = DWORD();
                        var flags = (int)DWORD();
                        DWORD(); // reserved
                        var name = STRING();

                        for (int s = 0; s < count; s++)
                        {
                            var slice = new Slice
                            {
                                Name    = name,
                                Frame   = (int)DWORD(),
                                OriginX = (int)LONG(),
                                OriginY = (int)LONG(),
                                Width   = (int)DWORD(),
                                Height  = (int)DWORD()
                            };

                            // 9 slice (ignored atm)
                            if (Calc.IsBitSet(flags, 0))
                            {
                                LONG();
                                LONG();
                                DWORD();
                                DWORD();
                            }

                            // pivot point
                            if (Calc.IsBitSet(flags, 1))
                            {
                                slice.Pivot = new Point2((int)DWORD(), (int)DWORD());
                            }

                            last = slice;
                            Slices.Add(slice);
                        }
                    }

                    reader.BaseStream.Position = chunkEnd;
                }

                reader.BaseStream.Position = frameEnd;
            }
        }
Beispiel #18
0
        public static AnimationFrame DeserializeAnimationFrame(this AnimationDeserializeContext context)
        {
            var animationFrame = new AnimationFrame();

            animationFrame.delay         = context.br.ReadInt32();
            animationFrame.positionDelta = context.br.ReadPosition();
            animationFrame.shadowOffset  = context.br.ReadPosition();

            animationFrame.SnapToGround = context.br.ReadBoolean();

            int layersCount = context.br.ReadInt32();

            if (layersCount > 0)
            {
                Cel currentCel;
                animationFrame.firstLayer = currentCel = new Cel(context);
                for (var i = 1; i < layersCount; i++)
                {
                    currentCel.next = new Cel(context);
                    currentCel      = currentCel.next;
                }
            }

            if (context.Version >= 39)
            {
                animationFrame.masks = context.DeserializeOrderedDictionary(() => new Mask(context));
                animationFrame.outgoingAttachments = context.DeserializeOrderedDictionary(() => new OutgoingAttachment(context));
            }
            else
            {
                //
                // Masks:
                {
                    var legacy = context.DeserializeTagLookup(() => new Mask(context));
                    animationFrame.masks = new OrderedDictionary <string, Mask>();
                    foreach (var mask in legacy)
                    {
                        Debug.Assert(mask.Key.Count < 2, "we don't support multi-tags yet");
                        animationFrame.masks.Add(mask.Key.ToString(), mask.Value);
                    }
                }

                //
                // Outgoing Attachments:
                {
                    var legacy = context.DeserializeTagLookup(() => new OutgoingAttachment(context));
                    animationFrame.outgoingAttachments = new OrderedDictionary <string, OutgoingAttachment>();
                    foreach (var outgoingAttachment in legacy)
                    {
                        Debug.Assert(outgoingAttachment.Key.Count < 2, "we don't support multi-tags yet");
                        animationFrame.outgoingAttachments.Add(outgoingAttachment.Key.ToString(),
                                                               outgoingAttachment.Value);
                    }
                }
            }

            animationFrame.incomingAttachments = context.DeserializeTagLookup(() => context.br.ReadPosition());

            int triggerCount = context.br.ReadInt32();

            if (triggerCount > 0)
            {
                animationFrame.triggers = new List <string>(triggerCount);
                for (var i = 0; i < triggerCount; i++)
                {
                    animationFrame.triggers.Add(context.br.ReadString());
                }
            }

            animationFrame.attachAtLayer = context.br.ReadInt32();
            animationFrame.canDrawLayersAboveSortedAttachees = context.br.ReadBoolean();

            animationFrame.cue = context.br.ReadNullableString();

            return(animationFrame);
        }