Skip to content

Commit

Permalink
!refactor: delete some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada committed Jul 25, 2023
1 parent 94abc5f commit 12f84fa
Showing 1 changed file with 45 additions and 108 deletions.
153 changes: 45 additions & 108 deletions src/foundation/components/Animation/AnimationComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,43 +306,6 @@ export class AnimationComponent extends Component {
this.entity.getTransform()._backupTransformAsRest();
}

public getStartInputValueOfAnimation(animationTrackName?: string): number {
const name = animationTrackName ?? this.__currentActiveAnimationTrackName;
if (name === undefined) {
const array = Array.from(AnimationComponent.__animationGlobalInfo.values());
if (array.length === 0) {
return 0;
}
const firstAnimationInfo = array[0] as unknown as AnimationInfo;
return firstAnimationInfo.maxEndInputTime;
}
const maxStartInputTime = valueWithDefault<AnimationInfo>({
value: AnimationComponent.__animationGlobalInfo.get(name),
defaultValue: defaultAnimationInfo,
}).minStartInputTime;

return maxStartInputTime;
}

public getEndInputValueOfAnimation(animationTrackName?: string): number {
const name = animationTrackName ?? this.__currentActiveAnimationTrackName;

if (name === undefined) {
const array = Array.from(AnimationComponent.__animationGlobalInfo.values());
if (array.length === 0) {
return 0;
}
const firstAnimationInfo = array[0] as unknown as AnimationInfo;
return firstAnimationInfo.maxEndInputTime;
}
const maxEndInputTime = valueWithDefault<AnimationInfo>({
value: AnimationComponent.__animationGlobalInfo.get(name),
defaultValue: defaultAnimationInfo,
}).maxEndInputTime;

return maxEndInputTime;
}

/**
* get the Array of Animation Track Name
* @returns Array of Animation Track Name
Expand Down Expand Up @@ -382,77 +345,6 @@ export class AnimationComponent extends Component {
return this.__isAnimating;
}

static get startInputValue() {
const components = ComponentRepository.getComponentsWithType(
AnimationComponent
) as AnimationComponent[];
if (components.length === 0) {
return 0;
} else {
const infoArray = Array.from(this.__animationGlobalInfo.values());
const lastInfo = infoArray[infoArray.length - 1];
return lastInfo.minStartInputTime;
}
}

static get endInputValue() {
const components = ComponentRepository.getComponentsWithType(
AnimationComponent
) as AnimationComponent[];
if (components.length === 0) {
return 0;
} else {
const infoArray = Array.from(this.__animationGlobalInfo.values());
const lastInfo = infoArray[infoArray.length - 1];
return lastInfo.maxEndInputTime;
}
}

static get componentTID(): ComponentTID {
return WellKnownComponentTIDs.AnimationComponentTID;
}

get componentTID(): ComponentTID {
return WellKnownComponentTIDs.AnimationComponentTID;
}

/**
* get the entity which has this component.
* @returns the entity which has this component
*/
get entity(): IAnimationEntity {
return EntityRepository.getEntity(this.__entityUid) as unknown as IAnimationEntity;
}

/**
* @override
* Add this component to the entity
* @param base the target entity
* @param _componentClass the component class to add
*/
addThisComponentToEntity<EntityBase extends IEntity, SomeComponentClass extends typeof Component>(
base: EntityBase,
_componentClass: SomeComponentClass
) {
class AnimationEntity extends (base.constructor as any) {
constructor(
entityUID: EntityUID,
isAlive: boolean,
components?: Map<ComponentTID, Component>
) {
super(entityUID, isAlive, components);
}

getAnimation() {
return this.getComponentByComponentTID(
WellKnownComponentTIDs.AnimationComponentTID
) as AnimationComponent;
}
}
applyMixins(base, AnimationEntity);
return base as unknown as ComponentToComponentMethods<SomeComponentClass> & EntityBase;
}

addKeyFrame(
trackName: AnimationTrackName,
pathName: AnimationPathName,
Expand Down Expand Up @@ -686,5 +578,50 @@ export class AnimationComponent extends Component {

this.__transformComponent?._backupTransformAsRest();
}

static get componentTID(): ComponentTID {
return WellKnownComponentTIDs.AnimationComponentTID;
}

get componentTID(): ComponentTID {
return WellKnownComponentTIDs.AnimationComponentTID;
}

/**
* get the entity which has this component.
* @returns the entity which has this component
*/
get entity(): IAnimationEntity {
return EntityRepository.getEntity(this.__entityUid) as unknown as IAnimationEntity;
}

/**
* @override
* Add this component to the entity
* @param base the target entity
* @param _componentClass the component class to add
*/
addThisComponentToEntity<EntityBase extends IEntity, SomeComponentClass extends typeof Component>(
base: EntityBase,
_componentClass: SomeComponentClass
) {
class AnimationEntity extends (base.constructor as any) {
constructor(
entityUID: EntityUID,
isAlive: boolean,
components?: Map<ComponentTID, Component>
) {
super(entityUID, isAlive, components);
}

getAnimation() {
return this.getComponentByComponentTID(
WellKnownComponentTIDs.AnimationComponentTID
) as AnimationComponent;
}
}
applyMixins(base, AnimationEntity);
return base as unknown as ComponentToComponentMethods<SomeComponentClass> & EntityBase;
}
}
ComponentRepository.registerComponentClass(AnimationComponent);

0 comments on commit 12f84fa

Please sign in to comment.