-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8951029
commit 2f954bc
Showing
17 changed files
with
31,197 additions
and
393 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CreateAbilityNe } from "../utils/common.js"; | ||
import { Handle, HandleEventMap } from "./Handle.js"; | ||
|
||
export interface AbilityEventMap extends HandleEventMap {} | ||
|
||
export interface Ability { | ||
get handle(): HandleHolder<"ability">; | ||
} | ||
|
||
export class Ability<T extends HandleEventMap = HandleEventMap> extends Handle<T> { | ||
constructor(itemHandle: HandleHolder<"ability">); | ||
constructor(itemHandle: Ability); | ||
constructor(abilCode: number); | ||
constructor(arg: number | Ability | HandleHolder<"ability">) { | ||
if (arg instanceof Ability || arg instanceof HandleHolder) super(arg); | ||
else if (typeof arg === "number") { | ||
super(CreateAbilityNe(arg)); | ||
} else { | ||
throw new TypeError("Unknown first arg"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable matching-export-value-to-file-name */ | ||
import { ABILITY_IF_LEVELS, GetAbilityBaseIntegerFieldById, GetAbilityIntegerField } from "../../utils/common.js"; | ||
import { Ability } from "../Ability.js"; | ||
|
||
export interface AbilityLevelAccessorNatives<T> { | ||
get: (ability: HandleHolder<"ability">, field: HandleHolder<"_enum">, level: number) => T; | ||
set: (ability: HandleHolder<"ability">, field: HandleHolder<"_enum">, level: number, value: T) => boolean; | ||
|
||
baseGet: (abilId: number, field: HandleHolder<"_enum">, level: number) => T; | ||
baseSet: (ability: number, field: HandleHolder<"_enum">, level: number, value: T) => boolean; | ||
} | ||
|
||
export interface AbilityData { | ||
instance: number | Ability; | ||
} | ||
|
||
export class AbilityLevelAccessor<T> implements Iterable<T> { | ||
#abilityData: AbilityData; | ||
#field: HandleHolder<"_enum">; | ||
|
||
#accessorNatives: AbilityLevelAccessorNatives<T>; | ||
|
||
constructor(abilityData: AbilityData, field: HandleHolder<"_enum">, accessNatives: AbilityLevelAccessorNatives<T>) { | ||
this.#abilityData = abilityData; | ||
this.#field = field; | ||
|
||
this.#accessorNatives = accessNatives; | ||
} | ||
|
||
*[Symbol.iterator](): Iterator<T> { | ||
for (let i = 0; i < this.getLength(); ++i) { | ||
yield this.getIndexValue(i); | ||
} | ||
} | ||
|
||
public getLength() { | ||
return typeof this.#abilityData.instance === "number" | ||
? GetAbilityBaseIntegerFieldById(this.#abilityData.instance, ABILITY_IF_LEVELS) | ||
: GetAbilityIntegerField(this.#abilityData.instance.handle, ABILITY_IF_LEVELS); | ||
} | ||
|
||
public getIndexValue(index: number) { | ||
return typeof this.#abilityData.instance === "number" | ||
? this.#accessorNatives.baseGet(this.#abilityData.instance, this.#field, index) | ||
: this.#accessorNatives.get(this.#abilityData.instance.handle, this.#field, index); | ||
} | ||
|
||
public setIndexValue(index: number, value: T) { | ||
return typeof this.#abilityData.instance === "number" | ||
? this.#accessorNatives.baseSet(this.#abilityData.instance, this.#field, index, value) | ||
: this.#accessorNatives.set(this.#abilityData.instance.handle, this.#field, index, value); | ||
} | ||
} | ||
|
||
export class AbilityData { | ||
#_instance: number | Ability; | ||
|
||
constructor(instance: number | Ability) { | ||
this.#_instance = instance; | ||
|
||
Object.defineProperty(this, "instance", { | ||
value: instance, | ||
writable: false, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.