Compare commits

...

17 Commits

  1. 1
      .gitignore
  2. 0
      LICENSE
  3. 38
      README.md
  4. BIN
      assets/contracts/procurement.png
  5. BIN
      assets/contracts/shuttle.png
  6. BIN
      assets/contracts/transportation.png
  7. BIN
      assets/fonts/m42.TTF
  8. BIN
      assets/logo/Offre.png
  9. BIN
      assets/logo/logoblanc.png
  10. BIN
      assets/logo/logoblancnotext.png
  11. BIN
      assets/logo/logonoir.png
  12. BIN
      assets/planets/planetproto.png
  13. BIN
      assets/ressources/ANTIMATTER.png
  14. BIN
      assets/ressources/medkit.png
  15. BIN
      assets/spaceships/spaceship.png
  16. BIN
      assets/spaceships/spaceshiporbits.png
  17. 1
      css/animation.css
  18. 131
      css/style.css
  19. 5
      css/ui.css
  20. BIN
      favicon.ico
  21. 18
      html/template.html
  22. 5
      html/templates/home.html
  23. 10
      html/templates/login.html
  24. 7
      html/templates/test_modal.html
  25. 13
      index.html
  26. 41
      js/Render/renderer.js
  27. 6
      js/index.js
  28. 85
      js/main.js
  29. 115
      js/skama_code/api/agent.js
  30. 7
      js/skama_code/api/config.js
  31. 131
      js/skama_code/api/planet.js
  32. 3
      js/skama_code/api/system.js
  33. 84
      js/skama_code/auth/auth.js
  34. 14
      js/skama_code/commun/initialzer.js
  35. 13
      js/skama_code/commun/position.js
  36. 51
      js/skama_code/commun/strategie.js
  37. 0
      js/skama_code/rendering/canvas_render.js
  38. 0
      js/skama_code/ui/menu.js
  39. 39
      js/skama_code/ui/modal.js
  40. 37
      js/skama_code/ui/templeting_engine.js
  41. 59
      js/skama_code/ui/timer.js
  42. 105
      js/test/tests.js
  43. 19
      templates/index.html
  44. 1
      token

1
.gitignore vendored

@ -0,0 +1 @@
/.vs/

@ -0,0 +1,38 @@
# Skamcraft
## Norm
* ``` ; ``` at the end of each line.
* snack_case for functions and variables.
* UpperCamelCase for Classes.
* all in english.
## DONE
[BETA] = not tested yet = can crash
* template engine :
* renders a page
* renders a fragment in a tag
* adds events to DOM
* authentication :
* verifie input
* registers a new client
* auth a client with is token
* stores token
* retives token from local storage for auth
* agents :
* create an agent
* get agent from token (for authentication)
* get public agent [BETA]
* list a page of agents max : 20
* list all agents in the game
* strategy :
* create a set of rules for input checking
* user frendly errors messages
## TO DO
* Documentaion
* system management
* waypoint management
* ship management

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 945 B

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 969 KiB

After

Width:  |  Height:  |  Size: 969 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 209 KiB

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 315 KiB

After

Width:  |  Height:  |  Size: 315 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 KiB

After

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 767 B

After

Width:  |  Height:  |  Size: 767 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 579 B

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 729 B

After

Width:  |  Height:  |  Size: 729 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 675 B

After

Width:  |  Height:  |  Size: 675 B

@ -0,0 +1 @@
/* Copyright © 2023 Entreprise SkamKraft */

