예제 #1
0
        /// <summary>
        /// Removes the item in the specified tile from the game, and updates the indexes.
        /// </summary>
        private static void RemoveItem(Tile tile, int dimension)
        {
            int     itemID = tile.Item.ItemID;
            Point2D l      = tile.Location;
            Chunk   chunk  = World.Data.World.GetChunkByTile(dimension, l.X, l.Y);

            if (chunk.Items.ContainsKey(itemID))
            {
                RTree.RTree <Point2D> result = chunk.Items[itemID];
                bool success = result.Delete(new RTree.Rectangle(l.X, l.Y, l.X, l.Y), new Point2D(l.X, l.Y));

                if (!success)
                {
                    throw new RegistryDeletionException("Failed to delete an item!");
                }

                if (result.Count == 0)
                {
                    RTree.RTree <Point2D> chunksContaining = ItemRegistry.Registries[dimension].ItemIDToChunk[itemID];
                    bool succeed = chunksContaining.Delete(new RTree.Rectangle(chunk.ChunkLocation.X, chunk.ChunkLocation.Y, chunk.ChunkLocation.X, chunk.ChunkLocation.Y), new Point2D(chunk.ChunkLocation.X, chunk.ChunkLocation.Y));

                    if (!succeed)
                    {
                        throw new RegistryDeletionException("Failed to delete a chunk containing an item!");
                    }
                }
                tile.Item = null;
            }
        }
