47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import AbstractTopBarInterface from '@burguillosinfo/conquer/interface/abstract-top-bar-interface'
|
|
import Conquer from '@burguillosinfo/conquer'
|
|
import MapNode from '@burguillosinfo/conquer/map-node'
|
|
|
|
export default class NodeView extends AbstractTopBarInterface {
|
|
private node: MapNode;
|
|
private getNodeNameH2(): HTMLElement {
|
|
const element = this.getMainNode().querySelector('h2.node-name');
|
|
if (!(element instanceof HTMLElement)) {
|
|
Conquer.fail('h2.node-name is not a H2 or does not exist.');
|
|
}
|
|
return element;
|
|
}
|
|
|
|
private getNodeDescriptionParagraph(): HTMLElement {
|
|
const element = this.getMainNode().querySelector('p.node-description');
|
|
if (!(element instanceof HTMLElement)) {
|
|
Conquer.fail('p.node-description is not a P or does not exist.');
|
|
}
|
|
return element;
|
|
}
|
|
|
|
constructor(node: MapNode) {
|
|
super()
|
|
this.node = node;
|
|
}
|
|
public async run() {
|
|
const mainNode = this.getMainNode()
|
|
this.runCallbacks('update-nodes');
|
|
try {
|
|
this.node = await this.node.fetch();
|
|
} catch (error) {
|
|
this.runCallbacks('close');
|
|
}
|
|
const view = this.getNodeFromTemplateId('conquer-view-node-template')
|
|
mainNode.append(view)
|
|
this.getNodeNameH2().innerText = this.node.getName();
|
|
this.getNodeDescriptionParagraph().innerText = this.node.getDescription()
|
|
+ "\n"
|
|
+ (this.node.isNear()
|
|
? 'Estas cerca y puedes interactuar con este sitio.'
|
|
: 'Estás demasiado lejos para hacer nada aquí.');
|
|
view.classList.remove('conquer-display-none')
|
|
mainNode.classList.remove('conquer-display-none')
|
|
}
|
|
}
|