@ -1,5 +1,130 @@
canvas {
width: 50%;
border: 2px solid black;
/* Copyright © 2023 Entreprise SkamKraft */
:root {
--main-back-color: rgb(143, 143, 143);
--second-back-color: black;
}
@font-face {
font-family: M42;
src: url("/assets/fonts/m42.TTF");
}
* {
box-sizing: border-box;
}
body {
background-color: var(--main-back-color);
font-family: 'M42';
font-size: 7px;
margin: 0px;
padding: 0px;
}
/* Main */
.container {
display: flex;
margin: 10px;
flex-direction: column;
align-items: center;
border: 4px solid rgba(68, 68, 68, 0.575);
}
.container .con-title {
font-size: 15px;
border-bottom: 2px solid black;
}
/*footer*/
footer {
position: fixed;
width: 100%;
bottom: 0;
display: flex;
justify-content: center;
background-color: var(--second-back-color);
color: white;
}
/*nav bar*/
.nav-nav {
--nav-img-width: 100px;
background-color: var(--second-back-color);
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-nav .nav-brand {
display: flex;
justify-content: center;
align-items: center;
}
.nav-nav .nav-brand img {
width: var(--nav-img-width);
}
.nav-nav .nav-links {
--links-color: rgb(0,0,0);
--links-backcolor: rgb(255, 123, 71);
--links-border-color: rgb(255, 173, 118);
height: 70%;
display: flex;
justify-content: space-between;
}
.nav-link {
margin-right: 10px;
background-color: var(--links-backcolor);
color: var(--links-color);
border: 4px solid var(--links-border-color);
list-style: none;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 3px 2px white;
}
/* General */
.smooth {
padding: 5px;
border-radius: 10px;
}
/* Modal */
.ext-modal {
background-color: rgba(255, 255, 255, 0.767);
border-radius: 10px;
padding: 50px;
}
.my-modal {
display: flex;
flex-direction: column;
align-items: center;
}
.modal-title {
font-size: 15px;
margin-bottom: 40px;
}
.my-modal #timer {
text-align: center;
border: 1px solid black;
border-radius: 10px;
width: 10%;
padding: 5px;
margin-bottom: 10px;
}
.my-modal button {
background-color: rgba(0, 0, 0, 0.308);
justify-self: center;
border: none;
border-radius: 5px;
width: fit-content;
padding: 10px;
}

@ -0,0 +1,5 @@
/* Copyright © 2023 Entreprise SkamKraft */
.modal-disable::backdrop {
background-color: rgba(0, 0, 0, 0.493);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 B

After

Width:  |  Height:  |  Size: 318 B

@ -0,0 +1,18 @@
<!-- Copyright © 2023 Entreprise SkamKraft -->
<nav class="nav-nav">
<div class="nav-brand">
<img src="assets/logo/logoblancnotext.png" />
</div>
<ul class="nav-links">
<li class="nav-link smooth" id="contracts-link">Contracts</li>
<li class="nav-link smooth" id="systems-link">System</li>
<li class="nav-link smooth" id="ships-link">Ships</li>
<li class="nav-link smooth" id="signin-link">Sign in</li>
<li class="nav-link smooth" id="signup-link">Sign up</li>
</ul>
</nav>
<main id="block-content"></main>
<div id="test"></div>
<footer>
<p>Skamcraft Sarl</p>
</footer>

@ -0,0 +1,5 @@
<!-- Copyright © 2023 Entreprise SkamKraft -->
<div class="container smooth">
<p class="con-title">Bienvenue sur SkamCraft</p>
<p class="con-content">Application client pour l'API Space Tarders.</p>
</div>

@ -0,0 +1,10 @@
<!-- Copyright © 2023 Entreprise SkamKraft -->
<div class="container smooth">
<p class="con-title">Login</p>
<input type="text" placeholder="agent token">
<div class="grp-btn">
<button id="valid">Validate</button>
<button>Cancel</button>
</div>
</div>

@ -0,0 +1,7 @@
<!-- Copyright © 2023 Entreprise SkamKraft -->
<div class="my-modal">
<p class="modal-title">Bienvenue dans cet modal</p>
<div id="timer"></div>
<button id="ok">OK</button>
</div>

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/ui.css">
<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>
</head>
<body>
</body>
</html>

@ -1,41 +0,0 @@
class renderer {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.waypoints = [];
this.ships = [];
}
drawSystem() {
const canvas = document.getElementById("canvas");
let w = canvas.width;
let h = canvas.height;
const ctx = canvas.getContext("2d");
this.waypoints.forEach(waypoint => {
switch (waypoint.type) {
case "PLANET":
drawWaypoint(waypoint, ctx, w/2, h/2, 'green');
break;
case "ASTEROID":
drawWaypoint(waypoint, ctx, w/2, h/2, 'blue');
break;
case "GAS_GIANT":
drawWaypoint(waypoint, ctx, w/2, h/2, 'red');
break;
}
});
}
drawShips() {
}
drawWaypoint(wayPoint, ctx, w, h, color) {
ctx.beginPath();
ctx.fillStyle = color;
ctx.arc(wayPoint.x/offset.x + w, wayPoint.y/offset.y + h, 1, 0, 2 * Math.PI);
ctx.fill();
}
}

@ -0,0 +1,6 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
import tests from "./test/tests.js";
tests.modal();

@ -1,85 +0,0 @@
let token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiQU5OTk5VTEFYMTIyNSIsInZlcnNpb24iOiJ2Mi4xLjEiLCJyZXNldF9kYXRlIjoiMjAyMy0xMS0wNCIsImlhdCI6MTcwMDIyNDU5MSwic3ViIjoiYWdlbnQtdG9rZW4ifQ.r05mWtD5FjC4s6Td-ycmHdzL7C2s75lz3q7OBmWeCqUUZ1ejPsRGQRWJDPmIh1kAqO4D9FFs3GCTPZUn1KsnQ-xmDvsIi_mqC1gJV-Q0irI7gwfsGXbfLaVCXo-Q98C_QWRh-O_xkrbhJkCcvnwdEhZm7FnZ3PL4XXKrG0XNa98JrnmG0qlz0cv8V9Q0sSIwXZbvA9BrhuV8PK7_YzPc6LZuNqgPeKiX_B-tSIHHl6Sr1EzuydnczmuS-xKQnbhmcqnpaCXzQmJr7tA8KLgu70KqpPCvA8AI6PLmBlvPWtZ20RdzezqlBh6S9SrBzQ9R0zr_9RyJxq28ws2jnHpVPw";
let offset = {
x: 10,
y: 10
};
function initGame() {
const settings = {
async: true,
crossDomain: true,
url: 'https://api.spacetraders.io/v2/register',
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
},
processData: false,
data: '{\n "faction": "COSMIC",\n "symbol": "ANNNNulax1225",\n "email": ""\n}'
};
$.ajax(settings).done(function (response) {
console.log(response);
});
}
function getAgent() {
const settings = {
async: true,
crossDomain: true,
url: 'https://api.spacetraders.io/v2/my/agent',
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`
}
};
$.ajax(settings).done(function (reponse) {
$('.main-window').prepend(`
<article class="agent-card">
<p class="account">${reponse.data.accountId}</p>
<p class="symbol">${reponse.data.symbol}</p>
<p class="headquarters">${reponse.data.headquarters}</p>
<p class="credits">${reponse.data.credits}</p>
<p class="startingFaction">${reponse.data.startingFaction}</p>
<p class="shipCount">${reponse.data.shipCount}</p>
</article>
`);
let metaSystem = reponse.data.headquarters.split("-");
getSystem(metaSystem[0] + "-" + metaSystem[1]);
});
}
function getWayPoint(wayPoint) {
const settings = {
async: true,
crossDomain: true,
url: `https://api.spacetraders.io/v2/systems/systemSymbol/waypoints/waypointSymbol`,
method: 'GET',
headers: {
Accept: 'application/json'
}
};
$.ajax(settings).done(function (response) {
console.log(response);
});
};
function getSystem(system) {
const settings = {
async: true,
crossDomain: true,
url: `https://api.spacetraders.io/v2/systems/${system}`,
method: 'GET',
headers: {
Accept: 'application/json'
}
};
$.ajax(settings).done(function (response) {
drawSystem(response.data.waypoints);
});
}
getAgent();

