Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        _rooms = new List <RoomData>();

        using (SnapshotImporter importer = new SnapshotImporter(snapshotFile))
        {
            int offset = 45056;

            for (int i = 0; i < 20; i++)
            {
                importer.Seek(offset);

                ImportRoom(importer, IsSpecialRoom(i));

                offset += 1024;
            }

            importer.Seek(33280); // 33280-33535 - sprites for Miner Willy
            for (int i = 0; i < 8; i++)
            {
                byte[] sprite = importer.ReadBytes(32);
                _sprites.Add(sprite);
            }
        }

        IsReady = true;
    }
Exemple #2
0
        public static async Task ImportArchetypeDecks()
        {
            //construct Progress<T>, passing ReportProgress as the Action<T>
            var progressIndicator = new Progress <Tuple <int, int> >(ReportProgress);

            try
            {
                // TODO: Get back to the IArchetypeImporter interface?
                var importer = new SnapshotImporter(new TrackerRepository());
                var count    = await importer.ImportDecks(
                    Settings.Default.AutoArchiveArchetypes,
                    Settings.Default.DeletePreviouslyImported,
                    Settings.Default.ShortenDeckNames,
                    progressIndicator);

                // Refresh decklist
                Core.MainWindow.LoadAndUpdateDecks();
                Notify("Import complete", $"{count} decks imported", 10);
            }
            catch (Exception e)
            {
                Log.Error(e);
                Notify("Import failed", e.Message, 15, "error");
            }
        }
Exemple #3
0
    void Start()
    {
        _rooms = new List <RoomData>();

        using (SnapshotImporter importer = new SnapshotImporter(snapshotFile))
        {
            int offset = 45056;

            for (int i = 0; i < 20; i++)
            {
                // Move to the offset
                importer.Seek(offset);

                // Import Room
                ImportRoom(importer, IsSpecialRoom(i));

                // Move to the next room
                offset += 1024;
            }

            importer.Seek(33280);
            for (int i = 0; i < 8; i++)
            {
                byte[] sprite = importer.ReadBytes(32);
                _sprites.Add(sprite);
            }
        }

        IsReady = true;
    }
        public void GetSnapshot_Error()
        {
            var mock = new Mock <IHttpClient>();

            mock.Setup(x => x.JsonGet(It.IsAny <string>()))
            .ReturnsAsync(@"{""error"":{""status"":500}}");
            var importer = new SnapshotImporter(mock.Object, _data.Object, _log.Object);

            Assert.That(async() => await importer.GetSnapshot(new Tuple <string, string>("standard", "2016-09-10")),
                        Throws.TypeOf <ImportException>()
                        .With.Message.EqualTo("Getting the snapshot failed (500)"));
        }
        public void GetSnapshot()
        {
            var mock = new Mock <IHttpClient>();

            mock.Setup(x => x.JsonGet(It.IsAny <string>()))
            .ReturnsAsync(@"{""title"":""Salt for all""}");
            var importer = new SnapshotImporter(mock.Object, _data.Object, _log.Object);

            var result = importer.GetSnapshot(new Tuple <string, string>("standard", "2016-09-10")).Result;

            Assert.That(result.Title, Is.EqualTo("Salt for all"));
        }
        public void GetSnapshotSlug()
        {
            var mock = new Mock <IHttpClient>();

            mock.Setup(x => x.JsonGet(It.IsAny <string>()))
            .ReturnsAsync(@"{""snapshotType"":""standard"",""slugs"":[{""slug"":""2016-07-10""}]}");

            var importer = new SnapshotImporter(mock.Object, _data.Object, _log.Object);

            Assert.That(async() => await importer.GetSnapshotSlug("standard"),
                        Is.EqualTo(new Tuple <string, string>("2016-07-10", "standard")));
        }
