コード例 #1
0
        public void TestOptionals()
        {
            TypesStructure before = new TypesStructure();

            before.ReqFloat32 = -1.1f;
            before.ReqFloat64 = -1.1;
            before.ReqInt8 = 12;
            before.ReqInt16 = 0x7fff;
            before.ReqInt32 = -1;
            before.ReqInt64 = 0x7fffffffffffffffL;
            before.ReqDecimal = decimal.MaxValue;
            before.ReqBool = false;
            before.ReqString = "";
            before.ReqBytes = new byte[] { };
            before.ReqEnumeration = TypesEnumeration.A;
            before.ReqStructure = new SmallStructure();
            before.ReqStructure.Test = 0;
            before.ReqListOfEnum.Add(new SmallStructure());

            before.OptFloat32 = 1.234f;
            before.OptFloat64 = 0.001234;
            before.OptInt8 = 123;
            before.OptInt16 = -1;
            before.OptInt32 = -1;
            before.OptInt64 = -1;
            before.OptDecimal = decimal.MaxValue;
            before.OptBool = true;
            before.OptString = "Foo";
            before.OptBytes = new byte[] { 1 };
            before.OptEnumeration = TypesEnumeration.C;
            before.OptStructure = new SmallStructure();
            before.OptStructure.Test = 3;
            before.OptListOfEnum.Add(null);
            before.OptListOfEnum.Add(new SmallStructure());

            byte[] result = Pincher.Encode(before);

            TypesStructure after = Pincher.Decode<TypesStructure>(result);

            AssertTypesStructuresAreEqual(before, after);
        }
コード例 #2
0
        public void TestDynamicDecodingWithTypes()
        {
            DynamicPincher pincher = new DynamicPincher(@"..\..\TestVersion3.pinch");

            TypesStructure sample = new TypesStructure();

            sample.ReqFloat32 = 1.2f;
            sample.ReqFloat64 = 3.4;
            sample.ReqInt8 = 5;
            sample.ReqInt16 = 6;
            sample.ReqInt32 = 7;
            sample.ReqInt64 = 8;
            sample.ReqDecimal = 9.10M;
            sample.ReqBool = true;
            sample.ReqString = "Eleven";
            sample.ReqBytes = new byte[] { 1, 2 };
            sample.ReqEnumeration = TypesEnumeration.B;
            sample.ReqStructure = new SmallStructure();
            sample.ReqStructure.Test = 13;

            SmallStructure firstSmall = new SmallStructure();
            firstSmall.Test = 14;

            SmallStructure secondSmall = new SmallStructure();
            secondSmall.Test = 15;

            sample.ReqListOfEnum.Add(firstSmall);
            sample.ReqListOfEnum.Add(secondSmall);

            byte[] data = Pincher.Encode(sample);

            DynamicStructure structure =
                pincher.Decode("Interlace.Pinch.TestsVersion3.TypesStructure", data);

            string structureText = structure.Dumped;
        }
コード例 #3
0
 void AssertTypesStructuresAreEqual(TypesStructure a, TypesStructure b)
 {
     Assert.AreEqual(a.ReqFloat32, b.ReqFloat32);
     Assert.AreEqual(a.ReqFloat64, b.ReqFloat64);
     Assert.AreEqual(a.ReqInt8, b.ReqInt8);
     Assert.AreEqual(a.ReqInt16, b.ReqInt16);
     Assert.AreEqual(a.ReqInt32, b.ReqInt32);
     Assert.AreEqual(a.ReqInt64, b.ReqInt64);
     Assert.AreEqual(a.ReqBool, b.ReqBool);
     Assert.AreEqual(a.ReqString, b.ReqString);
     ArrayAssert.AreEqual(a.ReqBytes, b.ReqBytes);
     Assert.AreEqual(a.ReqEnumeration, b.ReqEnumeration);
     Assert.AreEqual(a.ReqStructure, b.ReqStructure);
     CollectionAssert.AreEqual(a.ReqListOfEnum, b.ReqListOfEnum);
     Assert.AreEqual(a.OptFloat32, b.OptFloat32);
     Assert.AreEqual(a.OptFloat64, b.OptFloat64);
     Assert.AreEqual(a.OptInt8, b.OptInt8);
     Assert.AreEqual(a.OptInt16, b.OptInt16);
     Assert.AreEqual(a.OptInt32, b.OptInt32);
     Assert.AreEqual(a.OptInt64, b.OptInt64);
     Assert.AreEqual(a.OptBool, b.OptBool);
     Assert.AreEqual(a.OptString, b.OptString);
     CollectionAssert.AreEqual(a.OptBytes, b.OptBytes);
     Assert.AreEqual(a.OptStructure, b.OptStructure);
     CollectionAssert.AreEqual(a.OptListOfEnum, b.OptListOfEnum);
 }
コード例 #4
0
        public void TestSimple()
        {
            TypesStructure before = new TypesStructure();

            before.ReqFloat32 = 1.1f;
            before.ReqFloat64 = 1.1;
            before.ReqInt8 = 12;
            before.ReqInt16 = -1;
            before.ReqInt32 = 0x7fffffff;
            before.ReqInt64 = -1L;
            before.ReqDecimal = 1M;
            before.ReqBool = true;
            before.ReqString = "The quick brown fox.";
            before.ReqBytes = new byte[] { 1, 2, 3 };
            before.ReqEnumeration = TypesEnumeration.B;
            before.ReqStructure = new SmallStructure();
            before.ReqStructure.Test = 2;
            before.ReqListOfEnum.Add(new SmallStructure());

            before.OptFloat32 = null;
            before.OptFloat64 = null;
            before.OptInt8 = null;
            before.OptInt16 = null;
            before.OptInt32 = null;
            before.OptInt64 = null;
            before.OptDecimal = null;
            before.OptBool = null;
            before.OptString = null;
            before.OptBytes = null;
            before.OptEnumeration = null;
            before.OptStructure = null;
            before.OptListOfEnum.Add(null);

            byte[] result = Pincher.Encode(before);

            using (FileStream stream = new FileStream(@"C:\pinchtest.pinch", FileMode.Create))
            {
                Pincher.Encode(before, stream);
            }

            TypesStructure after = Pincher.Decode<TypesStructure>(result);

            AssertTypesStructuresAreEqual(before, after);
        }