@ -0,0 +1,115 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
import { SpaceTraders } from "./config.js"
export class Agent {
constructor(agent, token = "") {
this.token = token;
this.name = agent.symbol;
this.credits = agent.credits;
this.faction = agent.startingFaction;
this.hq = agent.headquarters;
this.shipsCpt = agent.shipCount;
}
get_agent_system() {
let metaSystem = this.hq.split("-");
return metaSystem[0] + "-" + metaSystem[1];
}
}
export class AgentBuilder {
static create(symbol, faction, callback, error_handler, email = "") {
const url = `${SpaceTraders.host}/register`;
$.ajax({
url: url,
method: "POST",
headers: { "Content-Type": "application/json" },
processData: false,
data: `{\n "faction": "${faction}",\n "symbol": "${symbol}",\n "email": "${email}"\n}`,
success: (reponse) => {
let agent = new Agent(reponse.data.agent, reponse.data.token)
callback(agent);
},
error: (err) => {
error_handler(["Symbol is invalid."])
}
});
}
static get(token, callback, error_handler){
const url = `${SpaceTraders.host}/my/agent`;
$.ajax({
url: url,
method: "GET",
headers: {
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
success: (reponse) => {
let agent = new Agent(reponse.data, token);
callback(agent);
},
error: (err) => {
error_handler(["Token invalide."]);
}
});
}
static get_public(symbol, callback) {
const url = `${SpaceTraders.host}/agents/${symbol}`;
$.ajax({
url: url,
method: "GET",
headers: {
Accept: "application/json"
},
success: (reponse) => {
let agent = new Agent(reponse.data);
callback(agent);
},
});
}
static list(limit, page, callback, agents = []) {
const url = `${SpaceTraders.host}/agents`;
const data = { limit, page };
$.ajax({
url: url,
method: "GET",
headers: {
Accept: "application/json"
},
data: data,
success: (reponse) => {
reponse.data.forEach(agent => {
agents.push(new Agent(agent));
});
callback(agents, reponse.meta);
},
});
}
static list_all(callback) {
this.list(20, 1, (agents, meta) => {
let maxPage = meta.total / 20;
this.#r_listing(2, maxPage, agents, callback);
});
}
static #r_listing(page, maxPage, agents, callback) {
if (page < maxPage) {
this.list(20, page++,() => {
setTimeout(() => {
callback(agents);
this.#r_listing(page++, maxPage, agents, callback);
}, 1000);
}, agents);
} else {
callback(agents);
}
}
}