Exemple #7
0
        public void GetSnapshotTest()
        {
            //var mock = new Mock<IHttpClient>();
            //mock.Setup(x => x.JsonGet(It.IsAny<string>())).ReturnsAsync(@"{""title"":""Salt for all""}");
            var httpClient        = new HttpClient();
            var trackerRepository = new TrackerRepository();
            var importer          = new SnapshotImporter(httpClient, trackerRepository);

            var result = importer.GetSnapshot(new Tuple <string, string>("standard", "2016-09-10")).Result;

            Assert.AreEqual("Salt for all", result.Title);
        }
        public void GetSnapshotSlug_Unexpected()
        {
            var mock = new Mock <IHttpClient>();

            mock.Setup(x => x.JsonGet(It.IsAny <string>()))
            .ReturnsAsync(@"{""snapshotType"":""standard"",""slugs"":[{""slug"":""2016-07-10""},{""slug"":""2016-06-10""}]}");

            var importer = new SnapshotImporter(mock.Object, _data.Object, _log.Object);

            Assert.That(async() => await importer.GetSnapshotSlug("standard"),
                        Throws.TypeOf <ImportException>()
                        .With.Message.EqualTo("Snapshot slug count greater than one"));
        }
Exemple #9
0
        public void GetSnapshotSlug_Error()
        {
            var mock = new Mock <IHttpClient>();

            mock.Setup(x => x.JsonGet(It.IsAny <string>()))
            .ReturnsAsync(@"{""error"":{""status"":500}}");

            var importer = new SnapshotImporter(mock.Object, null);

            Assert.That(async() => await importer.GetSnapshotSlug(),
                        Throws.TypeOf <ImportException>()
                        .With.Message.EqualTo("Getting the snapshot slug failed (500)"));
        }
Exemple #10
0
 public static void DeleteArchetypeDecks()
 {
     try
     {
         var importer = new SnapshotImporter(new TrackerRepository());
         var count    = importer.DeleteDecks();
         // Refresh decklist
         Core.MainWindow.LoadAndUpdateDecks();
         Notify("Deletion complete", $"{count} decks deleted", 10);
     }
     catch (Exception e)
     {
         Log.Error(e);
         Notify("Deletion failed", e.Message, 15, "error");
     }
 }
Exemple #11
0
        public void ImportDecksTest()
        {
            var httpClient        = new HttpClient();
            var trackerRepository = new TrackerRepository();
            var importer          = new SnapshotImporter(httpClient, trackerRepository);

            //_logger.Info("Starting meta deck import");
            int deckCount = 0;
            // delete previous snapshot decks
            //if (deletePrevious)
            //{
            //    _logger.Info("Deleting previous meta decks");
            //    _tracker.DeleteAllDecksWithTag(PluginTag);
            //}
            // get the lastest meta snapshot slug/date
            var slug = importer.GetSnapshotSlug();
            // use the slug to request the actual snapshot details
            //var snapshot = await GetSnapshot(slug);
            // add all decks to the tracker
            //foreach (var dt in snapshot.DeckTiers)
            //{
            //    var cards = "";
            //    _logger.Info($"Importing deck ({dt.Name})");
            //    foreach (var cd in dt.Deck.Cards)
            //    {
            //        cards += cd.Detail.Name;
            //        // don't add count if only one
            //        if (cd.Quantity > 1)
            //            cards += $" x {cd.Quantity}";
            //        cards += "\n";
            //    }
            //    // remove trailing newline
            //    if (cards.Length > 1)
            //        cards = cards.Substring(0, cards.Length - 1);

            //    // optionally remove player class from deck name
            //    // e.g. 'Control Warrior' => 'Control'
            //    var deckName = dt.Name;
            //    if (removeClass)
            //        deckName = deckName.Replace(dt.Deck.PlayerClass, "").Trim();

            //    _tracker.AddDeck(deckName, dt.Deck.PlayerClass, cards, archive, ArchetypeTag, PluginTag);
            //    deckCount++;
        }
        public static async Task ImportMetaDecks()
        {
            try
            {
                IArchetypeImporter importer =
                    new SnapshotImporter(new HttpClient(), new TrackerRepository());
                var count = await importer.ImportDecks(
                    Settings.Default.AutoArchiveArchetypes,
                    Settings.Default.DeletePreviouslyImported,
                    Settings.Default.RemoveClassFromName);

                Notify("Import Complete", $"{count} decks imported", 10);
            }
            catch (Exception e)
            {
                Log.Error(e);
                Notify("Import Failed", e.Message, 15, "error", null);
            }
        }
