import { Api } from './api';
import { playerOverview } from './sections/overview';
import $ from 'jquery';
+import {$exploreButton, $fightButton} from './dom';
const api = new Api('http://localhost:9090');
api.on('player', playerOverview);
async function main() {
- await api.login('xangelo2', 'test');
+ try {
+ await api.login('xangelo', 'test');
+ }
+ catch(e) {
+ await api.signup('xangelo', 'test', 'test');
+ await api.login('xangelo', 'test');
+ }
}
-
-$('#explore-action').on('click', async e => {
+$exploreButton().on('click', async e => {
e.preventDefault();
e.stopPropagation();
await api.move();
});
+$fightButton().on('click', async e => {
+ e.preventDefault();
+ e.stopPropagation();
+
+ const fightId = $(e.target).attr('data-fight-id');
+
+ if(!fightId || fightId === 'unset') {
+ return;
+ }
+
+ await api.fight(fightId);
+
+});
+
+$('.stat-increase').on('click', e => {
+ e.preventDefault();
+ e.stopPropagation();
+
+ const stat = $(e.target).attr('data-stat');
+
+ if(!stat) {
+ throw new Error('Invalid stat increase');
+ }
+
+ api.increaseStat(stat);
+});
+
main();