Exemple #1
0
        public bool TestSuffixValueOf(int expected, string fmt, string str)
        {
            int value = new Suffix(fmt).ValueOf(str);

            Console.WriteLine("Expected: " + expected + ", Actual: " + value);
            return(value == expected);
        }
Exemple #2
0
        public bool TestSuffixGenerate(string expected, string fmt, int num)
        {
            string output = new Suffix(fmt).Generate(num);

            Console.WriteLine("Expected: " + expected + ", Actual: " + output);
            return(output == expected);
        }
Exemple #3
0
        protected void saveButtonHandler(object sender, EventArgs e)
        {
            string path = _folderText.Text;

            if (path[path.Length - 1] != '\\')
            {
                path += '\\';
            }

            string name = _nameBox.Text;

            if (_appendBtn.Checked)
            {
                name += _appendBox.Text + _wnd.ExportExtension;

                string[] fileList = Directory.GetFiles(path);
                for (int i = 0; i < fileList.Length; i++)
                {
                    fileList[i] = Path.GetFileName(fileList[i]);
                }

                try {
                    var   suff       = new Suffix(name);
                    int[] exportList = suff.ListOfValues(fileList);

                    int nextNum = 0;
                    if (exportList != null)
                    {
                        nextNum = exportList[exportList.Length - 1] + 1;
                    }

                    name = suff.Generate(nextNum);
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                name += _wnd.ExportExtension;
            }

            string fullPath = path + name;

            _wnd.Export(fullPath, (int)_scaleBox.Value);

            string abrvName;

            if (path.Length >= 10)
            {
                abrvName = path.Substring(0, 7) + "...\\" + name;
            }
            else
            {
                abrvName = fullPath;
            }

            _saveMsg.Text = "Saved " + abrvName;
        }
Exemple #4
0
        void newSuffix(object sender, EventArgs e)
        {
            bool success = true;

            try {
                _suff = new Suffix(_main.Text);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                success = false;
            }

            _value.Enabled  = success;
            _string.Enabled = success;
        }
Exemple #5
0
        static void Main()
        {
            Console.Write("Number Tile Generator\nSuffix Format:\n> ");

            Suffix suffix;

            try {
                string sufStr = Console.ReadLine();
                suffix = new Suffix(sufStr);
                if (!suffix.HasInsert)
                {
                    throw new ArgumentException("\"" + sufStr + "\" does not contain an insert");
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                return;
            }

            Console.Write("Number of tiles:\n> ");
            int nTiles = 0;

            try {
                nTiles = Convert.ToInt32(Console.ReadLine());
                if (nTiles <= 0)
                {
                    throw new ArgumentException("The number of tiles must be positive");
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                return;
            }

            Console.Write("Output folder:\n> ");
            string dir = Console.ReadLine();

            if (dir[dir.Length - 1] != '\\')
            {
                dir += "\\";
            }

            new Characters().Generate(suffix, dir, nTiles);
        }
Exemple #6
0
        public void Generate(Suffix suff, string path, int count)
        {
            var img = new Bitmap(suff.Digits * 8 * Scale, 8 * Scale);

            using (var g = Graphics.FromImage(img))
            {
                g.InterpolationMode = InterpolationMode.NearestNeighbor;
                g.PixelOffsetMode   = PixelOffsetMode.Half;

                for (int i = 0; i < count; i++)
                {
                    string name = suff.Generate(i);
                    ProduceImage(g, suff, i);
                    img.Save(path + name);
                }
            }
        }
Exemple #7
0
        void ProduceImage(Graphics g, Suffix suff, int num)
        {
            var tiles = new int[suff.Digits];
            int n     = num;

            for (int i = 0; i < suff.Digits; i++)
            {
                tiles[suff.Digits - i - 1] = n % suff.Base;
                n /= suff.Base;
            }

            int rowLen = suff.Digits;

            rowLen += (4 - (suff.Digits % 4)) % 4;
            int pixSize = rowLen * 8;

            var bmp = new byte[bmpHeader.Length + pixSize];

            Buffer.BlockCopy(bmpHeader, 0, bmp, 0, bmpHeader.Length);

            Embed(bmp, bmp.Length, 2);
            Embed(bmp, suff.Digits * 8, 18);
            Embed(bmp, pixSize, 34);

            for (int i = 7; i >= 0; i--)
            {
                int idxBmp = bmpHeader.Length + i * rowLen;
                for (int j = 0; j < suff.Digits; j++)
                {
                    bmp[idxBmp + j] = Characters.tileset[tiles[j] * 8 + 7 - i];
                }
            }

            using (var ms = new MemoryStream(bmp))
            {
                using (var img = new Bitmap(ms))
                    g.DrawImage(img, 0, 0, suff.Digits * 8 * Scale, 8 * Scale);
            }
        }
Exemple #8
0
        public void Run()
        {
            ViewResults("NativeToRGBA", TestNativeToRGBA(0xFF00FFFF, 0xFC1F));
            ViewResults("RGBAToNative", TestRGBAToNative(0x83FF, 0x00FFFFFF));
            ViewResults("RGBAToNative", TestRGBAToNative(0xFC1F, 0xFF00FFFF));
            ViewResults("RGBAToNative", TestRGBAToNative(0xFFE0, 0xFFFF00FF));
            ViewResults("RGBAToNative", TestRGBAToNative(0x7FFF, 0xFFFFFF00));

            ViewResults("CreateSuffix (trailing '{')", TestException("ArgumentException", () => { var suff = new Suffix("_{{d2"); }));
            ViewResults("CreateSuffix (too short)", TestException("ArgumentException", () => { var suff = new Suffix("-{d}"); }));
            ViewResults("CreateSuffix (base type)", TestException("ArgumentException", () => { var suff = new Suffix("-{l}"); }));
            ViewResults("CreateSuffix (nDigits < 1)", TestException("ArgumentException", () => { var suff = new Suffix("_{d0}"); }));

            ViewResults("SuffixGenerate (num is -ve)", TestException("ArgumentException", () => { var str = new Suffix("_{d2}").Generate(-10); }));
            ViewResults("SuffixGenerate (num exceeds limit)", TestException("ArgumentException", () => { var str = new Suffix("_{b3}").Generate(10); }));

            ViewResults("SuffixGenerate", TestSuffixGenerate("number 090 here", "number {d3} here", 90));
            ViewResults("SuffixGenerate", TestSuffixGenerate("_0f4", "_{x3}", 244));
            ViewResults("SuffixGenerate", TestSuffixGenerate("_0F4", "_{X3}", 244));

            ViewResults("SuffixValueOf (no insert)", TestException("InvalidOperationException", () => { var num = new Suffix("nothing here").ValueOf("nothing here"); }));
            ViewResults("SuffixValueOf (incorrect size 1)", TestException("ArgumentException", () => { var num = new Suffix("{d2} cc").ValueOf("not correct"); }));
            ViewResults("SuffixValueOf (incorrect size 2)", TestException("ArgumentException", () => { var num = new Suffix("aa {d2} cc").ValueOf("not correct"); }));
            ViewResults("SuffixValueOf (incorrect size 3)", TestException("ArgumentException", () => { var num = new Suffix("aa {d2}").ValueOf("not correct"); }));
            ViewResults("SuffixValueOf (invalid input 1)", TestException("ArgumentException", () => { var num = new Suffix("{d2} cc").ValueOf("00 cd"); }));
            ViewResults("SuffixValueOf (invalid input 2)", TestException("ArgumentException", () => { var num = new Suffix("aa {d2} cc").ValueOf("aa 00 cd"); }));
            ViewResults("SuffixValueOf (invalid input 3)", TestException("ArgumentException", () => { var num = new Suffix("aa {d2} cc").ValueOf("ab 00 cc"); }));
            ViewResults("SuffixValueOf (invalid input 4)", TestException("ArgumentException", () => { var num = new Suffix("aa {d2}").ValueOf("ab 00"); }));
            ViewResults("SuffixValueOf (invalid input 4)", TestException("ArgumentOutOfRangeException", () => { var num = new Suffix("aa {d2}").ValueOf("aa 0-"); }));
            ViewResults("SuffixValueOf (oob digit)", TestException("ArgumentOutOfRangeException", () => { var num = new Suffix("aa {o2}").ValueOf("aa 09"); }));

            ViewResults("SuffixValueOf", TestSuffixValueOf(345, "the number is: {b10}", "the number is: 0101011001"));
            ViewResults("SuffixValueOf", TestSuffixValueOf(987, "{o4} is the number", "1733 is the number"));
            ViewResults("SuffixValueOf", TestSuffixValueOf(90, "number {d3} here", "number 090 here"));
            ViewResults("SuffixValueOf", TestSuffixValueOf(244, "_{x3}", "_0f4"));
            ViewResults("SuffixValueOf", TestSuffixValueOf(244, "_{X3}", "_0F4"));

            Console.WriteLine("\nTests Passed: " + nSuccesses + "/" + nTests);
        }
Exemple #9
0
        void process(object sender, EventArgs e)
        {
            this.Output = "";

            string path = _folderText.Text + "\\";

            string[] fileList = Directory.GetFiles(path);
            string   msg      = fileList[0] + "\n";

            int    nFiles = 0;
            string plural = "";

            for (int i = 0; i < fileList.Length; i++)
            {
                fileList[i] = Path.GetFileName(fileList[i]);
            }

            try {
                Suffix src = new Suffix(_srcField.Text);
                Suffix dst = new Suffix(_dstField.Text);
                if (!src.HasInsert || !dst.HasInsert)
                {
                    throw new ArgumentException("Both suffix inputs must contain an insert (eg. {d2})");
                }

                int[] values = src.ListOfValues(fileList);
                if (values == null)
                {
                    throw new ArgumentException("No files matching \"" + _srcField.Text + "\" were found");
                }

                nFiles = values.Length;
                plural = nFiles != 1 ? "s" : "";

                Action <int> rename = (idx) =>
                {
                    string outName = dst.Generate(values[idx]);
                    string srcFile = path + fileList[idx];
                    string dstFile = path + outName;

                    if (!File.Exists(srcFile))
                    {
                        return;
                    }

                    if (File.Exists(dstFile))
                    {
                        if (outName.ToLower() != src.Generate(values[idx]).ToLower())
                        {
                            throw new InvalidOperationException("i cant code :)");
                        }
                        else
                        {
                            return;
                        }
                    }

                    File.Move(srcFile, dstFile);
                };

                for (int i = 0; i < nFiles; i++)
                {
                    // This ensures that there aren't any rename conflicts,
                    //  where the destination file has the same name as the source file,
                    //  yet does not refer to the same number
                    int idx = src.Base > dst.Base ? nFiles - i - 1 : i;
                    rename(idx);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                return;
            }

            this.Output = "Successfully renamed " + nFiles + " file" + plural;
        }