@ -0,0 +1,7 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
export const SpaceTraders = {
host: "https://api.spacetraders.io/v2",
limit_max: 20,
}

@ -0,0 +1,131 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
import { SpaceTraders } from "./config.js";
import { Position } from "../commun/position.js";
class Market {
constructor(market) {
this.symbol = market.symbol;
this.exports = market.exports;
this.imports = market.imports;
this.exchange = market.exchange;
this.transctions = market.transctions;
this.trade_goods = market.tradeGoods;
}
has_export(market_export) {
}
list_exports(callback) {
}
has_import(market_import) {
}
list_import(callback) {
}
}
export class Planet {
constructor(waypoint) {
this.name = waypoint.symbol;
this.type = waypoint.type;
this.system = waypoint.systemSymbol;
this.position = new Position(waypoint.x, waypoint.y);
this.moons = waypoint.orbitals;
this.orbits = waypoint.orbits;
this.faction = waypoint.faction;
this.traits = waypoint.traits;
this.dangers = waypoint.modifiers;
this.discovery = waypoint.char;
this.is_under_construction = waypoint.isUnderConstruction;
}
get_market(callback, error_handler) {
const url = `${SpaceTraders.host}/systems/${this.system}/waypoints/${this.name}/market`;
$.ajax({
url: url,
method: "GET",
success: (reponse) => {
let market = new Market(reponse.data);
callback(market);
},
error: (err) => {
error_handler("Market not found");
}
});
}
is_type(type) {
return this.type === type ? true : false;
}
is_discovered() {
return this.discovery.length > 0 ? true : false;
}
}
export class PlanetBuilder {
static parse_system_name(name) {
return name.split("-").slice(0, 2).join("-");
}
static get(name, callback, error_handler) {
let system = PlanetBuilder.parse_system_name(name);
const url = `${SpaceTraders.host}/systems/${system}/waypoints/${name}`;
$.ajax({
url: url,
method: "GET",
success: (reponse) => {
let planet = new Planet(reponse.data);
callback(planet);
},
error: (err) => {
error_handler("Planet not found");
}
});
}
static list(system, limit, page, callback, planets = []) {
const url = `${SpaceTraders.host}/systems/${system}/waypoints`
$.ajax({
url: url,
method: "GET",
data: {
limit: limit,
page: page
},
success: (reponse) => {
reponse.data.forEach(planet => {
planets.push(new Planet(planet));
});
callback(planets, reponse.meta);
}
});
}
static list_all(system, callback) {
this.list(system, 20, 1, (planets, meta) => {
let maxPage = meta.total / 20;
this.#r_listing(system, 2, maxPage, planets, callback);
});
}
static #r_listing(system, page, maxPage, planets, callback) {
if (page < maxPage) {
this.list(20, page++,() => {
setTimeout(() => {
callback(planets);
this.#r_listing(system, page++, maxPage, planets, callback);
}, 1000);
}, planets);
} else {
callback(planets);
}
}
}

