pixi-dragonbones-runtime
Version:
DragonBones Runtime for Pixi.js
432 lines (431 loc) • 19.6 kB
TypeScript
/**
* The MIT License (MIT)
*
* Copyright (c) 2012-2018 DragonBones team and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { WorldClock } from "../animation/index.js";
import { Armature, Slot } from "../armature/index.js";
import { DragonBones } from "../core/index.js";
import { DragonBonesData, TextureAtlasData, TextureData, ArmatureData, DisplayData, ArmatureDisplayData, SlotData, SkinData } from "../model/index.js";
import { ObjectDataParser, BinaryDataParser, DataParser } from "../parser/index.js";
/**
* [en] Base class for the factory that create the armatures. (Typically only one global factory instance is required)
* The factory instance create armatures by parsed and added DragonBonesData instances and TextureAtlasData instances.
* Once the data has been parsed, it has been cached in the factory instance and does not need to be parsed again until it is cleared by the factory instance.
*
* [zh] 创建骨架的工厂基类。 (通常只需要一个全局工厂实例)
* 工厂通过解析并添加的 DragonBonesData 实例和 TextureAtlasData 实例来创建骨架。
* 当数据被解析过之后,已经添加到工厂中,在没有被工厂清理之前,不需要再次解析。
*
* @see DragonBonesData
* @see TextureAtlasData
* @see ArmatureData
* @see Armature
* @version DragonBones 3.0
*/
export declare abstract class BaseFactory {
protected static _objectParser: ObjectDataParser;
protected static _binaryParser: BinaryDataParser;
/**
* @private
*/
autoSearch: boolean;
protected readonly _dragonBonesDataMap: Record<string, DragonBonesData>;
protected readonly _textureAtlasDataMap: Record<string, Array<TextureAtlasData>>;
protected _dragonBones: DragonBones;
protected _dataParser: DataParser;
/**
* [en] Create a factory instance. (typically only one global factory instance is required)
*
* [zh] 创建一个工厂实例。 (通常只需要一个全局工厂实例)
*
* @version DragonBones 3.0
*/
constructor(dataParser?: DataParser | null);
protected _isSupportMesh(): boolean;
protected _getTextureData(textureAtlasName: string, textureName: string): TextureData | null;
protected _fillBuildArmaturePackage(dataPackage: BuildArmaturePackage, dragonBonesName: string, armatureName: string, skinName: string, textureAtlasName: string): boolean;
protected _buildBones(dataPackage: BuildArmaturePackage, armature: Armature): void;
/**
* @private
*/
protected _buildSlots(dataPackage: BuildArmaturePackage, armature: Armature): void;
protected _buildConstraints(dataPackage: BuildArmaturePackage, armature: Armature): void;
protected _buildChildArmature(dataPackage: BuildArmaturePackage | null, _slot: Slot, displayData: ArmatureDisplayData): Armature | null;
protected _getSlotDisplay(dataPackage: BuildArmaturePackage | null, displayData: DisplayData, slot: Slot): any;
protected abstract _buildTextureAtlasData(textureAtlasData: TextureAtlasData | null, textureAtlas: any): TextureAtlasData;
protected abstract _buildArmature(dataPackage: BuildArmaturePackage): Armature;
protected abstract _buildSlot(dataPackage: BuildArmaturePackage, slotData: SlotData, armature: Armature): Slot;
/**
* [en] Parse the raw data to a DragonBonesData instance and cache it to the factory.
*
* [zh] 将原始数据解析为 DragonBonesData 实例,并缓存到工厂中。
*
* @param rawData - [en] The raw data.
* @param rawData - [zh] 原始数据。
*
* @param name - [en] Specify a cache name for the instance so that the instance can be obtained through this name. (If not set, use the instance name instead)
* @param name - [zh] 为该实例指定一个缓存名称,以便可以通过此名称获取该实例。 (如果未设置,则使用该实例中的名称)
*
* @param scale - [en] Specify a scaling value for all armatures. (Default: 1.0)
* @param scale - [zh] 为所有的骨架指定一个缩放值。 (默认: 1.0)
*
* @returns [en] DragonBonesData instance
* @returns [zh] DragonBonesData 实例
*
* @see #getDragonBonesData()
* @see #addDragonBonesData()
* @see #removeDragonBonesData()
* @see DragonBonesData
* @version DragonBones 4.5
*/
parseDragonBonesData(rawData: any, name?: string | null, scale?: number): DragonBonesData | null;
/**
* [en] Parse the raw texture atlas data and the texture atlas object to a TextureAtlasData instance and cache it to the factory.
*
* [zh] 将原始贴图集数据和贴图集对象解析为 TextureAtlasData 实例,并缓存到工厂中。
*
* @param rawData - [en] The raw texture atlas data.
* @param rawData - [zh] 原始贴图集数据。
*
* @param textureAtlas - [en] The texture atlas object.
* @param textureAtlas - [zh] 贴图集对象。
*
* @param name - [en] Specify a cache name for the instance so that the instance can be obtained through this name. (If not set, use the instance name instead)
* @param name - [zh] 为该实例指定一个缓存名称,以便可以通过此名称获取该实例。 (如果未设置,则使用该实例中的名称)
*
* @param scale - [en] Specify a scaling value for the map set. (Default: 1.0)
* @param scale - [zh] 为贴图集指定一个缩放值。 (默认: 1.0)
*
* @returns [en] TextureAtlasData instance
* @returns [zh] TextureAtlasData 实例
*
* @see #getTextureAtlasData()
* @see #addTextureAtlasData()
* @see #removeTextureAtlasData()
* @see TextureAtlasData
* @version DragonBones 4.5
*/
parseTextureAtlasData(rawData: any, textureAtlas: any, name?: string | null, scale?: number): TextureAtlasData;
/**
* [en] Update texture atlases.
*
* [zh] 更新贴图集对象。
*
* @param textureAtlases - [en] The texture atlas objects.
* @param textureAtlases - [zh] 多个贴图集对象。
*
* @param name - [en] The texture atlas name.
* @param name - [zh] 贴图集名称。
*
* @version DragonBones 5.7
*/
updateTextureAtlases(textureAtlases: Array<any>, name: string): void;
/**
* [en] Get a specific DragonBonesData instance.
*
* [zh] 获取特定的 DragonBonesData 实例。
*
* @param name - [en] The DragonBonesData instance cache name.
* @param name - [zh] DragonBonesData 实例的缓存名称。
*
* @returns [en] DragonBonesData instance
* @returns [zh] DragonBonesData 实例
*
* @see #parseDragonBonesData()
* @see #addDragonBonesData()
* @see #removeDragonBonesData()
* @see DragonBonesData
* @version DragonBones 3.0
*/
getDragonBonesData(name: string): DragonBonesData | null;
/**
* [en] Cache a DragonBonesData instance to the factory.
*
* [zh] 将 DragonBonesData 实例缓存到工厂中。
*
* @param data - [en] The DragonBonesData instance.
* @param data - [zh] DragonBonesData 实例。
*
* @param name - [en] Specify a cache name for the instance so that the instance can be obtained through this name. (if not set, use the instance name instead)
* @param name - [zh] 为该实例指定一个缓存名称,以便可以通过此名称获取该实例。 (如果未设置,则使用该实例中的名称)
*
* @see #parseDragonBonesData()
* @see #getDragonBonesData()
* @see #removeDragonBonesData()
* @see DragonBonesData
* @version DragonBones 3.0
*/
addDragonBonesData(data: DragonBonesData, name?: string | null): void;
/**
* [en] Remove a DragonBonesData instance.
*
* [zh] 移除 DragonBonesData 实例。
*
* @param name - [en] The DragonBonesData instance cache name.
* @param name - [zh] DragonBonesData 实例缓存名称。
*
* @param disposeData - [en] Whether to dispose data. (Default: true)
* @param disposeData - [zh] 是否释放数据。 (默认: true)
*
* @see #parseDragonBonesData()
* @see #getDragonBonesData()
* @see #addDragonBonesData()
* @see DragonBonesData
* @version DragonBones 3.0
*/
removeDragonBonesData(name: string, disposeData?: boolean): void;
/**
* [en] Get a list of specific TextureAtlasData instances.
*
* [zh] 获取特定的 TextureAtlasData 实例列表。
*
* @param name - [en] The TextureAtlasData cahce name.
* @param name - [zh] TextureAtlasData 实例缓存名称。
*
* @see #parseTextureAtlasData()
* @see #addTextureAtlasData()
* @see #removeTextureAtlasData()
* @see TextureAtlasData
* @version DragonBones 3.0
*/
getTextureAtlasData(name: string): Array<TextureAtlasData> | null;
/**
* [en] Cache a TextureAtlasData instance to the factory.
*
* [zh] 将 TextureAtlasData 实例缓存到工厂中。
*
* @param data - [en] The TextureAtlasData instance.
* @param data - [zh] TextureAtlasData 实例。
*
* @param name - [en] Specify a cache name for the instance so that the instance can be obtained through this name. (if not set, use the instance name instead)
* @param name - [zh] 为该实例指定一个缓存名称,以便可以通过此名称获取该实例。 (如果未设置,则使用该实例中的名称)
*
* @see #parseTextureAtlasData()
* @see #getTextureAtlasData()
* @see #removeTextureAtlasData()
* @see TextureAtlasData
* @version DragonBones 3.0
*/
addTextureAtlasData(data: TextureAtlasData, name?: string | null): void;
/**
* [en] Remove a TextureAtlasData instance.
*
* [zh] 移除 TextureAtlasData 实例。
*
* @param name - [en] The TextureAtlasData instance cache name.
* @param name - [zh] TextureAtlasData 实例的缓存名称。
*
* @param disposeData - [en] Whether to dispose data.
* @param disposeData - [zh] 是否释放数据。
*
* @see #parseTextureAtlasData()
* @see #getTextureAtlasData()
* @see #addTextureAtlasData()
* @see TextureAtlasData
* @version DragonBones 3.0
*/
removeTextureAtlasData(name: string, disposeData?: boolean): void;
/**
* [en] Get a specific armature data.
*
* [zh] 获取特定的骨架数据。
*
* @param name - [en] The armature data name.
* @param name - [zh] 骨架数据名称。
*
* @param dragonBonesName - [en] The cached name for DragonbonesData instance.
* @param dragonBonesName - [zh] DragonBonesData 实例的缓存名称。
*
* @see ArmatureData
* @version DragonBones 5.1
*/
getArmatureData(name: string, dragonBonesName?: string): ArmatureData | null;
/**
* [en] Clear all cached DragonBonesData instances and TextureAtlasData instances.
*
* [zh] 清除缓存的所有 DragonBonesData 实例和 TextureAtlasData 实例。
*
* @param disposeData - [en] Whether to dispose data.
* @param disposeData - [zh] 是否释放数据。
*
* @version DragonBones 4.5
*/
clear(disposeData?: boolean): void;
/**
* [en] Create a armature from cached DragonBonesData instances and TextureAtlasData instances.
* Note that when the created armature that is no longer in use, you need to explicitly dispose {@link Armature#dispose()}.
*
* [zh] 通过缓存的 DragonBonesData 实例和 TextureAtlasData 实例创建一个骨架。
* 注意,创建的骨架不再使用时,需要显式释放 {@link Armature#dispose()}。
*
* @param armatureName - [en] The armature data name.
* @param armatureName - [zh] 骨架数据名称。
*
* @param dragonBonesName - [en] The cached name of the DragonBonesData instance. (If not set, all DragonBonesData instances are retrieved, and when multiple DragonBonesData instances contain a the same name armature data, it may not be possible to accurately create a specific armature)
* @param dragonBonesName - [zh] DragonBonesData 实例的缓存名称。 (如果未设置,将检索所有的 DragonBonesData 实例,当多个 DragonBonesData 实例中包含同名的骨架数据时,可能无法准确的创建出特定的骨架)
*
* @param skinName - [en] The skin name, you can set a different ArmatureData name to share it's skin data. (If not set, use the default skin data)
* @param skinName - [zh] 皮肤名称,可以设置一个其他骨架数据名称来共享其皮肤数据。(如果未设置,则使用默认的皮肤数据)
*
* @returns [en] The armature.
* @returns [zh] 骨架。
*
* @example
* ```ts
* let armature = factory.buildArmature("armatureName", "dragonBonesName");
* armature.clock = factory.clock;
* ```
* @see DragonBonesData
* @see ArmatureData
* @version DragonBones 3.0
*/
buildArmature(armatureName: string, dragonBonesName?: string, skinName?: string, textureAtlasName?: string): Armature | null;
/**
* @private
*/
replaceDisplay(slot: Slot, displayData: DisplayData | null, displayIndex?: number): void;
/**
* [en] Replaces the current display data for a particular slot with a specific display data.
* Specify display data with "dragonBonesName/armatureName/slotName/displayName".
*
* [zh] 用特定的显示对象数据替换特定插槽当前的显示对象数据。
* 用 "dragonBonesName/armatureName/slotName/displayName" 指定显示对象数据。
*
* @param dragonBonesName - [en] The DragonBonesData instance cache name.
* @param dragonBonesName - [zh] DragonBonesData 实例的缓存名称。
*
* @param armatureName - [en] The armature data name.
* @param armatureName - [zh] 骨架数据名称。
*
* @param slotName - [en] The slot data name.
* @param slotName - [zh] 插槽数据名称。
*
* @param displayName - [en] The display data name.
* @param displayName - [zh] 显示对象数据名称。
*
* @param slot - [en] The slot.
* @param slot - [zh] 插槽。
*
* @param displayIndex - [en] The index of the display data that is replaced. (If it is not set, replaces the current display data)
* @param displayIndex - [zh] 被替换的显示对象数据的索引。 (如果未设置,则替换当前的显示对象数据)
*
* @example
* ```ts
* let slot = armature.getSlot("weapon");
* factory.replaceSlotDisplay("dragonBonesName", "armatureName", "slotName", "displayName", slot);
* ```
* @version DragonBones 4.5
*/
replaceSlotDisplay(dragonBonesName: string, armatureName: string, slotName: string, displayName: string, slot: Slot, displayIndex?: number): boolean;
/**
* @private
*/
replaceSlotDisplayList(dragonBonesName: string | null, armatureName: string, slotName: string, slot: Slot): boolean;
/**
* [en] Share specific skin data with specific armature.
*
* [zh] 将特定的皮肤数据共享给特定的骨架使用。
*
* @param armature - [en] The armature.
* @param armature - [zh] 骨架。
*
* @param skin - [en] The skin data.
* @param skin - [zh] 皮肤数据。
*
* @param isOverride - [en] Whether it completely override the original skin. (Default: false)
* @param isOverride - [zh] 是否完全覆盖原来的皮肤。 (默认: false)
*
* @param exclude - [en] A list of slot names that do not need to be replace.
* @param exclude - [zh] 不需要被替换的插槽名称列表。
*
* @example
* ```ts
* let armatureA = factory.buildArmature("armatureA", "dragonBonesA");
* let armatureDataB = factory.getArmatureData("armatureB", "dragonBonesB");
* if (armatureDataB && armatureDataB.defaultSkin) {
* factory.replaceSkin(armatureA, armatureDataB.defaultSkin, false, ["arm_l", "weapon_l"]);
* }
* ```
* @see Armature
* @see SkinData
* @version DragonBones 5.6
*/
replaceSkin(armature: Armature, skin: SkinData, isOverride?: boolean, exclude?: Array<string> | null): boolean;
/**
* [en] Replaces the existing animation data for a specific armature with the animation data for the specific armature data.
* This enables you to make a armature template so that other armature without animations can share it's animations.
*
* [zh] 用特定骨架数据的动画数据替换特定骨架现有的动画数据。
* 这样就能实现制作一个骨架动画模板,让其他没有制作动画的骨架共享该动画。
*
* @param armature - [en] The armtaure.
* @param armature - [zh] 骨架。
*
* @param armatureData - [en] The armature data.
* @param armatureData - [zh] 骨架数据。
*
* @param isOverride - [en] Whether to completely overwrite the original animation. (Default: false)
* @param isOverride - [zh] 是否完全覆盖原来的动画。(默认: false)
*
* @example
* ```ts
* let armatureA = factory.buildArmature("armatureA", "dragonBonesA");
* let armatureDataB = factory.getArmatureData("armatureB", "dragonBonesB");
* if (armatureDataB) {
* factory.replaceAnimation(armatureA, armatureDataB);
* }
* ```
* @see Armature
* @see ArmatureData
* @version DragonBones 5.6
*/
replaceAnimation(armature: Armature, armatureData: ArmatureData, isOverride?: boolean): boolean;
/**
* @private
*/
getAllDragonBonesData(): Record<string, DragonBonesData>;
/**
* @private
*/
getAllTextureAtlasData(): Record<string, Array<TextureAtlasData>>;
/**
* [en] An Worldclock instance updated by engine.
*
* [zh] 由引擎驱动的 WorldClock 实例。
*
* @version DragonBones 5.7
*/
get clock(): WorldClock;
/**
* @private
*/
get dragonBones(): DragonBones;
}
/**
* @private
*/
export declare class BuildArmaturePackage {
dataName: string;
textureAtlasName: string;
data: DragonBonesData;
armature: ArmatureData;
skin: SkinData | null;
}