Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan alignment #60

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion electron/settings/settings-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const SettingsDefault: SettingsInterface = {
diver: {
end_turn: "backspace",
open_chat: "return",
alignment_scan: "",
active_open_menu: true,
open_menu: "",
go_up: "ctrl+up",
Expand Down Expand Up @@ -131,7 +132,7 @@ export const SettingsDefault: SettingsInterface = {
alliance: "",
mount: "n",
directory: "",
alignement: "",
alignment: "",
bestiary: "b",
title: "t",
achievement: "u",
Expand Down
3 changes: 2 additions & 1 deletion electron/settings/settings.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface SettingsInterface {
diver: {
end_turn: string;
open_chat: string;
alignment_scan: string,
active_open_menu: boolean;
open_menu: string;
go_up: string;
Expand All @@ -56,7 +57,7 @@ export interface SettingsInterface {
alliance: string;
mount: string;
directory: string;
alignement: string;
alignment: string;
bestiary: string;
title: string;
achievement: string;
Expand Down
3 changes: 2 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
"header": "Miscellaneous",
"end-turn": "End your turn / Ready (fight)",
"open-chat": "Open the chat",
"alignment_scan":"Scan player alignments",
"active-open-menu": "Open menu when no window is open (ECHAP)",
"open-menu": "Open the menu",
"go_up": "Go to Upper Map",
Expand All @@ -259,7 +260,7 @@
"alliance": "Alliance",
"mount": "Mount",
"directory": "List of Guilds and Alliances",
"alignement": "Alignment",
"alignment": "Alignment",
"bestiary": "Bestiary",
"title": "Titles and Ornaments",
"achievement": "Achievements",
Expand Down
5 changes: 3 additions & 2 deletions locale/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
"header": "Diverso",
"end-turn": "Saltar su torno / Listo (combate)",
"open-chat": "Abrir el chat",
"active-open-menu": "Abrir menú cuando no hay ventana abierta (ECHAP)",
"alignment_scan":"Escanear alineaciones de reproductores",
"active-open-menu": "Apri menu quando nessuna finestra è aperta (ECHAP)",
"open-menu": "Abre el menu",
"go_up": "Ir a Mapa Superior",
"go_bottom": "Ir a Mapa Inferior",
Expand All @@ -255,7 +256,7 @@
"alliance": "Alianza",
"mount": "Montura",
"directory": "Repertorio de gremio y alianza",
"alignement": "Alineamiento",
"alignment": "Alineamiento",
"bestiary": "Bestiario",
"title": "Título y ornamentos",
"achievement": "Logros",
Expand Down
3 changes: 2 additions & 1 deletion locale/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"header": "Divers",
"end-turn": "Passer son tour / Prêt (combat)",
"open-chat": "Ouvrir le chat",
"alignment_scan":"Scanner les alignements des joueurs",
"active-open-menu": "Ouvrir le menu lorsqu'aucune fenêtre n'est ouverte (ECHAP)",
"open-menu": "Ouvrir le menu",
"go_up" : "Aller à la carte du dessus",
Expand All @@ -258,7 +259,7 @@
"alliance": "Alliance",
"mount": "Monture",
"directory": "Répertoire de guilde et d'alliance",
"alignement": "Alignement",
"alignment": "Alignement",
"bestiary": "Bestiare",
"title": "Titres et Ornements",
"achievement": "Succès",
Expand Down
3 changes: 2 additions & 1 deletion locale/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
"header": "Varie",
"end-turn": "Finisci il turno / Pronto (combattimenti)",
"open-chat": "Apri la chat",
"alignment_scan": "Scansione degli allineamenti dei giocatori",
"active-open-menu": "Apri menu quando nessuna finestra è aperta (ECHAP)",
"open-menu": "Apri il menu",
"go_up": "Vai alla Mappa superiore",
Expand All @@ -259,7 +260,7 @@
"alliance": "Alleanza",
"mount": "Cavalcatura",
"directory": "Lista delle gilde e delle alleanze",
"alignement": "Allineamento",
"alignment": "Allineamento",
"bestiary": "Bestiario",
"title": "Titoli ed ornamenti",
"achievement": "Obbiettivi",
Expand Down
9 changes: 8 additions & 1 deletion src/app/core/helpers/shortcuts.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class ShortcutsHelper {
(<any>this.window).key(shortcut, (e: KeyboardEvent) => {
action(e);
});

this.shortcuts.push(shortcut);
}

Expand All @@ -24,6 +23,14 @@ export class ShortcutsHelper {

this.shortcutsVanilla.push(listener);
}
public bindVanillaKeyUp(shortcut: string, action: (e?: KeyboardEvent) => void): void {
let listener = (e: KeyboardEvent) => {
if (shortcut.includes(e.key.toLowerCase()) ) action(e);
};
(<any>this.window).addEventListener('keyup', listener);

this.shortcutsVanilla.push(listener);
}

public unBindAll(): void{
this.shortcuts.forEach((shortcut) => {
Expand Down
84 changes: 84 additions & 0 deletions src/app/core/mods/alignment/alignment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Logger } from "app/core/electron/logger.helper";
import { alignmentUIContainer } from "./alignmentUIContainer";

import { Mod } from "../mod";

/**
* This mod add the possibility to show alignment
*/
export class Alignment extends Mod {
private lastScan;
private container : alignmentUIContainer;

startMod() {
this.lastScan = 0;

/* Add <style>*/
let alignmentbarCss = document.createElement('style');
alignmentbarCss.id = 'alignmentBarCss';
alignmentbarCss.innerHTML = `
.alignmentBarsContainer {
position: absolute;
top: 0;
left: 0;
pointer-events: none;
z-index: 1;
visibility: hidden;
}

.alignmentBarContainer {
box-sizing: border-box;
border: 1px gray solid;
background-color: #222;
height: 6px;
width: 30px;
position: absolute;
border-radius: 3px;
overflow: hidden;
transition-duration: 500ms;
margin-top: 10px;
}

.alignmentBar {
transition-duration: 300ms;
height: 100%;
width: 0%;
background-color: #333;
}
`;
this.wGame.document.getElementsByTagName('head')[0].appendChild(alignmentbarCss);
}

public scan() {
// When you active the mod
let currentTime = Math.floor(Date.now() / 1000);
if (currentTime > this.lastScan + 1) {
// Is last scan was more than 1 second
this.lastScan = currentTime;
if (this.container != null) {
this.container.destroy();
}
this.container = new alignmentUIContainer(this.wGame);
this.container.show(); // Scan
}
}

public destroy() {
if (this.container) {
this.container.destroy();
this.container = null;
}
}

public reset() {
super.reset();
if (this.container) {
this.container.destroy();
}
let alignmentbarCss = this.wGame.document.getElementById('alignmentBarCss');
if (alignmentbarCss && alignmentbarCss.parentElement) {
alignmentbarCss.parentElement.removeChild(alignmentbarCss);
}
}

}
124 changes: 124 additions & 0 deletions src/app/core/mods/alignment/alignmentUIBar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { Logger } from "app/core/electron/logger.helper";

export class alignmentUIBar {

private player: any; // Le joueur qui détiens la barre de couleur en fct de son alignment
private wGame: any;

private alignmentBarContainer: HTMLDivElement; // Parent de la barre
private alignmentBar: HTMLDivElement; // La barre en elle-même

constructor(player: any, wGame: any | Window) {
this.player = player;
this.wGame = wGame;
this.createBar();
}

public getId() {
return this.player.data.playerId;
}

private createBar() {
/* Get data */
let cellId = this.player.cellId;
let alignmentInfo = this.player.data.alignmentInfos;

let scenePos = this.wGame.isoEngine.mapRenderer.getCellSceneCoordinate(cellId);
let pos = this.wGame.isoEngine.mapScene.convertSceneToCanvasCoordinate(scenePos.x, scenePos.y);

/* Create bar container */
this.alignmentBarContainer = document.createElement('div');
this.alignmentBarContainer.id = 'playerAlignmentBarContainer' + this.player.data.playerId;
this.alignmentBarContainer.className = 'alignmentBarContainer';

/* Create bar */
this.alignmentBar = document.createElement('div');
this.alignmentBar.id = 'playerAlignmentBar' + this.player.data.playerId;
this.alignmentBar.className = 'alignmentBar';

/* Color */
this.setColorByAlignment(alignmentInfo.alignmentSide);

this.alignmentBarContainer.appendChild(this.alignmentBar); // Add bar in barContainer
this.wGame.document.getElementById('alignmentBars').appendChild(this.alignmentBarContainer);

/* Set x and y to for the barContainer */
this.alignmentBarContainer.style.left = (pos.x - this.alignmentBarContainer.offsetWidth / 2) + 'px';
this.alignmentBarContainer.style.top = (pos.y) + 'px';
this.alignmentBarContainer.style.opacity = '';
}

public update() {
let player = this.wGame.actorManager.getPlayers();
let currentPlayer;
for (let index = 0; index < player.length; index++) {
// Check player doesn't desapear
if (player[index].data.playerId == this.player.data.playerId) {
currentPlayer = player[index];
}
}

if (currentPlayer == null) {
// player desapear
return true;
}

if (!this.alignmentBar || !this.alignmentBarContainer) {
this.createBar();
}

this.alignmentBar.style.width = '100%';
this.alignmentBar.style.right = '';

let cellId = currentPlayer.cellId;

if (cellId) {
try {
let scenePos = this.wGame.isoEngine.mapRenderer.getCellSceneCoordinate(cellId);
let pos = this.wGame.isoEngine.mapScene.convertSceneToCanvasCoordinate(scenePos.x, scenePos.y);
this.alignmentBarContainer.style.left = (pos.x - this.alignmentBarContainer.offsetWidth / 2) + 'px';
this.alignmentBarContainer.style.top = (pos.y) + 'px';
this.alignmentBarContainer.style.opacity = '';
} catch (e) {
Logger.info(cellId);
Logger.error(e);
}
}

}

public destroy() {
// this.alignmentBar.parentElement.removeChild(this.alignmentBar);
// this.alignmentBarContainer.parentElement.removeChild(this.alignmentBarContainer);
}

private setColorByAlignment(alignmentSide) {
switch (alignmentSide) {
case 1:
// Bonta
this.alignmentBarContainer.style.borderColor = '#1f8fcb';
this.alignmentBarContainer.style.backgroundColor = '#1f8fcb';

this.alignmentBar.style.borderColor = '#1f8fcb';
this.alignmentBar.style.backgroundColor = '#1f8fcb';
break;
case 2:
// Brak
this.alignmentBarContainer.style.borderColor = '#820000';
this.alignmentBarContainer.style.backgroundColor = '#820000';

this.alignmentBar.style.borderColor = '#820000';
this.alignmentBar.style.backgroundColor = '#820000';

break;
default:
// Neutral
this.alignmentBarContainer.style.borderColor = '#000';
this.alignmentBarContainer.style.backgroundColor = '#000';

this.alignmentBar.style.borderColor = '#000';
this.alignmentBar.style.backgroundColor = '#000';
break;
}
}
}
Loading