Skip to content

Commit

Permalink
Type gen fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-782 committed Nov 16, 2023
1 parent 2c60f64 commit ef38f7f
Show file tree
Hide file tree
Showing 31 changed files with 180 additions and 147 deletions.
22 changes: 15 additions & 7 deletions .typesAppenderConfig.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { Item } from "./src/handles/Item.ts";
import { Player } from "./src/handles/Player.ts";
import { Unit } from "./src/handles/Unit.ts";
import { Widget } from "./src/handles/Widget.ts";
import { Event, JassCodeCallback, Location, Trigger, TriggerAction, UnitEvent, UnitState } from "./src/utils/common.ts";
import {
HEvent,
JassCodeCallback,
HLocation,
HTrigger,
HTriggerAction,
HUnitEvent,
HUnitState,
} from "./src/utils/common.ts";

declare const __ColnfigOnlyBundlePath = "./build/dts-bundle/out.d.ts";
declare const __ColnfigOnlyFixedBundleOutPath = "./build/fullTypes/bootstrap.d.ts";
Expand All @@ -24,17 +32,17 @@ interface __ColnfigOnlyTypeToHandle {
destructable: Destructable;
widget: Widget;
unit: Unit;
event: Event;
event: HEvent;
item: Item;
ability: HandleHolder<"ability">;
buff: HandleHolder<"buff">;
force: HandleHolder<"force">;
group: HandleHolder<"group">;
trigger: Trigger;
trigger: HTrigger;
triggercondition: HandleHolder<"triggercondition">;
triggeraction: TriggerAction;
triggeraction: HTriggerAction;
timer: HandleHolder<"timer">;
location: Location;
location: HLocation;
region: HandleHolder<"region">;
rect: HandleHolder<"rect">;
boolexpr: HandleHolder<"boolexpr">;
Expand All @@ -52,13 +60,13 @@ interface __ColnfigOnlyTypeToHandle {
playerstate: HandleHolder<"playerstate">;
playerscore: HandleHolder<"playerscore">;
playergameresult: HandleHolder<"playergameresult">;
unitstate: UnitState;
unitstate: HUnitState;
aidifficulty: HandleHolder<"aidifficulty">;
eventid: HandleHolder<"eventid">;
gameevent: HandleHolder<"gameevent">;
playerevent: HandleHolder<"playerevent">;
playerunitevent: HandleHolder<"playerunitevent">;
unitevent: UnitEvent;
unitevent: HUnitEvent;
limitop: HandleHolder<"limitop">;
widgetevent: HandleHolder<"widgetevent">;
dialogevent: HandleHolder<"dialogevent">;
Expand Down
2 changes: 1 addition & 1 deletion src/handles/Unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class Unit<T extends UnitEventMap = UnitEventMap> extends Widget<T> {
limitOp: LimitOp,
value: number,
callback: UnitEventMap[StateEventSymbol],
) {
): UnitStateEmiter {
const stateEmiter = new UnitStateEmiter(this, unitState, limitOp, value);

this.on(stateEmiter.emitSymbol, callback);
Expand Down
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ export * from "./handles/Handle.js";
export * from "./handles/Destructable.js";
export * from "./handles/Item.js";

export { Event, JassCodeCallback, Location, Trigger, TriggerAction, UnitEvent, UnitState } from "./utils/common.js";
export {
HEvent,
JassCodeCallback,
HLocation,
HTrigger,
HTriggerAction,
HUnitEvent,
HUnitState,
} from "./utils/common.js";

export { UnitState, LimitOp } from "./services/emitters/UnitStateEmiter.js";

// -- ONLY FOR dts-bundle

Expand All @@ -46,15 +56,15 @@ declare global {
* A low-level object that replaces the handle type in war3js.
* It is not recommended to use it as an object, as some fields may start to be used by the war3js backend.
*/
interface HandleHolder<S extends string = string> {
interface HandleHolder<T extends string = string, P = unknown> {
/**
* Returns jass handle type. For fake handles this is _enum.
*/
get type(): S;
get type(): T;
/**
* The library object this handle is bound to
*/
payload: any;
payload: P;

/**
* Compares handle's internal pointers as numbers. ``null`` is interpreted as 0
Expand Down
4 changes: 2 additions & 2 deletions src/services/emitters/UnitEmiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Unit } from "../../handles/Unit.js";
import {
CreateTriggerNe,
DestroyTrigger,
Trigger,
HTrigger,
TriggerAddActionNe,
TriggerRegisterUnitEventNe,
UnitEvents,
Expand Down Expand Up @@ -82,7 +82,7 @@ const stringToHandle = {
};

type UnitTriggerInfo = {
[key: string]: Trigger;
[key: string]: HTrigger;
};

const dispatchUnitEvent = (unit: Unit, eventType: string) => {
Expand Down
30 changes: 16 additions & 14 deletions src/services/emitters/UnitStateEmiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { StateEventSymbol, Unit } from "../../handles/Unit.js";
import { UnitEventStateLimit } from "../../triggerEvents/unit/UnitEventStateLimit.js";
import {
CreateTriggerNe,
Trigger,
HTrigger,
TriggerRegisterUnitStateEventNe,
UnitState as UnitStateHandle,
LimitOp as LimitOpHandle,
HUnitState as UnitStateHandle,
HLimitOp as LimitOpHandle,
TriggerAddActionNe,
UnitStates,
LimitOps,
DestroyTrigger,
} from "../../utils/common.js";
import { IDisposable } from "../IDisposable.js";
import { DestroyTrigger } from "./../../utils/common";

export const enum UnitState {
Life,
Expand All @@ -28,7 +30,7 @@ export const enum LimitOp {

export class UnitStateEmiter implements IDisposable {
#unit: Unit;
#trigger: Trigger;
#trigger: HTrigger;
#emitSymbolEvent: StateEventSymbol;

#unitState: UnitState;
Expand All @@ -49,16 +51,16 @@ export class UnitStateEmiter implements IDisposable {

switch (unitState) {
case UnitState.Life:
unitStateHandle = UnitStateHandle.UNIT_STATE_LIFE;
unitStateHandle = UnitStates.UNIT_STATE_LIFE;
break;
case UnitState.MaxLife:
unitStateHandle = UnitStateHandle.UNIT_STATE_MAX_LIFE;
unitStateHandle = UnitStates.UNIT_STATE_MAX_LIFE;
break;
case UnitState.Mana:
unitStateHandle = UnitStateHandle.UNIT_STATE_MANA;
unitStateHandle = UnitStates.UNIT_STATE_MANA;
break;
case UnitState.MaxMana:
unitStateHandle = UnitStateHandle.UNIT_STATE_MAX_MANA;
unitStateHandle = UnitStates.UNIT_STATE_MAX_MANA;
break;
default:
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -67,19 +69,19 @@ export class UnitStateEmiter implements IDisposable {

switch (limitOp) {
case LimitOp.lt:
limitOpHandle = LimitOpHandle.LESS_THAN;
limitOpHandle = LimitOps.LESS_THAN;
break;
case LimitOp.le:
limitOpHandle = LimitOpHandle.LESS_THAN_OR_EQUAL;
limitOpHandle = LimitOps.LESS_THAN_OR_EQUAL;
break;
case LimitOp.eq:
limitOpHandle = LimitOpHandle.EQUAL;
limitOpHandle = LimitOps.EQUAL;
break;
case LimitOp.gt:
limitOpHandle = LimitOpHandle.GREATER_THAN;
limitOpHandle = LimitOps.GREATER_THAN;
break;
case LimitOp.ge:
limitOpHandle = LimitOpHandle.GREATER_THAN_OR_EQUAL;
limitOpHandle = LimitOps.GREATER_THAN_OR_EQUAL;
break;
default:
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/TriggerUnitEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { Unit } from "../../handles/Unit.js";
import { UnitEventType } from "../../services/emitters/UnitEmiter.js";
import { GetTriggerUnit } from "../../utils/common.js";
import { TriggerEvent } from "../TriggerEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class TriggerUnitEvent<E extends UnitEventType = UnitEventType> extends TriggerEvent {
readonly triggerUnit: Unit;
constructor(event: E) {
super(event);
this.triggerUnit = GetTriggerUnit();
this.triggerUnit = fromHandleHolderSoft(GetTriggerUnit());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventAcquiredTarget.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Unit } from "../../handles/Unit.js";
import { GetEventTargetUnit } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventAcquiredTarget extends TriggerUnitEvent<"acquiredTarget"> {
readonly target: Unit;
constructor() {
super("acquiredTarget");
this.target = GetEventTargetUnit();
this.target = fromHandleHolderSoft(GetEventTargetUnit());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventAttacked.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Unit } from "../../handles/Unit.js";
import { GetAttacker } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventAttacked extends TriggerUnitEvent<"attacked"> {
readonly attacker: Unit;
constructor() {
super("attacked");
this.attacker = GetAttacker();
this.attacker = fromHandleHolderSoft(GetAttacker());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventConstructFinish.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Unit } from "../../handles/Unit.js";
import { GetConstructedStructure } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventConstructFinish extends TriggerUnitEvent<"constructFinish"> {
readonly constructedStructure: Unit;
constructor() {
super("constructFinish");
this.constructedStructure = GetConstructedStructure();
this.constructedStructure = fromHandleHolderSoft(GetConstructedStructure());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventDeath.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Unit } from "../../handles/Unit.js";
import { GetKillingUnit } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventDeath extends TriggerUnitEvent<"death"> {
readonly killingUnit: Unit;
constructor() {
super("death");
this.killingUnit = GetKillingUnit();
this.killingUnit = fromHandleHolderSoft(GetKillingUnit());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventDetected.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Player } from "../../handles/Player.js";
import { GetEventDetectingPlayer } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventDetected extends TriggerUnitEvent<"detected"> {
readonly detectingPlayer: Player;
constructor() {
super("detected");
this.detectingPlayer = GetEventDetectingPlayer();
this.detectingPlayer = fromHandleHolderSoft(GetEventDetectingPlayer());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventDropItem.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Item } from "../../handles/Item.js";
import { GetManipulatedItem } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventDropItem extends TriggerUnitEvent<"dropItem"> {
readonly droppedItem: Item;
constructor() {
super("dropItem");
this.droppedItem = GetManipulatedItem();
this.droppedItem = fromHandleHolderSoft(GetManipulatedItem());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventHeroRevivable.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Unit } from "../../handles/Unit.js";
import { GetRevivableUnit } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventHeroRevivable extends TriggerUnitEvent<"heroRevivable"> {
readonly revivableUnit: Unit;
constructor() {
super("heroRevivable");
this.revivableUnit = GetRevivableUnit();
this.revivableUnit = fromHandleHolderSoft(GetRevivableUnit());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventHeroReviveCancel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Unit } from "../../handles/Unit.js";
import { GetRevivingUnit } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventHeroReviveCancel extends TriggerUnitEvent<"heroReviveCancel"> {
readonly revivingUnit: Unit;
constructor() {
super("heroReviveCancel");
this.revivingUnit = GetRevivingUnit();
this.revivingUnit = fromHandleHolderSoft(GetRevivingUnit());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventHeroReviveFinish.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Unit } from "../../handles/Unit.js";
import { GetRevivingUnit } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventHeroReviveFinish extends TriggerUnitEvent<"heroReviveFinish"> {
readonly revivingUnit: Unit;
constructor() {
super("heroReviveFinish");
this.revivingUnit = GetRevivingUnit();
this.revivingUnit = fromHandleHolderSoft(GetRevivingUnit());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventHeroReviveStart.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Unit } from "../../handles/Unit.js";
import { GetRevivingUnit } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventHeroReviveStart extends TriggerUnitEvent<"heroReviveStart"> {
readonly revivingUnit: Unit;
constructor() {
super("heroReviveStart");
this.revivingUnit = GetRevivingUnit();
this.revivingUnit = fromHandleHolderSoft(GetRevivingUnit());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventHeroSkill.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { GetLearnedSkill, GetLearnedSkillLevel } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventHeroSkill extends TriggerUnitEvent<"heroSkill"> {
readonly learnedSkill: number;
readonly learnedSkillLevel: number;
constructor() {
super("heroSkill");
this.learnedSkill = GetLearnedSkill();
this.learnedSkillLevel = GetLearnedSkillLevel();
this.learnedSkillLevel = fromHandleHolderSoft(GetLearnedSkillLevel());
}
}
3 changes: 2 additions & 1 deletion src/triggerEvents/unit/UnitEventIssuedOrder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { GetIssuedOrderId } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";
import { fromHandleHolderSoft } from "../../utils/FromHandleHolder.js";

export class UnitEventIssuedOrder extends TriggerUnitEvent<"issuedOrder"> {
readonly issuedOrderId: number;
constructor() {
super("issuedOrder");
this.issuedOrderId = GetIssuedOrderId();
this.issuedOrderId = fromHandleHolderSoft(GetIssuedOrderId());
}
}
4 changes: 1 addition & 3 deletions src/triggerEvents/unit/UnitEventIssuedPointOrder.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { GetIssuedOrderId, GetOrderPointX, GetOrderPointLoc, GetOrderPointY, Location } from "../../utils/common.js";
import { GetIssuedOrderId, GetOrderPointX, GetOrderPointY } from "../../utils/common.js";
import { TriggerUnitEvent } from "./TriggerUnitEvent.js";

export class UnitEventIssuedPointOrder extends TriggerUnitEvent<"issuedPointOrder"> {
readonly issuedOrderId: number;
readonly orderPointX: number;
readonly orderPointY: number;
readonly orderPointLoc: Location;
constructor() {
super("issuedPointOrder");
this.issuedOrderId = GetIssuedOrderId();
this.orderPointX = GetOrderPointX();
this.orderPointY = GetOrderPointY();
this.orderPointLoc = GetOrderPointLoc();
}
}
Loading

0 comments on commit ef38f7f

Please sign in to comment.