64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { Resource, ResourceNameType, ResourceIdType } from "@ray-lab/renderer-virtual";
|
|
|
|
/**
|
|
* Resource processing tools.
|
|
* Whenever a new resource setting is received,
|
|
* an instance of this class will be instantiated to manage the received resource.
|
|
* @typeParam ResourceOption - Resource option type.
|
|
*/
|
|
abstract class ResourceHandler<ResourceOption extends Resource = Resource> {
|
|
|
|
/**
|
|
* Resource type enumeration.
|
|
*/
|
|
public static resourceType: ResourceNameType;
|
|
public static resourceTypeAlias: ResourceNameType;
|
|
|
|
/**
|
|
* Original resource option.
|
|
*/
|
|
public resourceOption: ResourceOption;
|
|
|
|
/**
|
|
* Resource unique number.
|
|
*/
|
|
public resourceId: ResourceIdType;
|
|
|
|
/**
|
|
* @param resourceOption - Resource option.
|
|
*/
|
|
public constructor(resourceOption: ResourceOption) {
|
|
this.resourceOption = resourceOption;
|
|
this.resourceId = resourceOption.id ?? Symbol(resourceOption.type);
|
|
}
|
|
|
|
/**
|
|
* Resource initialization lifecycle.
|
|
* It will be called once after `WebGLState` is ready.
|
|
*/
|
|
public abstract setup(): any;
|
|
|
|
/**
|
|
* Marks whether the instance is destroyed.
|
|
*/
|
|
public isDestroyed: boolean = false;
|
|
|
|
/**
|
|
* Resource destruction lifecycle.
|
|
* Will be called when the resource is destroyed.
|
|
*/
|
|
public abstract destroy(): any;
|
|
|
|
/**
|
|
* Resource Settings Update Lifecycle.
|
|
* Called when the resource settings will to be updated.
|
|
* At this time, you can access the old settings through `this.resourceOption`.
|
|
*
|
|
* Note:
|
|
* You don't need to execute ```this.resourceOption = newResourceOption``` manually,
|
|
* The assignment will be done after this function returns.
|
|
* @param newResourceOption - New resource option.
|
|
*/
|
|
public abstract update(newResourceOption: ResourceOption): any;
|
|
}
|