proc-gen equipment drops from monsters can be picked up
[sketchy-heroes.git] / src / public / app / game.ts
index 4fe0293dec311c0b5d2d3569c791f20d41922795..94df3e34af33a517011bae1e0b32546fc4ea2d68 100644 (file)
@@ -1,21 +1,68 @@
 import { Api } from './api';
 import { playerOverview } from './sections/overview';
 import $ from 'jquery';
+import {$exploreButton, $fightButton, disablePickItemButton} 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);
+});
+
+$('#take-world-drop').on('click', e => {
+  e.preventDefault();
+  e.stopPropagation();
+
+  
+  const id = $(e.target).attr('data-drop-id');
+  if(id === 'unset' || id === undefined) {
+    return;
+  }
+
+  // lets pick this item up!
+  api.pickItem(id.toString());
+});
+
 main();