Example #1
0
 public static void WriteBPDataToFile(string filepath, BPData data)
 {
     using (FileStream fs = new FileStream(filepath, File.Exists(filepath)?FileMode.Truncate: FileMode.OpenOrCreate, FileAccess.Write))
         using (BinaryWriter writer = new BinaryWriter(fs))
         {
             WriteBPData(writer, data);
         }
 }
Example #2
0
        public static BPData ReadBPDataFromFile(string filepath)
        {
            BPData data = new BPData();

            using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                using (BinaryReader reader = new BinaryReader(fs))
                {
                    ReadBPData(reader, ref data);
                }
            return(data);
        }
Example #3
0
        public static void WriteBPData(BinaryWriter writer, BPData bpData)
        {
            writer.Write(bpData.version);
            writer.Write(bpData.name);
            writer.Write((byte)bpData.posType);
            WriteEntities(writer, bpData.entities);
            WriteConnects(writer, bpData.connects);

            writer.Write(bpData.latitude);
            writer.Write(bpData.longitude);
            BinaryHelper.WriteVector2(writer, ref bpData.gcsMin);
            BinaryHelper.WriteVector2(writer, ref bpData.gcsMax);
            BinaryHelper.WriteVector3(writer, ref bpData.originalPos);
            writer.Write(bpData.planetRadius);
        }
Example #4
0
        public static void ReadBPData(BinaryReader reader, ref BPData bpData)
        {
            bpData.version  = reader.ReadInt32();
            bpData.name     = reader.ReadString();
            bpData.posType  = (BPData.PosType)reader.ReadByte();
            bpData.entities = new List <BPEntityData>();
            ReadEntities(reader, ref bpData.entities);
            bpData.connects = new List <ConnectData>();
            ReadConnects(reader, ref bpData.connects);

            bpData.latitude  = reader.ReadSingle();
            bpData.longitude = reader.ReadSingle();
            BinaryHelper.TryReadVector2(reader, ref bpData.gcsMin);
            BinaryHelper.TryReadVector2(reader, ref bpData.gcsMax);
            BinaryHelper.TryReadVector3(reader, ref bpData.originalPos);
            bpData.planetRadius = reader.ReadSingle();
        }
Example #5
0
        public void CountBpEntities(BPData data)
        {
            m_BPEntitiesCount.Clear();
            m_EntityInfos.Clear();
            m_EntityIcons.Clear();

            if (data == null)
            {
                return;
            }

            if (data.entities != null && data.entities.Count > 0)
            {
                foreach (var entity in data.entities)
                {
                    if (!m_BPEntitiesCount.ContainsKey(entity.protoId))
                    {
                        m_BPEntitiesCount[entity.protoId] = 0;
                    }
                    m_BPEntitiesCount[entity.protoId] += 1;
                }

                foreach (var iter in m_BPEntitiesCount)
                {
                    ItemProto itemProto = LDB.items.Select(iter.Key);
                    if (itemProto != null)
                    {
                        m_EntityInfos[iter.Key] = string.Format("{0}:{1}", itemProto.name, iter.Value);
                        m_EntityIcons[iter.Key] = itemProto.iconSprite.texture;
                    }
                    else
                    {
                        m_EntityInfos[iter.Key] = string.Format("{0}:{1}", iter.Key, iter.Value);
                    }
                }
            }
        }