package speiger.src.coreengine.assets.oldImpl;

import java.io.Closeable;
import java.util.List;

import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.base.IAsset;
import speiger.src.coreengine.assets.base.IAssetPackage;

public abstract class BaseAsset implements IAsset {
	protected AssetLocation location;
	protected IAssetPackage owner;
	protected List<Closeable> closeable = new ObjectArrayList<>();
	
	public BaseAsset(AssetLocation location, IAssetPackage owner) {
		this.location = location;
		this.owner = owner;
	}
	
	@Override
	public void close() {
		for(Closeable close : closeable) {
			try { close.close(); }
			catch(Exception e) { e.printStackTrace(); }
		}
		closeable.clear();
	}
	
	protected <T extends Closeable> T markClosed(T value) {
		closeable.add(value);
		return value;
	}
	
	@Override
	public AssetLocation location() {
		return location;
	}
	
	@Override
	public IAssetPackage owner() {
		return owner;
	}
}
