Ejemplo n.º 1
0
        public static SmartPtr <T> Read(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
        {
            if (owner == null)
            {
                Log.LogErr("WARNING: SmartPtr created without an owner!");
            }
            int fileID = reader.ReadInt32();

            reader.AlignTo(4);
            Int64 pathID = reader.ReadInt64();

            if (fileID == 0 && pathID == 0)
            {
                return(new SmartPtr <T>());
            }

            var objInfo = assetsFile.GetObjectInfo <T>(fileID, pathID);

            if (objInfo == null)
            {
                Log.LogErr($"WARNING: Could not find objectinfo for creating SmartPtr of type {typeof(T).Name} on owner type {owner?.GetType()?.Name ?? "(null owner)"}!  Returned a null pointer instead.");
                return(null);
            }

            SmartPtr <T> ptr = new SmartPtr <T>(owner, assetsFile.GetObjectInfo <T>(fileID, pathID));

            //TODO: not sure this is only ever called by existing objects
            ptr.IsNew = false;

            return(ptr);
        }
Ejemplo n.º 2
0
 private void Init(AssetsObject owner, IObjectInfo <T> target)
 {
     Target = target ?? throw new NullReferenceException("Target cannot be null");
     Owner  = owner ?? throw new NullReferenceException("Owner cannot be null");
     //TODO: not sure this is only ever called by new objects
     IsNew = true;
     Target.ParentFile.AddPtrRef(this);
     Owner.ObjectInfo.ParentFile.AddPtrRef(this);
 }
Ejemplo n.º 3
0
        public void DeleteObject(AssetsObject assetsObject)
        {
            Log.LogMsg($"Deleting object of type {assetsObject.GetType().Name}");
            //TODO: implement dispose on these or something?
            var obj = Metadata.ObjectInfos.FirstOrDefault(x => x == assetsObject.ObjectInfo);

            if (obj == null)
            {
                Log.LogErr("Tried to delete an object that wasn't part of this file");
                return;
            }

            Metadata.ObjectInfos.Remove(assetsObject.ObjectInfo);
            //TODO: IDs need to be shored up at all?  reflection loop through all objects looking for refs?

            CleanupPtrs(assetsObject.ObjectInfo);
        }
Ejemplo n.º 4
0
            public void Parse(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
            {
                Texture = SmartPtr <Texture2DObject> .Read(assetsFile, owner, reader);

                AlphaTexture = SmartPtr <Texture2DObject> .Read(assetsFile, owner, reader);

                SubMeshes   = reader.ReadArrayOf(r => new Submesh(reader));
                IndexBuffer = reader.ReadArray();
                reader.AlignTo(4);
                VertexData          = new VertexData(reader);
                BindPose            = reader.ReadArrayOf(r => r.ReadSingle());
                TextureRect         = new RectF(reader);
                TextureRectOffset   = new Vector2F(reader);
                AtlasRectOffset     = new Vector2F(reader);
                SettingsRaw         = reader.ReadUInt32();
                UVTransform         = new Vector4F(reader);
                DownscaleMultiplier = reader.ReadSingle();
            }
Ejemplo n.º 5
0
        public void AddObject(AssetsObject assetsObject, bool assignNextObjectID = true)
        {
            if (assetsObject.ObjectInfo == null)
            {
                throw new ArgumentException("ObjectInfo must be set!");
            }

            if (assignNextObjectID)
            {
                assetsObject.ObjectInfo.ObjectID = GetNextObjectID();
            }
            if (assetsObject.ObjectInfo.ObjectID < 1)
            {
                throw new ArgumentException("ObjectInfo.ObjectID must be > 0.");
            }
            if (Metadata.ObjectInfos.Exists(x => x.ObjectID == assetsObject.ObjectInfo.ObjectID))
            {
                throw new ArgumentException("ObjectInfo.ObjectID already exists in this file.");
            }

            Metadata.ObjectInfos.Add(assetsObject.ObjectInfo);
        }
Ejemplo n.º 6
0
 public SpriteRenderData(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
 {
     Parse(assetsFile, owner, reader);
 }
Ejemplo n.º 7
0
 private void Parse(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
 {
     PreloadIndex = reader.ReadInt32();
     PreloadSize  = reader.ReadInt32();
     Asset        = SmartPtr <AssetsObject> .Read(assetsFile, owner, reader);
 }
Ejemplo n.º 8
0
 public AssetInfo(AssetsFile assetsFile, AssetsObject owner, AssetsReader reader)
 {
     Parse(assetsFile, owner, reader);
 }
Ejemplo n.º 9
0
 public SmartPtr(AssetsObject owner, IObjectInfo <T> target)
 {
     Init(owner, target);
 }
Ejemplo n.º 10
0
 public SmartPtr(AssetsObject owner, T target)
 {
     Init(owner, (IObjectInfo <T>)target.ObjectInfo);
 }