-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for all out attack and feint
- Loading branch information
1 parent
06d7919
commit c16370d
Showing
24 changed files
with
585 additions
and
256 deletions.
There are no files selected for viewing
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
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,83 @@ | ||
import { ChooserData } from '../../types.js'; | ||
import { MODULE_NAME } from '../../util/constants.js'; | ||
import { activateChooser } from '../../util/miscellaneous.js'; | ||
import BaseActorController from '../abstract/BaseActorController.js'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import Maneuvers from '/systems/gurps/module/actor/maneuver.js'; | ||
|
||
//#region types | ||
export interface ManeuverInfo { | ||
tooltip: string; | ||
page: string; | ||
callback?: (token: Token) => void; | ||
} | ||
interface Maneuver extends ManeuverInfo { | ||
name: string; | ||
canAttack: boolean; | ||
key: string; | ||
} | ||
interface GurpsManeuver { | ||
changes: { | ||
key: string; | ||
mode: number; | ||
priority: number; | ||
value: string; | ||
}[]; | ||
flags: { | ||
gurps: { | ||
alt: null; | ||
defense: 'any' | 'none' | 'dodge-block'; | ||
fullturn: boolean; | ||
icon: string; | ||
move: 'step' | 'half' | 'full'; | ||
name: string; | ||
}; | ||
}; | ||
icon: string; | ||
id: 'maneuver'; | ||
label: string; | ||
} | ||
//#endregion | ||
|
||
export default abstract class BaseManeuverChooser extends BaseActorController { | ||
abstract maneuversInfo: Record<string, ManeuverInfo>; | ||
|
||
constructor(appName: string, token: Token, options: Partial<Application.Options>) { | ||
super(appName, token, { | ||
title: `Maneuver Chooser - ${token.name}`, | ||
template: `modules/${MODULE_NAME}/templates/maneuverChooser.hbs`, | ||
...options, | ||
}); | ||
} | ||
getData(): ChooserData<['Maneuver', 'Description']> { | ||
const maneuversDescriptions = this.getManeuversData().map((maneuver) => ({ | ||
Maneuver: maneuver.name, | ||
Description: maneuver.tooltip, | ||
})); | ||
return { items: maneuversDescriptions, headers: ['Maneuver', 'Description'], id: 'manuever_choice' }; | ||
} | ||
activateListeners(html: JQuery): void { | ||
activateChooser(html, 'manuever_choice', (index) => { | ||
const maneuver = this.getManeuversData()[index]; | ||
this.token.setManeuver(maneuver.key); | ||
ChatMessage.create({ | ||
content: `${this.token.name} uses the "${maneuver.name}" maneuver [PDF:${maneuver.page}]`, | ||
}); | ||
this.closeForEveryone(); | ||
maneuver.callback?.(this.token); | ||
}); | ||
} | ||
|
||
getManeuversData(): Maneuver[] { | ||
const gurpsManeuvers: Record<string, GurpsManeuver> = Maneuvers.getAllData(); | ||
return Object.entries(this.maneuversInfo).map(([key, maneuverInfo]: [string, ManeuverInfo]) => { | ||
return { | ||
...maneuverInfo, | ||
name: game.i18n.localize(gurpsManeuvers[key].label), | ||
canAttack: key.includes('attack'), | ||
key, | ||
}; | ||
}); | ||
} | ||
} |
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,44 @@ | ||
export default function controllerFactory() { | ||
class Controller extends Application { | ||
actor: Actor; | ||
|
||
static apps = new Map<string, Controller>(); | ||
|
||
constructor(appName: string, actor: Actor, options: Partial<Application.Options>) { | ||
const id = `${appName}-${actor.id}`; | ||
super(mergeObject(Application.defaultOptions, { resizable: true, width: 600, id, ...options })); | ||
this.actor = actor; | ||
if (!this.actor) { | ||
throw new Error('no actor'); | ||
} | ||
Controller.apps.set(id, this); | ||
} | ||
|
||
async close(options?: Application.CloseOptions): Promise<void> { | ||
await super.close(options); | ||
Controller.apps.delete(this.id); | ||
} | ||
|
||
static closeById(id: string): boolean { | ||
const instance = Controller.apps.get(id); | ||
if (!instance) return false; | ||
instance.close(); | ||
return true; | ||
} | ||
|
||
closeForEveryone(): void { | ||
EasyCombat.socket.executeForEveryone('closeController', this.id); | ||
} | ||
|
||
static async closeAll(): Promise<void> { | ||
await Promise.all( | ||
[...this.apps.values()].map(async (app) => { | ||
if (app instanceof this) { | ||
await app.close(); | ||
} | ||
}), | ||
); | ||
} | ||
} | ||
return Controller; | ||
} |
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
Oops, something went wrong.