Exemple #13
0
    void ImportRoom(SnapshotImporter importer, bool hasSpecialGraphic)
    {
        RoomData data = new RoomData();

        // Read in the screen attributes
        byte[] buf = importer.ReadBytes(512);
        int    i   = 0;

        //string s = "";

        for (int y = 0; y < 16; y++)
        {
            for (int x = 0; x < 32; x++)
            {
                //s += " " + buf[i];
                data.Attributes[i] = buf[i];
                i++;
            }
            //s += "\r\n";
        }

        //print(s);

        // Read in the room name
        data.RoomName = importer.ReadString(32);

        // Read in the block graphics
        for (i = 0; i < 8; i++)
        {
            // Read in the first byte that represents the attribute
            byte   attr      = importer.Read();
            byte[] blockData = importer.ReadBytes(8);
            data.Blocks[attr] = new BlockData(blockData, (BlockType)i);
        }

        // Read Miner Willy's start position

        // TODO: Read 1 byte for y-offset
        importer.Read();
        // TODO: Read 1 byte for sprite willy starts at
        importer.Read();
        // TODO: Read 1 byte for direction facing
        importer.Read();
        // TODO: Read 1 byte, should always be 0
        importer.Read();

        short     rawMWPos = importer.ReadShort();
        CellPoint startPos = new CellPoint(rawMWPos.GetX(), rawMWPos.GetY());

        data.MinerWillyStart = startPos;
        importer.Read(); // Should always be zero??

        // TODO: Conveyor belt (4 bytes for the conveyor belt)
        data.ConveyorDirection = (ConveyorDirection)importer.Read();
        importer.ReadBytes(3);

        data.BorderColour = importer.Read();

        bool addKey = true;

        for (var j = 0; j < 5; j++)
        {
            byte attr = importer.Read();
            //if (attr == 255) addKey = false;
            //if (attr == 0) addKey = false;

            byte      secondGfxBuf = importer.Read();
            short     keyPosRaw    = importer.ReadShort();
            CellPoint keyPos       = new CellPoint(keyPosRaw.GetX(), keyPosRaw.GetY());

            // read dummy byte
            int dummy = importer.Read();

            if (addKey)
            {
                data.RoomKeys.Add(new RoomKey(attr, keyPos));
            }

            addKey = true;
        }

        /*
         * Offset 628 is set at 0 in all Manic Miner rooms. Its counterpart in the runtime work area
         * (see Appendix F) "is used to decide whether or not all the items have yet been collected;
         * just before the items are displayed it is set to zero, then when an uncollected item is
         * displayed, it is changed to the attribute of that item. Thus, after printing items, if
         * this byte is still zero then all items must have been collected." [Garry Lancaster]
         *
         *  Offset 654 is always set at 255.
         */
        byte d1 = importer.Read();
        byte d2 = importer.Read();

        // PORTAL
        byte portalColour = importer.Read();

        byte[] portalShape = importer.ReadBytes(32);

        short portalPosRaw = importer.ReadShort();

        importer.ReadShort(); // Bit of a fudge, because we're gonna ignore the SECOND short...

        data.AddPortal(portalColour, portalShape, portalPosRaw.GetX(), portalPosRaw.GetY());

        data.KeyShape = importer.ReadBytes(8);

        byte airFirst  = importer.Read();
        byte airSize   = (byte)((airFirst - 32) - 4);
        byte airPixels = importer.Read();

        data.AirSupply = new AirSupply()
        {
            Length = airSize, Tip = airPixels
        };

        // Horizontal guardians
        for (int h = 0; h < 4; h++)
        {
            // TODO: Check this logic because we are getting black areas top left

            HorizontalGuardian hg = new HorizontalGuardian();
            hg.Attribute = importer.Read();
            var pos = importer.ReadShort();
            hg.StartX = pos.GetX();
            hg.StartY = pos.GetY();
            importer.Read(); // ignore this byte
            hg.StartFrame = importer.Read();
            hg.Left       = importer.Read() & 0x1f;
            hg.Right      = importer.Read() & 0x1f;

            if (hg.Attribute != 255)
            {
                data.HorizontalGuardians.Add(hg);
            }
        }

        importer.ReadBytes(3); // Always 255, and 0 and 0 Offset 730 is a terminator which is always set at 255, and Offsets 731 and 732 are 0 for all Manic Miner rooms.

        if (hasSpecialGraphic)
        {
            importer.ReadBytes(3); // ignore offsets 733, 734 and 736

            byte[] specialGraphic = importer.ReadBytes(32);
            data.SpecialGraphics.Add(specialGraphic);
        }
        else
        {
            // TODO: Vertical guardians
            for (int h = 0; h < 4; h++)
            {
                HorizontalGuardian hg = new HorizontalGuardian();
                hg.Attribute = importer.Read();
                var pos = importer.ReadShort();
                hg.StartX = pos.GetX();
                hg.StartY = pos.GetY();
                importer.Read(); // ignore this byte
                hg.StartFrame = importer.Read();
                hg.Left       = importer.Read() & 0x1f;
                hg.Right      = importer.Read() & 0x1f;

                if (hg.Attribute != 0)
                {
                    // TODO: NEED TO ADD TO VERTICAL GUARDIANS
                    //data.HorizontalGuardians.Add(hg);
                }
            }
        }

        for (int sp = 0; sp < 8; sp++)
        {
            byte[] shape = importer.ReadBytes(32);
            data.GuardianGraphics.Add(shape);
        }

        _rooms.Add(data);
    }