@ -0,0 +1,3 @@
export class System {
}

@ -0,0 +1,84 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
import { AgentBuilder } from '../api/agent.js'
import Strategie from '../commun/strategie.js';
let strategies = {
register: [
{
name: "symbol",
validations: [
"required",
"max_length|14"
]
},
{
name: "faction",
validations: [
"required"
]
}
],
login: [
{
name: "token",
validations: [
"required"
]
}
]
}
export class Auth {
constructor(store = false) {
this.store = store;
this.validated = () => {};
this.error_handler = () => {};
this.strategies = strategies;
}
done(validated) {
this.validated = validated;
return this;
}
fail(error_handler) {
this.error_handler = error_handler;
return this;
}
async login(token) {
let validateur = new Strategie(this.strategies.login);
validateur.validate("token", token);
if (validateur.errors.length > 0) this.error_handler(validateur.errors);
else {
if (this.store) localStorage.setItem("token", token);
await AgentBuilder.get(token, this.validated, this.error_handler);
}
}
async relog() {
if(this.#is_login()) await AgentBuilder.get(localStorage.getItem("token"), this.validated, this.error_handler);
else return false;
}
async register(new_agent) {
let validateur = new Strategie(this.strategies.register);
validateur.validate("symbol", new_agent.symbol);
validateur.validate("faction", new_agent.faction);
if (validateur.errors.length > 0) this.error_handler(validateur.errors);
else {
await AgentBuilder.create(new_agent.symbol, new_agent.faction, (agent) => {
if (this.store) localStorage.setItem("token", agent.token);
this.validated(agent);
}, this.error_handler);
}
}
#is_login() {
if (this.store && localStorage.getItem("token")) {
return true
}
return false
}
}

@ -0,0 +1,14 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
export class Initialzer {
constructor(UI) {
this.UI = UI;
}
init_menu_link(tag, template) {
this.UI.add_event(tag, "click", () => {
this.UI.render(`templates/${template}`);
})
}
}

@ -0,0 +1,13 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
export class Position {
constructor(x, y) {
this.x = x;
this.y = y;
}
get_canvas_pos(w, h) {
return new Position(x - w/2, y - h/2)
}
}

@ -0,0 +1,51 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
export default class Strategie {
constructor(strategie) {
this.strategie = strategie;
this.errors = [];
}
validate(name, input) {
this.strategie.forEach(input_strat => {
if(input_strat.name === name) input_strat.validations.forEach((validation) => {
let args = validation.split("|");
switch (args[0]) {
case "required":
this.#test(Strategie.#required(input), `${name} is required.`);
break;
case "max_length":
this.#test(Strategie.#max_length(input, parseInt(args[1])), `${name} must have a max lenght of ${args[1]}.`);
break;
case "min_length":
this.#test(Strategie.#min_length(input, parseInt(args[1])), `${name} must have a min lenght of ${args[1]}`);
break;
}
});
});
}
#test(test, error) {
if(!test) this.errors.push(error);
}
static #valide_email(input) {
}
static #min_length(input, length) {
if(input.length < length) return false;
return true;
}
static #max_length(input, length) {
if(input.length > length) return false;
return true;
}
static #required(input) {
if (input === undefined || input === null || input === "") return false;
return true;
}
}

