exploring/fighting is functional
[sketchy-heroes.git] / src / public / app / game.ts
index 4fe0293dec311c0b5d2d3569c791f20d41922795..acfec1428e0ecacb2132a2c41978127ae06875a7 100644 (file)
@@ -1,21 +1,54 @@
 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();