Daniel-alias-la-puissance
Melro Serdoura Daniel ago%!(EXTRA string=1 year)
parent ae85242fef
commit 2c2507cf79
  1. BIN
      assets/spaceships/blueprint.png
  2. 2
      index.html
  3. 0
      js/skama_code/api/ntm.js
  4. 150
      js/skama_code/api/ship.js

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

@ -5,6 +5,8 @@
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/ui.css">
<link rel="stylesheet" href="css/animation.css">
<link rel="stylesheet" href="css/ships.css">
<script src="js/lib/fabric.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script type="module" src="js/index.js" defer></script>

@ -1,5 +1,6 @@
// Copyright © 2023 Entreprise SkamKraft
"use strict";
import { SpaceTraders } from "./config.js";
import { My } from "./agent.js";
@ -19,7 +20,25 @@ export class Ship {
this.fuel = data.fuel;
}
static list(callback) {
static get(shipSymbol, callback, error_handler) {
const url = `${SpaceTraders.host}/my/ships/${shipSymbol}`;
$.ajax({
url: url,
method: "GET",
headers: {
Accept: "application/json",
Authorization: `Bearer ${My.agent.token}`,
},
success: (response) => {
callback(new Ship(response.data));
},
error: (err) => {
error_handler(err);
},
});
}
static list(callback, error_handler) {
const url = `${SpaceTraders.host}/my/ships`;
$.ajax({
url: url,
@ -29,50 +48,149 @@ export class Ship {
Authorization: `Bearer ${My.agent.token}`,
},
success: (response) => {
let listShips = [];
response.data.forEach(ship => {
listShips.push(new Ship(ship))
const ships = [];
const meta = response.meta;
response.data.forEach((ship) => {
ships.push(new Ship(ship));
});
callback(listShips);
callback(ships, meta);
},
error: (err) => {
error_handler(["Token invalide."]);
error_handler(err);
},
});
}
static get(shipSymbol, callback, error_handler) {
const url = `${SpaceTraders.host}/my/ships/${shipSymbol}`;
static purchase(shipType, waypointSymbol, callback, error_handler) {
const url = `${SpaceTraders.host}/my/ships`;
$.ajax({
url: url,
method: "GET",
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${My.agent.token}`,
},
data: `{\n "shipType": "${shipType}",\n "waypointSymbol": "${waypointSymbol}"\n}`,
success: (response) => {
callback(new Ship(response.data));
callback(new Ship(response.data.ship));
},
error: (err) => {
error_handler(err);
},
});
}
static getPosition(callback) {
const url = `${SpaceTraders.host}/my/ships/${this.name}/nav`;
refresh(callback, error_handler) {
const url = `${SpaceTraders.host}/my/ships/${this.symbol}`;
$.ajax({
url: url,
method: "GET",
headers: {
Accept: "application/json",
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${My.agent.token}`,
},
success: (response) => {
const new_ship = new Ship(response.data);
callback(new_ship);
},
error: (err) => {
error_handler(err);
},
});
}
orbit(callback, error_handler) {
if (this.nav.status == "ORBIT")
return error_handler("Ship already in orbit.");
const url = `${SpaceTraders.host}/my/ships/${this.symbol}/orbit`;
$.ajax({
url: url,
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${My.agent.token}`,
},
success: (response) => {
callback(response.data);
},
error: (err) => {
error_handler(err);
},
});
}
dock(callback, error_handler) {
if (this.nav.status == "DOCKED")
return error_handler("Ship already docked");
const url = `${SpaceTraders.host}/my/ships/${this.symbol}/dock`;
$.ajax({
url: url,
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${My.agent.token}`,
},
success: (response) => {
callback(response.data);
},
error: (err) => {
error_handler(err);
},
});
}
navigate(waypoint, callback, error_handler) {
if (this.nav.status != "ORBIT")
return error_handler("Ship must be in orbit.");
const url = `${SpaceTraders.host}/my/ships/${this.symbol}/navigate`;
$.ajax({
url: url,
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${My.agent.token}`,
},
processData: false,
data: `{\n "waypointSymbol": "${waypoint}"\n}`,
success: (response) => {
callback(response);
},
error: (err) => {
error_handler(err);
},
});
}
refuel(callback, error_handler) {
if (this.nav.status != "ORBIT")
return error_handler("Ship must be in orbit.");
const url = `${SpaceTraders.host}/my/ships/${this.symbol}/refuel`;
$.ajax({
url: url,
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: "Bearer 123",
},
processData: false,
data: '{\n "units": "100",\n "fromCargo": false\n}',
success: (response) => {
callback(response);
},
error: (err) => {
error_handler(["Token invalide."]);
error_handler(err);
},
});
}
}
}
Loading…
Cancel
Save