Exemple #14
0
    void ImportRoom(SnapshotImporter importer, bool hasSpecialGraphics)
    {
        //throw new NotImplementedException();

        RoomData data = new RoomData();

        /*
         * for(int y=0; y<16; y++)
         * {
         *  for(int x=0; x<32; x++)
         *  {
         *      data.SetAttr(x, y, importer.Read());
         *  }
         * }
         */

        byte[] buf = importer.ReadBytes(512);
        int    ii  = 0;

        for (int y = 0; y < 16; y++)
        {
            for (int x = 0; x < 32; x++)
            {
                //data.SetAttr(x, y, buf[i]);
                data.Attributes[ii] = buf[ii];
                ii++;
            }
        }

        data.RoomName = importer.ReadString(32);

        for (int i = 0; i < 8; i++)
        {
            byte attr = importer.Read();

            ////SpriteTexture tex = new SpriteTexture(8, 8, Vector2.zero);
            //SpriteTexture tex = new SpriteTexture(8, 8, new Vector2(0,1));
            //tex.Clear(new Color(0,0,0,0));
            //for(int y=0; y<8; y++)
            //{
            //    tex.SetLine(y, importer.Read());
            //}

            //data.Blocks[attr] = tex.Apply();

            byte[] blockData = importer.ReadBytes(8);
            data.Blocks[attr] = new BlockData(blockData, (BlockType)i);

            // for debug only

            /*
             * GameObject go = new GameObject();
             * go.transform.position = new Vector3(i*8, _rooms.Count*8, 0);
             * var sr = go.AddComponent<SpriteRenderer>();
             * sr.sprite = data.Blocks[attr];
             */
            // /for debug only
        }

        importer.Read(); // y-offset
        importer.Read(); // starts at
        importer.Read(); // direction facing
        importer.Read(); // always 0

        // start position
        short     startPos = importer.ReadShort();
        CellPoint pos      = new CellPoint(startPos.GetX(), startPos.GetY());

        data.StartPoint = pos;

        importer.Read(); // always 0 ???

        //importer.ReadBytes(4); // (623-626) conveyor belt
        data.ConveyorDirection = (ConveyorDirection)importer.Read();
        importer.ReadBytes(3);

        data.BorderColour = importer.Read(); // border color

        // positions of the items (keys)
        bool addKey = true;

        for (int j = 0; j < 5; j++)
        {
            addKey = true; // reset value (set default)

            byte attr = importer.Read();
            //if (attr == 255) continue;
            //if (attr == 0) continue;
            //if (attr == 255) addKey = false;
            //if (attr == 0) addKey = false;

            byte      secondGfxBuf = importer.Read();
            short     keyPosRaw    = importer.ReadShort();
            CellPoint keyPos       = new CellPoint(keyPosRaw.GetX(), keyPosRaw.GetY());

            importer.Read(); // dummy byte

            if (addKey)
            {
                data.RoomKeys.Add(new RoomKey(attr, keyPos));
            }
        }

        importer.Read(); // dummy
        importer.Read(); // dummy always =255

        // PORTAL
        byte portalColour = importer.Read();               // 655

        byte[] portalShape       = importer.ReadBytes(32); // 656-687 (=687-656+1)
        short  portalPositionRaw = importer.ReadShort();   // 688-691

        importer.ReadShort();                              // skip short
        data.AddPortal(portalColour, portalShape, portalPositionRaw.GetX(), portalPositionRaw.GetY());
        // /PORTAL

        data.KeyShape = importer.ReadBytes(8); // ITEMS (keys) shape

        byte airFirst = importer.Read();
        byte airSize  = (byte)(airFirst - 32 - 4);
        byte airPixel = importer.Read();

        data.AirSupply = new AirSupply()
        {
            Length = airSize, Tip = airPixel
        };

        // GUARDIANS
        // horizontal guardians(offset 702-732)
        for (int i = 0; i < 4; i++)
        {
            // todo: check black square in room 1
            GuardianHorizontal gh = new GuardianHorizontal();
            gh.Attribute = importer.Read();
            var pos_tmp = importer.ReadShort();
            gh.StartX = pos_tmp.GetX();
            gh.StartY = pos_tmp.GetY();
            //gh.StartPoint = new CellPoint(pos_tmp.GetX(), pos_tmp.GetY());
            importer.Read(); // ignore
            gh.StartFrame = importer.Read();
            gh.Left       = importer.Read() & 0x1f;
            gh.Right      = importer.Read() & 0x1f;

            if (gh.Attribute != 255)
            {
                data.HorizontalGuardians.Add(gh);
            }
        }

        importer.ReadBytes(3); // offset 730 - 255, 731-0, 732-0

        if (hasSpecialGraphics)
        {
            importer.ReadBytes(3); // ignore offset 733, 734, 735

            // SPECIAL GRAPHICS (offset 736-767)
            byte[] specialGraphic = importer.ReadBytes(32);
            data.SpecialGraphics.Add(specialGraphic);
            // /SPECIAL GRAPHICS
        }
        else
        {
            // vertical guardians(offset 702-732)
            for (int i = 0; i < 4; i++)
            {
                GuardianHorizontal gh = new GuardianHorizontal();
                gh.Attribute = importer.Read();
                var pos_tmp = importer.ReadShort();
                gh.StartX = pos_tmp.GetX();
                gh.StartY = pos_tmp.GetY();
                //gh.StartPoint = new CellPoint(pos_tmp.GetX(), pos_tmp.GetY());
                importer.Read(); // ignore
                gh.StartFrame = importer.Read();
                gh.Left       = importer.Read() & 0x1f;
                gh.Right      = importer.Read() & 0x1f;

                if (gh.Attribute != 255)
                {
                    //data.VerticalGuardians.Add(gh);
                }
            }
        }
        // /GUARDIANS

        // GUARDIAN GRAPHICS (offset 768-1023)
        for (int i = 0; i < 8; i++)
        {
            byte[] shape = importer.ReadBytes(32);
            data.GuardianGraphics.Add(shape);
        }
        // /GUARDIAN GRAPHICS


        _rooms.Add(data);
    }