@ -0,0 +1,39 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
export class Modal {
constructor(name, template_engine, tag = "#block-content") {
this.name = name;
this.template_engine = template_engine;
this.tag = tag;
this.modal_class = "";
}
render(template) {
this.template_engine.get_template((reponse) => {
$(this.tag).prepend(`
<dialog id="${this.name}" class="${this.modal_class} modal-disable">
${reponse}
</dialog>
`);
}, template);
}
on_close(callback) {
document.querySelector(`#${this.name}`).addEventListener("close", callback);
}
add_class(modal_class) {
let modal;
if(modal = $(`#${this.name}`)) modal.addClass(modal_class);
this.modal_class = `${this.modal_class} ${modal_class}`;
}
show() {
document.querySelector(`#${this.name}`).showModal();
}
close() {
document.querySelector(`#${this.name}`).close();
}
}

@ -0,0 +1,37 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
export class TemplateEngine {
constructor(path) {
this.templatePath = path;
}
render(template) {
this.get_template((reponse) => {
$('body').html(reponse);
this.get_template((reponse) => {
$("#block-content").html(reponse);
}, template)
});
}
frag_load(tag, template) {
this.get_template((reponse) => {
$(tag).html(reponse);
}, template);
}
get_template(callback, template = "") {
let url = template === "" ? `${this.templatePath}/template.html`: `${this.templatePath}/${template}`;
$.ajax(url,{
async: false,
method: "GET",
success: callback,
error: (err) => {
console.log(err);
}
});
}
add_event(tag, action, callback) {
$("body").on(action, tag, callback);
}
}

@ -0,0 +1,59 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
export class Timer {
constructor(time, step, unit = "s") {
this.passed_time = 0;
this.time = time;
this.step = step;
this.continue = true;
switch (unit) {
case "ms":
this.unit = 1;
break;
case "s":
this.unit = 1000;
break;
case "m":
this.unit = 60000;
break;
case "h":
this.unit = 3600000;
break;
default:
this.unit = 1;
break;
}
}
on(action, callback) {
switch(action) {
case "end":
this.end_callback = callback;
break;
case "step":
this.step_callback = callback;
break;
}
}
start() {
this.continue = true;
this.#time_step();
}
stop() {
this.continue = false;
this.passed_time = 0;
}
#time_step() {
if (this.passed_time < this.time && this.continue) {
if (this.step_callback) this.step_callback(this.passed_time);
this.passed_time += this.step;
setTimeout(() => {
this.#time_step()
}, this.step*this.unit);
} else {
if (this.end_callback) this.end_callback(this.time);
}
}
}