예제 #2
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Open the map file.
         */
        public void Open()
        {
            if (Header != null)
            {
                return;
            }

            Header       = new Header(_reader, 0, 0);
            _recordIndex = new RecordIndex(_reader, Header.IndexOffset,
                                           Header.IndexLength);
            _stringIndex = new StringIndex(_reader, Header.StringIndexOffset,
                                           Header.StringIndexLength);
            _stringData = new StringData(_reader, Header.StringDataOffset,
                                         Header.StringDataLength);
            _geoData = new GeoData(_reader, Header.GeoDataOffset,
                                   Header.GeoDataLength);
            TabularData = new TabularData(_reader, Header.TabularDataOffset,
                                          Header.TabularDataLength, Header.Fields,
                                          _stringData, _stringIndex);
            _rtreeIndex = new RTreeIndex(_reader, Header.RtreeIndexOffset,
                                         Header.RtreeIndexLength);
            _tree = new RTree.RTree(_rtreeIndex.File);
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            savePath    = tbSavePath.Text.Trim();
            jsonVersion = tbJsonVersion.Text.Trim();
            shift       = Int32.Parse(tbShift.Text.Trim());
            subImageNum = Int32.Parse(this.tbSubImageNum.Text.Trim());
            basePath    = System.IO.Path.GetDirectoryName(tbPath.Text);
            if (Directory.Exists(savePath))
            {
                DeleteADirectory(savePath);
            }
            System.IO.Directory.CreateDirectory(savePath);

            //读取文件内容
            StreamReader sr = new StreamReader(tbPath.Text, System.Text.Encoding.Default);

            json = sr.ReadToEnd().TrimStart();
            sr.Close();

            JObject finaljObject = new JObject();
            JObject onlyAssets   = new JObject();
            //string json = "{\"orderId\":\"000001\",\"goodsId[0]\":\"001\",\"goodsId[3]\":\"003\",\"goodsId[10]\":\"new data\"}";
            JObject jsonObj = (JsonConvert.DeserializeObject(json) as JObject)["assets"] as JObject;

            finaljObject.Add(new JProperty("tags", (JsonConvert.DeserializeObject(json) as JObject)["tags"]));
            foreach (var p in jsonObj.Properties().ToArray())
            {
                string   id  = p.Name;
                OneAsset one = JsonConvert.DeserializeObject <OneAsset>(p.Value.ToString());
                if (one.state == 0)
                {
                    LogHelper.WriteLog(one.name + " 未查看,直接跳过截图");
                    continue;
                }

                #region 这里读取图片进行等分
                //等分数量
                //int subImageNum = Int32.Parse(this.tbSubImageNum.Text.Trim());
                //得到原图的宽高
                int subWidth, subHeight;
                //srcHeight = 2056;    ////获取原图宽、高  
                //srcWidth = 2456;
                subWidth  = one.size.width / subImageNum + shift;
                subHeight = one.size.height / subImageNum + shift;
                if (!crop(Path.Combine(basePath, HttpUtility.UrlDecode(one.name)), subWidth, subHeight, subImageNum))
                {
                    continue;
                }
                #endregion

                #region
                //所有缺陷框
                RTree.RTree <Region> tree = new RTree.RTree <Region>();
                if (one.state == 2)//这里需要操作素材打的框
                {
                    #region 这里写单个的区块的素材操作了
                    string oneJsonFile = Path.Combine(basePath, id + "-asset.json");
                    using (StreamReader srTemp = new StreamReader(oneJsonFile, System.Text.Encoding.Default))
                    {
                        OneAssetWithRegions oneAR = JsonConvert.DeserializeObject <OneAssetWithRegions>(srTemp.ReadToEnd().TrimStart());

                        #region 重头戏来了,这里处理完救赎
                        foreach (var f**k in oneAR.regions)
                        {
                            tree.Add(new RTree.Rectangle(f**k.boundingBox.left,
                                                         f**k.boundingBox.top,
                                                         f**k.boundingBox.left,
                                                         f**k.boundingBox.top,
                                                         0, 0), f**k);
                        }
                        #endregion
                    }
                    #endregion
                }
                #endregion
                string oldName = one.name;
                #region 这里做一些逻辑判断
                for (int n = 1; n <= subImageNum * subImageNum; n++)
                {
                    one.id   = id + n;
                    one.size = new AssetsSize()
                    {
                        width = subWidth, height = subHeight
                    };                                                                    // 这里其实写不写无所谓,但追求完美还是写!!!!注意如果下次还要等分,这里还是写完整
                    one.name = Path.GetFileNameWithoutExtension(oldName) + "-" + n + Path.GetExtension(oldName);
                    one.path = "file:${path}" + one.name;

                    if (tree.Count > 0)
                    {
                        //判断所有的边框是否存在在裁剪后的边框内
                        F**k f**k    = cropRRectangles[n - 1];
                        var  objects = tree.Contains(f**k.rectangle);
                        if (objects.Count > 0)//有边框那么,改状态,还要生成本地json文件
                        {
                            one.state = 2;
                            OneAssetWithRegions fuckOne = new OneAssetWithRegions();
                            fuckOne.asset   = one;
                            fuckOne.version = jsonVersion;

                            foreach (var re in objects)
                            {
                                re.boundingBox = new BoundingBox()
                                {
                                    left   = re.boundingBox.left - f**k.point.X,
                                    top    = re.boundingBox.top - f**k.point.Y,
                                    width  = re.boundingBox.width,
                                    height = re.boundingBox.height
                                };
                                re.points.Clear();
                                re.points.Add(new AssetPoint()
                                {
                                    x = re.boundingBox.left, y = re.boundingBox.top
                                });
                                re.points.Add(new AssetPoint()
                                {
                                    x = re.boundingBox.left + re.boundingBox.width, y = re.boundingBox.top
                                });
                                re.points.Add(new AssetPoint()
                                {
                                    x = re.boundingBox.left + re.boundingBox.width, y = re.boundingBox.top + re.boundingBox.height
                                });
                                re.points.Add(new AssetPoint()
                                {
                                    x = re.boundingBox.left, y = re.boundingBox.top + re.boundingBox.height
                                });
                            }

                            fuckOne.regions = objects;
                            File.WriteAllText(Path.Combine(savePath, id + n + "-asset.json"), JsonConvert.SerializeObject(fuckOne));
                            onlyAssets.Add(new JProperty(one.id, JObject.Parse(JsonConvert.SerializeObject(one))));
                            LogHelper.WriteLog("ng " + HttpUtility.UrlDecode(one.name));
                        }
                        else//没有那么
                        {
                            one.state = 1;
                            if (cbSaveOk.Checked)
                            {
                                onlyAssets.Add(new JProperty(one.id, JObject.Parse(JsonConvert.SerializeObject(one))));
                            }
                            LogHelper.WriteLog("ok " + HttpUtility.UrlDecode(one.name));
                        }
                    }
                    //if (one.state == 1)//这里不用判断素材框, 直接草他个等分数的平方
                    //{

                    //}
                    //else


                    //#region 这里处理完了就可以知道 图片等分出来的区块的state,然后新建个-asset.json,然后再吧assets新增
                    ////one.state = 2;

                    //#endregion
                }
                #endregion
                //写入一个字符串
                int o = 0;
            }
            finaljObject.Add(new JProperty("assets", onlyAssets));
            string bb = finaljObject.ToString();
            File.WriteAllText(Path.Combine(savePath, "import.power-ai"), bb);

            MessageBox.Show("处理完成");


            //            ////////给原图分块
            //            for (int j = 0; j < subImageNum; j++)

            //            {
            //                for (int i = 0; i < subImageNum; i++)
            //                {
            //                    if (j < subImageNum - 1 && i < subImageNum - 1)
            //                    {
            //                        cv::Mat temImage(subHeight, subWidth, CV_8UC3, cv::Scalar(0,0,0));
            //            cv::Mat imageROI = src(cv::Rect(i * subWidth, j * subHeight, temImage.cols, temImage.rows));
            //            cv::addWeighted(temImage, 1.0, imageROI, 1.0, 0., temImage);
            //            subImages.push_back(temImage);
            //        }else{                
            //                cv::Mat temImage(srcHeight - (subImageNum - 1) * subHeight, srcWidth - (subImageNum - 1) * subWidth, CV_8UC3, cv::Scalar(0,0,0));
            //                cv::Mat imageROI = src(cv::Rect(i * subWidth, j * subHeight, temImage.cols, temImage.rows));
            //        cv::addWeighted(temImage, 1.0, imageROI, 1.0, 0., temImage);
            //                subImages.push_back(temImage);                
            //            }
            //}
            //std::cout<<subImages[0]<<std::endl;   //测试语句,打印出子图矩阵
        }
예제 #4
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Open the map file.
         */
        public void Open()
        {
            if (Header != null)
            {
                return;
            }

            Header = new Header(_reader, 0, 0);
            _recordIndex = new RecordIndex(_reader, Header.IndexOffset,
                    Header.IndexLength);
            _stringIndex = new StringIndex(_reader, Header.StringIndexOffset,
                    Header.StringIndexLength);
            _stringData = new StringData(_reader, Header.StringDataOffset,
                    Header.StringDataLength);
            _geoData = new GeoData(_reader, Header.GeoDataOffset,
                    Header.GeoDataLength);
            TabularData = new TabularData(_reader, Header.TabularDataOffset,
                    Header.TabularDataLength, Header.Fields,
                    _stringData, _stringIndex);
            _rtreeIndex = new RTreeIndex(_reader, Header.RtreeIndexOffset,
                    Header.RtreeIndexLength);
            _tree = new RTree.RTree(_rtreeIndex.File);
        }