コード例 #5
0
ファイル: DataTilesManager.cs プロジェクト: TD6370/TheCell
    public List <DataTile> CreateStructDataTile(string NameStructMap, Rect boundsStruct, TileBase[] allTiles, BoundsInt boundsMap, TypesStructure p_tag)
    {
        int             countFindTiles = 0;
        List <DataTile> listDataTiles  = new List <DataTile>();

        int startX      = (int)boundsStruct.x + Math.Abs(boundsMap.x);
        int startY      = (int)boundsStruct.y + Math.Abs(boundsMap.y);
        int boundsSizeX = startX + (int)boundsStruct.width;
        int boundsSizeY = startY + (int)boundsStruct.height;

        for (int x = startX; x < boundsSizeX; x++)
        {
            for (int y = startY; y < boundsSizeY; y++)
            {
                TileBase tile = allTiles[x + y * boundsMap.size.x];


                if (tile != null)
                {
                    int cellX = x + -startX;
                    int cellY = y + -startY;

                    DataTile dataTiles = new DataTile()
                    {
                        X    = cellX,
                        Y    = cellY,
                        Name = tile.name,
                        Tag  = p_tag.ToString(),
                    };

                    listDataTiles.Add(dataTiles);
                    countFindTiles++;
                }
            }
        }

        return(listDataTiles);
        //m_CollectionDataMapTiles.Add(NameStructMap, listDataTiles);
    }
コード例 #6
0
    public bool AddConstructInGridData(string nameField, DataTile itemTile,
                                       PaletteMapController.SelCheckOptDel p_TypeModeOptStartDelete = PaletteMapController.SelCheckOptDel.None,
                                       PaletteMapController.SelCheckOptDel p_TypeModeOptStartCheck  = PaletteMapController.SelCheckOptDel.None)
    {
        TypePrefabs prefabName        = TypePrefabs.PrefabField;
        string      personTextureName = "";

        if (itemTile == null)
        {
            Debug.Log("####### AddConstructInGridData  itemTile == null");
            return(false);
        }

        //ArgumentException: The requested value 'SpriteBossAlien(Clone)' was not found.

        TypesStructure structType = (TypesStructure)Enum.Parse(typeof(TypesStructure), itemTile.Tag);;

        if (structType == TypesStructure.Terra)
        {
            prefabName = TypePrefabs.PrefabField;
        }
        if (structType == TypesStructure.Person)
        {
            personTextureName = itemTile.Name.ClearClone();
            prefabName        = TypePrefabs.PrefabBoss;
        }
        if (structType == TypesStructure.Prefab)
        {
            //ArgumentException: The requested value 'SpriteBossAlien(Clone)' was not found.
            prefabName = (TypePrefabs)Enum.Parse(typeof(TypePrefabs), itemTile.Name);
        }

        Vector2 posStruct = Helper.GetPositByField(nameField);
        int     x         = (int)posStruct.x;
        int     y         = (int)posStruct.y;
        int     _y        = y * (-1);
        Vector3 pos       = new Vector3(x, _y, 0) * Spacing;

        pos.z = -1;
        if (prefabName == TypePrefabs.PrefabUfo)
        {
            pos.z = -2;
        }

        string nameObject = Helper.CreateName(prefabName.ToString(), nameField, "-1");// prefabName.ToString() + "_" + nameFiled + "_" + i;

        ModelNPC.ObjectData objDataSave = BilderGameDataObjects.BildObjectData(prefabName);
        objDataSave.CreateID(nameObject);
        objDataSave.SetNameObject(nameObject, true);

        if (PoolGameObjects.IsUseTypePoolPrefabs)
        {
            objDataSave.ModelView = itemTile.Name;
        }
        else
        {
            if (structType == TypesStructure.Terra)
            {
                var objTerra = objDataSave as ModelNPC.TerraData;
                if (objTerra == null)
                {
                    Debug.Log("####### AddConstructInGridData: structType is TypesStructure.Terra   objDataSave Not is ModelNPC.TerraData !!!!");
                    return(false);
                }
                objTerra.ModelView = itemTile.Name;
            }
            if (structType == TypesStructure.TerraPrefab)
            {
                var objTerraPrefab = objDataSave as ModelNPC.WallData;
                if (objTerraPrefab == null)
                {
                    Debug.Log("####### AddConstructInGridData: structType is TypesStructure.TerraPrefab   objDataSave Not is ModelNPC.TerraData !!!!");
                    return(false);
                }
                objTerraPrefab.ModelView = itemTile.Name;
            }
        }

        if (structType == TypesStructure.Person)
        {
            var objPerson = objDataSave as ModelNPC.GameDataBoss;
            if (objPerson == null)
            {
                Debug.Log("####### AddConstructInGridData: structType is TypesStructure.Terra   objDataSave Not is ModelNPC.TerraData !!!!");
                return(false);
            }
        }

        bool res = Storage.Data.AddDataObjectInGrid(objDataSave, nameField, "CreateDataGamesObjectsWorld",
                                                    p_TypeModeOptStartDelete, p_TypeModeOptStartCheck);


        objDataSave.SetPosition(pos);
        return(res);
    }