package de.siphalor.was.assets;

import org.jetbrains.annotations.NotNull;

import java.io.InputStream;
import java.net.URL;
import java.util.Optional;

/**
 * This class controls the game's assets. Assets are all the file in the assets package in the jar. It can mostly be safely assumed that the certain asset files exist.
 */
public class AssetsManager {

	/**
	 * Returns a new InputStream to the requested asset.
	 * @param path The path beginning from the <code>assets</code> package
	 * @return An optional with the input stream if the asset exists
	 */
	@NotNull
	public static Optional<InputStream> getStream(@NotNull String path) {
		return Optional.ofNullable(Thread.currentThread().getContextClassLoader().getResourceAsStream("assets/" + path));
	}

	/**
	 * Returns an URL to the requested asset.
	 * @param path The path beginning from the <code>assets</code> package
	 * @return An optional with the url if the asset exists
	 */
	@NotNull
	public static Optional<URL> getURL(@NotNull String path) {
		return Optional.ofNullable(Thread.currentThread().getContextClassLoader().getResource(path));
	}

}