@ -0,0 +1,105 @@
// Copyright © 2023 Entreprise SkamKraft
'use strict';
import { Timer } from "../skama_code/ui/timer.js";
import { Modal } from "../skama_code/ui/modal.js";
import { TemplateEngine } from "../skama_code/ui/templeting_engine.js";
import { Initialzer } from "../skama_code/commun/initialzer.js ";
import { AgentBuilder } from "../skama_code/api/agent.js";
import { Auth } from "../skama_code/auth/auth.js";
import { PlanetBuilder } from "../skama_code/api/planet.js";
let temp_path = "html";
let token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiSEFSRElDSyIsInZlcnNpb24iOiJ2Mi4xLjQiLCJyZXNldF9kYXRlIjoiMjAyMy0xMi0wMiIsImlhdCI6MTcwMjY2Mjc2Mywic3ViIjoiYWdlbnQtdG9rZW4ifQ.PrvaOz3W79acq6RoxryMW53PRRz824_AM0VGLwfXCOsGCOCAIY-rn6-bZTOnLAtp4xPSDqEk4c38oWYAWW59p0iMDDLpur6ONnjT0RjjsQS9zr5BByfBpP36CT23IZSSzk3XxGrFolHJAyU3K1liYfNbsPuNTXlkHGNHq6yMqH4ZQUPFsXEsCkg9cUynkdLw3C39SvWhtJ89oblj_8tQp2k8dxhZemepuXtiI51eFMpv8A0WRAi7pVYo_ajJujY9QDLYn_m5hDZWTlQMIstjPaDl99p2IMweIMO2Q2G-0lKiWQ4sl6VW5tuVrz1HLYU6kyMjFQWNn6kFDE7LWMTrfw";
let tests = {
timer: function() {
let timer = new Timer(1, 0.1666, "m");
timer.on("step", (time) => {
console.log(time);
})
timer.on("end", () => {
console.log("pattes fini");
});
timer.start();
},
render_template: function() {
let UI = new TemplateEngine(temp_path);
let initer = new Initialzer(UI);
UI.render("templates/home.html");
UI.frag_load("#test", "templates/login.html");
$(document).ready(() => {
initer.init_menu_link("#contracts-link", "contracts.html");
initer.init_menu_link("#ships-link", "ships.html");
initer.init_menu_link("#systems-link", "systems.html");
initer.init_menu_link("#signup-link", "register.html");
initer.init_menu_link("#signin-link", "login.html");
initer.init_menu_link(".nav-brand", "home.html");
});
},
authentication: function() {
let auth = new Auth(true);
auth.done((agent) => {
console.log(agent);
}).fail((errs) => {
errs.forEach(err => {
console.log(err);
});
});
auth.login(token);
auth.relog();
//auth.register({
// symbol: "lkdsjfsjdlfjlk",
// faction: "COSMIC"
//});
},
modal: function() {
let template_engine = new TemplateEngine(temp_path);
let timer = new Timer(60, 1, "s");
timer.on("step", (time) => {
$("#timer").html(`
<p>${time}</p>
`);
});
template_engine.render("templates/login.html");
let modal = new Modal("test-modal", template_engine);
modal.add_class("ext-modal")
modal.render("templates/test_modal.html");
template_engine.add_event("#valid", "click", () => {
modal.show();
timer.start();
});
template_engine.add_event("#ok", "click", () => {
modal.close();
timer.stop();
});
},
get_planet: function() {
PlanetBuilder.get("X1-TT23-FF1E", (planet) => {
console.log(planet);
}, (err) => {
console.log(err);
});
},
get_all_planets: function() {
PlanetBuilder.list_all("X1-AG10", (planets) => {
console.log(planets);
});
},
get_all_agents: function() {
AgentBuilder.list_all((agents) => {
console.log(agents);
});
}
}
export default tests;

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../css/style.css">
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="../js/main.js"></script>
<title>Space traders</title>
</head>
<body>
<main class="main-window">
<input id="token" type="text">
<br>
<canvas id="canvas"></canvas>
</main>
</body>
</html>

@ -1 +0,0 @@
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiQU5OTk5VTEFYMTIyNSIsInZlcnNpb24iOiJ2Mi4xLjEiLCJyZXNldF9kYXRlIjoiMjAyMy0xMS0wNCIsImlhdCI6MTcwMDIyNDU5MSwic3ViIjoiYWdlbnQtdG9rZW4ifQ.r05mWtD5FjC4s6Td-ycmHdzL7C2s75lz3q7OBmWeCqUUZ1ejPsRGQRWJDPmIh1kAqO4D9FFs3GCTPZUn1KsnQ-xmDvsIi_mqC1gJV-Q0irI7gwfsGXbfLaVCXo-Q98C_QWRh-O_xkrbhJkCcvnwdEhZm7FnZ3PL4XXKrG0XNa98JrnmG0qlz0cv8V9Q0sSIwXZbvA9BrhuV8PK7_YzPc6LZuNqgPeKiX_B-tSIHHl6Sr1EzuydnczmuS-xKQnbhmcqnpaCXzQmJr7tA8KLgu70KqpPCvA8AI6PLmBlvPWtZ20RdzezqlBh6S9SrBzQ9R0zr_9RyJxq28ws2jnHpVPw
Loading…
Cancel
Save