Skip to content

Commit

Permalink
Better UI typing. Better tests for interface callbacks exports.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neloreck committed Jul 24, 2023
1 parent cd737f5 commit bd1b5ba
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, it, jest } from "@jest/globals";

import { registry } from "@/engine/core/database";
import { ActorInventoryMenuManager, EActorMenuMode } from "@/engine/core/managers/interface/ActorInventoryMenuManager";
import { AnyCallable } from "@/engine/lib/types";
import { ActorInventoryMenuManager } from "@/engine/core/managers/interface/ActorInventoryMenuManager";
import { AnyCallable, EActorMenuMode } from "@/engine/lib/types";
import { gameConsole } from "@/fixtures/xray/mocks/console.mock";

describe("ActorInventoryMenuManager class", () => {
Expand Down
22 changes: 4 additions & 18 deletions src/engine/core/managers/interface/ActorInventoryMenuManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,11 @@ import { executeConsoleCommand } from "@/engine/core/utils/game/game_console";
import { readIniString } from "@/engine/core/utils/ini";
import { LuaLogger } from "@/engine/core/utils/logging";
import { consoleCommands } from "@/engine/lib/constants/console_commands";
import { ACTOR } from "@/engine/lib/constants/words";
import { ClientObject, IniFile } from "@/engine/lib/types";
import { ACTOR, NIL } from "@/engine/lib/constants/words";
import { ClientObject, EActorMenuMode, EActorMenuType, IniFile } from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);

/**
* Current state of actor menu interaction.
*/
export enum EActorMenuMode {
UNDEFINED = 0,
INVENTORY = 1,
TRADE = 2,
UPGRADE = 3,
DEAD_BODY_SEARCH = 4,
TALK_DIALOG = 9,
TALK_DIALOG_SHOW = 10,
TALK_DIALOG_HIDE = 11,
}

// todo: .CUIActorMenu_OnItemDropped handler
export class ActorInventoryMenuManager extends AbstractCoreManager {
public activeMode: EActorMenuMode = EActorMenuMode.UNDEFINED;
Expand Down Expand Up @@ -103,8 +89,8 @@ export class ActorInventoryMenuManager extends AbstractCoreManager {
/**
* todo: Description.
*/
public onItemDropped(from: ClientObject, to: ClientObject, oldList: number, newList: number): void {
logger.info("Actor menu inventory item dropped:", from?.name(), to?.name(), oldList, newList);
public onItemDropped(from: ClientObject, to: ClientObject, oldList: EActorMenuType, newList: EActorMenuType): void {
logger.info("Actor menu inventory item dropped:", from?.name() || NIL, to?.name() || NIL, oldList, newList);
}

/**
Expand Down
31 changes: 31 additions & 0 deletions src/engine/lib/types/xray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,34 @@ export enum ESoundObjectType {
LOOPED = sound_object.looped || 1,
S2D = sound_object.s2d || 2,
}

/**
* Current state of actor menu interaction.
*/
export enum EActorMenuMode {
UNDEFINED = 0,
INVENTORY = 1,
TRADE = 2,
UPGRADE = 3,
DEAD_BODY_SEARCH = 4,
TALK_DIALOG = 9,
TALK_DIALOG_SHOW = 10,
TALK_DIALOG_HIDE = 11,
}

/**
* Type of actor UI window to drag drop items.
*/
export enum EActorMenuType {
INVALID = 0,
ACTOR_SLOT,
ACTOR_BAG,
ACTOR_BELT,
ACTOR_TRADE,
PARTNER_TRADE_BAG,
PARTNER_TRADE,
DEAD_BODY_BAG,
QUICK_SLOT,
TRASH_SLOT,
LIST_TYPE_MAX,
}
43 changes: 40 additions & 3 deletions src/engine/scripts/declarations/callbacks/interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { beforeAll, describe, expect, it, jest } from "@jest/globals";
import { LoadScreenManager } from "@/engine/core/managers/interface/LoadScreenManager";
import { getExtern } from "@/engine/core/utils/binding";
import { AnyCallablesModule } from "@/engine/lib/types";
import { checkBinding } from "@/fixtures/engine";
import { checkBinding, checkNestedBinding } from "@/fixtures/engine";

describe("'interface' external callbacks", () => {
beforeAll(() => {
Expand All @@ -12,14 +12,51 @@ describe("'interface' external callbacks", () => {

it("should correctly inject external methods for game", () => {
checkBinding("ui_wpn_params");
checkNestedBinding("ui_wpn_params", "GetRPM");
checkNestedBinding("ui_wpn_params", "GetDamage");
checkNestedBinding("ui_wpn_params", "GetDamageMP");
checkNestedBinding("ui_wpn_params", "GetHandling");
checkNestedBinding("ui_wpn_params", "GetAccuracy");

checkBinding("inventory_upgrades");
checkNestedBinding("inventory_upgrades", "get_upgrade_cost");
checkNestedBinding("inventory_upgrades", "can_repair_item");
checkNestedBinding("inventory_upgrades", "can_upgrade_item");
checkNestedBinding("inventory_upgrades", "effect_repair_item");
checkNestedBinding("inventory_upgrades", "effect_functor_a");
checkNestedBinding("inventory_upgrades", "prereq_functor_a");
checkNestedBinding("inventory_upgrades", "precondition_functor_a");
checkNestedBinding("inventory_upgrades", "property_functor_a");
checkNestedBinding("inventory_upgrades", "property_functor_b");
checkNestedBinding("inventory_upgrades", "property_functor_c");
checkNestedBinding("inventory_upgrades", "question_repair_item");

checkBinding("pda");
checkNestedBinding("pda", "set_active_subdialog");
checkNestedBinding("pda", "fill_fraction_state");
checkNestedBinding("pda", "get_max_resource");
checkNestedBinding("pda", "get_max_power");
checkNestedBinding("pda", "get_max_member_count");
checkNestedBinding("pda", "actor_menu_mode");
checkNestedBinding("pda", "property_box_clicked");
checkNestedBinding("pda", "property_box_add_properties");
checkNestedBinding("pda", "get_monster_back");
checkNestedBinding("pda", "get_monster_icon");
checkNestedBinding("pda", "get_favorite_weapon");
checkNestedBinding("pda", "get_stat");

checkBinding("actor_menu_inventory");
checkNestedBinding("actor_menu_inventory", "CUIActorMenu_OnItemDropped");

checkBinding("actor_menu");
checkBinding("inventory_upgrades");
checkBinding("loadscreen");
checkNestedBinding("actor_menu", "actor_menu_mode");
});

it("should correctly get tips from manager", () => {
checkBinding("loadscreen");
checkNestedBinding("loadscreen", "get_tip_number");
checkNestedBinding("loadscreen", "get_mp_tip_number");

const loadScreenManager: LoadScreenManager = LoadScreenManager.getInstance();

jest.spyOn(loadScreenManager, "getRandomMultiplayerTipIndex");
Expand Down
22 changes: 19 additions & 3 deletions src/engine/scripts/declarations/callbacks/interface.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { ActorInventoryMenuManager, EActorMenuMode } from "@/engine/core/managers/interface/ActorInventoryMenuManager";
import { ActorInventoryMenuManager } from "@/engine/core/managers/interface/ActorInventoryMenuManager";
import { ItemUpgradesManager } from "@/engine/core/managers/interface/ItemUpgradesManager";
import { LoadScreenManager } from "@/engine/core/managers/interface/LoadScreenManager";
import { PdaManager } from "@/engine/core/managers/interface/PdaManager";
import { WeaponParams } from "@/engine/core/ui/game/WeaponParams";
import { extern } from "@/engine/core/utils/binding";
import { LuaLogger } from "@/engine/core/utils/logging";
import { TWeapon } from "@/engine/lib/constants/items/weapons";
import { AnyArgs, AnyObject, ClientObject, TCount, TIndex, TLabel, TName, TSection } from "@/engine/lib/types";
import {
AnyArgs,
AnyObject,
ClientObject,
EActorMenuMode,
EActorMenuType,
TCount,
TIndex,
TLabel,
TName,
TSection,
} from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);

Expand Down Expand Up @@ -60,7 +71,12 @@ extern("actor_menu", {
* todo;
*/
extern("actor_menu_inventory", {
CUIActorMenu_OnItemDropped: (from: ClientObject, to: ClientObject, oldList: number, newList: number): boolean => {
CUIActorMenu_OnItemDropped: (
from: ClientObject,
to: ClientObject,
oldList: EActorMenuType,
newList: EActorMenuType
): boolean => {
ActorInventoryMenuManager.getInstance().onItemDropped(from, to, oldList, newList);

return true;
Expand Down

0 comments on commit bd1b5ba

Please sign in to comment.