import type { Disposable } from "@goldenratio/core-utils"; import type { EnvProvider } from "./env_provider/env_provider.js"; import { Texture } from "./texture.js"; import type { DrawCircleOptions, DrawLineOptions, DrawRectangleOptions, DrawTextureOptions, DrawTextureTileOptions, InitOptions, LoadTextureOptions, MaskSource, SpriteSheetLoadTextureOptions, Camera2D, DrawNineSliceTextureOptions, Rectangle, Point } from "./types/types.js"; import type { SpriteSheetData } from "./types/spritesheet_types.js"; export declare class Karlib implements Disposable { private readonly context2d; private readonly canvas_size; private readonly texture_util; private readonly camera_util; private readonly env; private readonly res_textures; private readonly pixel_perfect; private readonly transparent_background; constructor(options: InitOptions); private add_texture_cache; /** * Loads image and converts it to texture. * If the image path contains token "{dpr}", then when loading the image,"{dpr}" value is replaced with device-pixel-ratio. * If texture fails to load, it returns `undefined` */ load_texture(image_file_path: string, options?: LoadTextureOptions): Promise; /** * Minimal support for TexturePacker exported spritesheet * Supports only JSON hash format * If the path contains token "{dpr}", then when loading the file, "{dpr}" value is replaced with device-pixel-ratio. */ load_spritesheet_tp(json_file_path: string | SpriteSheetData, options?: SpriteSheetLoadTextureOptions): Promise>; /** * Sets background color */ clear_background(color?: string): void; /** * Render a line */ draw_line(options: DrawLineOptions): void; /** * Render a rectangle shape */ draw_rectangle(options: DrawRectangleOptions): void; /** * Render a circle shape */ draw_circle(options: DrawCircleOptions): void; /** * Render a texture */ draw_texture(options: DrawTextureOptions): void; /** * Render a repeating texture across a given area. The texture can be scrolled, scaled, and rotated independently */ draw_texture_tile(options: DrawTextureTileOptions): void; /** * Allows you to stretch a texture using 9-slice scaling. * The corners will remain unscaled (useful for buttons with rounded corners for example) * and the other areas will be scaled horizontally and or vertically * A B * +---+----------------------+---+ * C | 1 | 2 | 3 | * +---+----------------------+---+ * | | | | * | 4 | 5 | 6 | * | | | | * +---+----------------------+---+ * D | 7 | 8 | 9 | * +---+----------------------+---+ * When changing this objects width and/or height: * areas 1 3 7 and 9 will remain unscaled. * areas 2 and 8 will be stretched horizontally * areas 4 and 6 will be stretched vertically * area 5 will be stretched both horizontally and vertically */ draw_nine_slice_texture(options: DrawNineSliceTextureOptions): void; /** * Executes a drawing function with an clipping mask. * @param draw_fn mask is applied for any drawing done inside this function * @param mask_source when not defined mask is not applied. By setting it to undefined, you can use it to disable/enable mask */ draw_scissor_mode(draw_fn: () => void, mask_source?: MaskSource): void; /** * Begin 2D mode with custom camera */ draw_mode_2d(draw_fn: () => void, camera: Camera2D): void; is_rect_in_camera_view(rect: Rectangle, camera: Camera2D): boolean; is_point_in_camera_view(point: Point, camera: Camera2D): boolean; get_context_2d(): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D; get_canvas_width(): number; get_canvas_height(): number; get_tinted_texture(source: Texture, tint_color: string, tint_alpha: number): Texture; get_texture_from_name(name: string): Texture | undefined; get_env(): EnvProvider; /** * Dispose the karlib instance. * Once dispose is called, the karlib instance should not be re-used */ dispose(): void; }