import * as io from "./io.ts";
import * as gfx from "./graphics.ts";

const LOADED_TEXTURES = new Map<string, Promise<gfx.Texture>>();

export function load_texture(path: string): Promise<gfx.Texture> {
  let promise = LOADED_TEXTURES.get(path);
  if (!promise) {
    promise = io.load(path).then((buffer) => gfx.create_texture(buffer, path));
    LOADED_TEXTURES.set(path, promise);
  }

  return promise;
}
