diff --git a/.gitignore b/.gitignore index e69de29..6cae44f 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/.vs/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f3a291 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d85088f --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +DO NOT USE THIS CODE OR LOOK AT IT IF YOU ARE NOT ALLOWED TO +IF YOU DO YOU CAN USE OR TEACH THE KNOWLEAGE YOU ACQUEIRED. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f624a3 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Skamcraft + +## Start +* Start with live server in VsCode to get full functionnality. +* Start with php : +``` bash + cd /.../Skamcraft + php -S 127.0.0.1:80 +``` + +## Norm +* ``` ; ``` at the end of each line. +* snack_case for functions and variables. +* UpperCamelCase for Classes. +* all in english. diff --git a/img/procurement.png b/assets/contracts/procurement.png similarity index 100% rename from img/procurement.png rename to assets/contracts/procurement.png diff --git a/img/shuttle.png b/assets/contracts/shuttle.png similarity index 100% rename from img/shuttle.png rename to assets/contracts/shuttle.png diff --git a/img/transportation.png b/assets/contracts/transportation.png similarity index 100% rename from img/transportation.png rename to assets/contracts/transportation.png diff --git a/fonts/m42.TTF b/assets/fonts/m42.TTF similarity index 100% rename from fonts/m42.TTF rename to assets/fonts/m42.TTF diff --git a/assets/img/background.jpg b/assets/img/background.jpg new file mode 100644 index 0000000..5d0683d Binary files /dev/null and b/assets/img/background.jpg differ diff --git a/assets/logo/Offre.png b/assets/logo/Offre.png new file mode 100644 index 0000000..70230f5 Binary files /dev/null and b/assets/logo/Offre.png differ diff --git a/img/Skamkraft.png b/assets/logo/logoblanc.png similarity index 100% rename from img/Skamkraft.png rename to assets/logo/logoblanc.png diff --git a/assets/logo/logoblancnotext.png b/assets/logo/logoblancnotext.png new file mode 100644 index 0000000..a48c638 Binary files /dev/null and b/assets/logo/logoblancnotext.png differ diff --git a/assets/logo/logonoir.png b/assets/logo/logonoir.png new file mode 100644 index 0000000..7d4783c Binary files /dev/null and b/assets/logo/logonoir.png differ diff --git a/assets/planets/planetproto.png b/assets/planets/planetproto.png new file mode 100644 index 0000000..3d500b4 Binary files /dev/null and b/assets/planets/planetproto.png differ diff --git a/assets/ressources/ANTIMATTER.png b/assets/ressources/ANTIMATTER.png new file mode 100644 index 0000000..bd8dffe Binary files /dev/null and b/assets/ressources/ANTIMATTER.png differ diff --git a/assets/ressources/medkit.png b/assets/ressources/medkit.png new file mode 100644 index 0000000..4491d9b Binary files /dev/null and b/assets/ressources/medkit.png differ diff --git a/assets/spaceships/spaceship.png b/assets/spaceships/spaceship.png new file mode 100644 index 0000000..acc67df Binary files /dev/null and b/assets/spaceships/spaceship.png differ diff --git a/assets/spaceships/spaceshiporbits.png b/assets/spaceships/spaceshiporbits.png new file mode 100644 index 0000000..344a342 Binary files /dev/null and b/assets/spaceships/spaceshiporbits.png differ diff --git a/assets/systems/galaxie1.png b/assets/systems/galaxie1.png new file mode 100644 index 0000000..e40e2b2 Binary files /dev/null and b/assets/systems/galaxie1.png differ diff --git a/css/animation.css b/css/animation.css new file mode 100644 index 0000000..3207215 --- /dev/null +++ b/css/animation.css @@ -0,0 +1,15 @@ +/* Copyright © 2023 Entreprise SkamKraft */ + + +.ext-modal[open] { + animation: myFadeIn 2.0s ease normal; +} + +@keyframes myFadeIn{ + from { + bottom: 100%; + } + to { + bottom: 0%; + } +} \ No newline at end of file diff --git a/css/auth.css b/css/auth.css deleted file mode 100644 index 5bb0acb..0000000 --- a/css/auth.css +++ /dev/null @@ -1,165 +0,0 @@ -/* Copyright © 2023 Entreprise SkamCraft */ - -/* @font-face { - font-family: M42; - src: url(/fonts/m42.TTF); -} */ - -* { - font-family: "Montserrat", sans-serif; - font-size: 16px; - color: #ffffff; - margin: 0; - padding: 0; - text-decoration: none; - list-style: none; -} - -body { - background-color: #212121; -} - -.logo { - display: flex; - justify-content: center; - align-items: center; -} - -.logo img { - width: 80px; - padding: 20px; -} - -.logo h4 { - font-size: 30px; -} - -.form { - --input-focus: #a37b03; - --font-color: #323232; - --font-color-sub: #666666; - --bg-color: beige; - --main-color: black; - padding: 20px; - background: #eab308; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - text-align: center; - gap: 20px; - border-radius: 20px; - border: 2px solid var(--main-color); - box-shadow: 4px 4px var(--main-color); - width: 20%; - margin: auto; - margin-top: 10%; -} - -.title { - color: var(--font-color); - font-weight: 900; - font-size: 20px; -} - -.title span { - color: var(--font-color-sub); - font-weight: 600; - font-size: 17px; -} - -.input { - width: 250px; - height: 40px; - border-radius: 5px; - border: 2px solid var(--main-color); - background-color: var(--bg-color); - box-shadow: 4px 4px var(--main-color); - font-size: 15px; - font-weight: 600; - color: var(--font-color); - padding: 5px 10px; - outline: none; -} - -.input::placeholder { - color: var(--font-color-sub); - opacity: 0.8; -} - -.input:focus { - border: 2px solid var(--input-focus); -} - -.select * { - color: var(--main-color); -} - -.button-confirm { - width: 120px; - height: 40px; - border-radius: 5px; - border: 2px solid var(--main-color); - background-color: var(--bg-color); - box-shadow: 4px 4px var(--main-color); - font-size: 17px; - font-weight: 600; - color: var(--font-color); - cursor: pointer; -} - -.button-confirm:active { - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.link-connection { - position: relative; - display: inline-block; -} - -.link-connection:hover { - cursor: pointer; - text-underline-offset: 2px; - text-decoration: underline; - transform: scale(1.1); - transition: 0.3s; -} - -.alert { - position: fixed; - left: 50%; - transform: translateX(-50%); - bottom: 10%; - border-radius: 0.5rem; - border-width: 0.25rem; - border-color: #ef4444; - background-color: #fee2e2; - padding: 1rem; - width: 300px; - max-width: 90%; - text-align: center; -} - -.alert-inner { - display: flex; - align-items: center; - gap: 0.5rem; - color: #ef4444; -} - -.icon { - height: 1.25rem; - width: 1.25rem; - fill: #d94848; -} - -.message { - color: #d94848; - font-weight: 500; -} - -.content { - margin-top: 0.5rem; - font-size: 0.875rem; - color: #d94848; -} diff --git a/css/global.css b/css/global.css deleted file mode 100644 index 5296ef1..0000000 --- a/css/global.css +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright © 2023 Entreprise SkamCraft */ - -* { - font-family: "Inter", sans-serif; - box-sizing: border-box; - overflow: hidden; - background-color: #272727; -} - -body, -html { - height: 100%; - display: flex; - flex-direction: column; -} - -/* Menu */ -.menu { - display: flex; - align-items: center; - justify-content: space-between; -} - -.title-section { - color: white; - display: flex; - align-items: center; - padding-left: 10px; -} - -.title-section img { - max-width: 80px; - max-height: 50px; -} - -.page-change-button { - padding-left: 10px; -} - -button { - margin: 2px; - color: black; - background-color: white; - border: 2px solid white; - border-radius: 10px; -} - -button:hover { - border-color: #eab308; - background-color: #eab308; - transition: all 1s; -} - -main { - flex: 1; -} - -#credits { - background-color: white; - border: 2px solid white; - border-radius: 10px; - color: black; -} - -/* Footer */ -footer { - color: white; -} - -footer p { - display: flex; - justify-content: center; - margin-bottom: 0px; -} - -/* Modal */ -.modal-content { - color: white; -} - -#exampleModal { - color: white; - background-color: rgba(255, 255, 255, 0.1) -} - -#modal-footer { - background-color: #272727; -} - -#status { - color: orange; -} - -#revenu { - color: white -} \ No newline at end of file diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..1503b8f --- /dev/null +++ b/css/style.css @@ -0,0 +1,195 @@ +/* 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-image: url("/assets/img/background.jpg"); + font-family: 'M42'; + font-size: 7px; + margin: 0px; + padding: 0px; +} + +/* Main */ +.container { + color: white; + background-color: rgba(0, 0, 0, 0.726); + display: flex; + margin: 10px; + width: fit-content; + margin: auto; + margin-top: 10px; margin-bottom: 30px; + flex-direction: column; + align-items: center; + border: 4px solid rgba(68, 68, 68, 0.575); +} + +.max-container { + background-color: rgba(0, 0, 0, 0.726); + color: white; + display: flex; + margin: 10px; + width: 95%; + margin: auto; + margin-top: 10px; margin-bottom: 30px; + flex-direction: column; + align-items: center; + border: 4px solid rgba(68, 68, 68, 0.575); +} + +.con-title { + font-size: 15px; + border-bottom: 2px solid black; +} + +.btn { + padding: 10px; + font-size: 8px; + font-family: 'M42'; + color: white; + border: none; + border-radius: 10px; +} + +.btn-val { + background-color: rgba(0, 0, 255, 0.637); +} + +.btn-cancel { + background-color: rgba(255, 0, 0, 0.699); +} + +/*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; +} + +.stats { + color: white; +} + +/* General */ +.smooth { + padding: 5px; + padding-left: 10px; + padding-right: 10px; + border-radius: 5px; +} + +.in-big { + font-family: 'M42'; + font-size: 6px; + padding: 5px; + width: 100%; + margin-bottom: 10px; + border-radius: 5px; + border: none; +} + +.errors p { + background-color: rgba(255, 56, 56, 0.733); + border: 3px solid rgb(255, 111, 111); + padding: 10px; + color: white; + border-radius: 5px; + text-align: center; +} + +/* 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; +} + +.show-token { + width: fit-content; + border: 2px solid black; + border-radius: 10px; + padding: 30px; + font-size: 5px; + white-space:pre-wrap; + word-break:break-word; +} + +.my-modal #timer { + text-align: center; + border: 1px solid black; + border-radius: 10px; + width: 10%; + padding: 5px; + margin-bottom: 10px; +} + +#canvas { + border-radius: 10px; +} \ No newline at end of file diff --git a/css/ui.css b/css/ui.css new file mode 100644 index 0000000..085f1e5 --- /dev/null +++ b/css/ui.css @@ -0,0 +1,11 @@ +/* Copyright © 2023 Entreprise SkamKraft */ + +#block-content { + margin: 0; + padding: 0; +} + +.modal-disable::backdrop { + background-color: rgba(0, 0, 0, 0.493); +} + diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..b78bc3c Binary files /dev/null and b/favicon.ico differ diff --git a/html/template.html b/html/template.html new file mode 100644 index 0000000..9821bca --- /dev/null +++ b/html/template.html @@ -0,0 +1,16 @@ + + +
+ diff --git a/html/templates/auth/login.html b/html/templates/auth/login.html new file mode 100644 index 0000000..81974a4 --- /dev/null +++ b/html/templates/auth/login.html @@ -0,0 +1,11 @@ + + +
+

Login

+ +
+ + +
+
+
\ No newline at end of file diff --git a/html/templates/auth/login_modal.html b/html/templates/auth/login_modal.html new file mode 100644 index 0000000..37f30ac --- /dev/null +++ b/html/templates/auth/login_modal.html @@ -0,0 +1,9 @@ + + +
+ +
+ + +
+
diff --git a/html/templates/auth/reg.html b/html/templates/auth/reg.html new file mode 100644 index 0000000..4d68dcd --- /dev/null +++ b/html/templates/auth/reg.html @@ -0,0 +1,12 @@ + + +
+

New Agent

+ + +
+ + +
+
+
\ No newline at end of file diff --git a/html/templates/auth/reg_modal.html b/html/templates/auth/reg_modal.html new file mode 100644 index 0000000..fa72c87 --- /dev/null +++ b/html/templates/auth/reg_modal.html @@ -0,0 +1,10 @@ + + +
+ +

+
+ + +
+
diff --git a/html/templates/home.html b/html/templates/home.html new file mode 100644 index 0000000..167aa3b --- /dev/null +++ b/html/templates/home.html @@ -0,0 +1,5 @@ + +
+

Bienvenue sur SkamCraft

+

Application client pour l'API Space Tarders.

+
\ No newline at end of file diff --git a/html/templates/systems/system.html b/html/templates/systems/system.html new file mode 100644 index 0000000..eb4ed2f --- /dev/null +++ b/html/templates/systems/system.html @@ -0,0 +1,5 @@ + +
+

+ +
\ No newline at end of file diff --git a/html/templates/systems/systems.html b/html/templates/systems/systems.html new file mode 100644 index 0000000..f040c78 --- /dev/null +++ b/html/templates/systems/systems.html @@ -0,0 +1,5 @@ + +
+

Systems

+ +
\ No newline at end of file diff --git a/img/contrat.jpg b/img/contrat.jpg deleted file mode 100644 index 2f9b7dc..0000000 Binary files a/img/contrat.jpg and /dev/null differ diff --git a/index.html b/index.html index 4978638..bd71585 100644 --- a/index.html +++ b/index.html @@ -1,59 +1,15 @@ - - - - - - - - - - - - - - - - SkamCraft - - - - - - - -
- - - -
- - - - - \ No newline at end of file + + + + + + + + + + + + + + diff --git a/js/controllers/contracts.js b/js/controllers/contracts.js new file mode 100644 index 0000000..e69de29 diff --git a/js/controllers/home.js b/js/controllers/home.js new file mode 100644 index 0000000..9bafb7f --- /dev/null +++ b/js/controllers/home.js @@ -0,0 +1,9 @@ +import menu_mod from "./menu_mod.js"; + +export default function home(temp_engine) { + temp_engine.after_render(menu_mod); + temp_engine.render("templates/home.html"); +} + + + diff --git a/js/controllers/login.js b/js/controllers/login.js new file mode 100644 index 0000000..9761989 --- /dev/null +++ b/js/controllers/login.js @@ -0,0 +1,54 @@ +import { Modal } from "../skama_code/ui/modal.js"; +import { Auth } from "../skama_code/auth/auth.js"; +import { My } from "../skama_code/api/agent.js"; +import home from "./home.js"; +import menu_mod from "./menu_mod.js"; + +export default function login(temp_engine) { + let auth = new Auth(true); + let modal = new Modal("login-modal", temp_engine); + + function render_login() { + temp_engine.render(`templates/auth/login.html`); + modal.load("templates/auth/login_modal.html") + } + + modal.add_class("ext-modal"); + temp_engine.after_render(menu_mod); + + render_login(); + + temp_engine.add_event("#ok", "click", () => { + home(temp_engine); + }); + + temp_engine.add_event("#forget_login", "click", () => { + My.agent = null; + auth.unload_token(); + modal.close(); + render_login(); + }); + + temp_engine.add_event("#val", "click", () => { + let token = $("#in-token").val(); + auth.login(token); + }); + + temp_engine.add_event("#cancel", "click", () => { + $("#in-token").val(""); + }); + + auth.done((agent) => { + modal.show(); + My.agent = agent; + }).fail((errs) => { + $(".errors").html(""); + errs.forEach(err => { + $(".errors").append(` +

${err}

+ `); + }); + }); + + auth.relog(); +} \ No newline at end of file diff --git a/js/controllers/menu_mod.js b/js/controllers/menu_mod.js new file mode 100644 index 0000000..6287759 --- /dev/null +++ b/js/controllers/menu_mod.js @@ -0,0 +1,45 @@ +import { My } from "../skama_code/api/agent.js"; +import login from "./login.js"; +import reg from "./reg.js"; +import home from "./home.js"; +import { systems } from "./systems.js"; + +function init_menu(temp_engine) { + temp_engine.add_event("#reg-link", "click", () => { + reg(temp_engine); + }); + temp_engine.add_event("#login-link", "click", () => { + login(temp_engine); + }); + temp_engine.add_event("#systems-link", "click", () => { + systems(temp_engine); + }) + temp_engine.add_event(".nav-brand", "click", () => { + home(temp_engine); + }); +} + +function loged_links() { + $(".nav-links").prepend(` + + + `); +} + +function show_stats() { + $(".stats").html(` +

Agent name : ${My.agent.name}

+

Credits : ${My.agent.credits}

+

Ships : ${My.agent.ships_cpt}

+

Faction : ${My.agent.faction}

+

HQ : ${My.agent.hq}

+ `); +} + +export default function menu_mod(temp_engine) { + init_menu(temp_engine); + if(My.agent) { + show_stats(); + loged_links(); + } +} \ No newline at end of file diff --git a/js/controllers/reg.js b/js/controllers/reg.js new file mode 100644 index 0000000..a8b8425 --- /dev/null +++ b/js/controllers/reg.js @@ -0,0 +1,64 @@ +import { Modal } from "../skama_code/ui/modal.js"; +import { Auth } from "../skama_code/auth/auth.js"; +import { My } from "../skama_code/api/agent.js"; +import home from "./home.js"; +import menu_mod from "./menu_mod.js"; + +export default function reg(temp_engine) { + let active = false; + let auth = new Auth(true); + let modal = new Modal("reg-modal", temp_engine); + + function render_reg() { + temp_engine.render(`templates/auth/reg.html`); + modal.load("templates/auth/reg_modal.html") + } + + modal.add_class("ext-modal"); + temp_engine.after_render(menu_mod); + + render_reg(); + + temp_engine.add_event("#ok", "click", () => { + home(temp_engine); + }); + + temp_engine.add_event("#forget_reg", "click", () => { + My.agent = null; + auth.unload_token(); + modal.close(); + render_reg(); + }); + + temp_engine.add_event("#val", "click", () => { + if (!active) { + active = true; + let name = $("#in-name").val(); + let faction = $("#in-faction").val(); + auth.register({ + name: name, + faction: faction + }); + } + }); + + temp_engine.add_event("#cancel", "click", () => { + $("#in-name").val(""); + $("#in-faction").val(""); + }); + + auth.done((agent) => { + $(".show-token").text(agent.token); + modal.show(); + My.agent = agent; + active = false; + }).fail((errs) => { + $(".errors").html(""); + errs.forEach(err => { + $(".errors").append(` +

${err}

+ `); + }); + active = false; + }); +} \ No newline at end of file diff --git a/js/controllers/system.js b/js/controllers/system.js new file mode 100644 index 0000000..915227f --- /dev/null +++ b/js/controllers/system.js @@ -0,0 +1,100 @@ +import { SystemBuilder } from "../skama_code/api/system.js"; +import { Position } from "../skama_code/commun/position.js"; +import menu_mod from "./menu_mod.js" + +let canvas; +let last_target; + +let offset = { + x: 2, + y: 2 +}; +let max = 100; +let w = (window.innerWidth/10)*9; +let h = (window.innerHeight/4)*3; + +function animate() { + canvas.renderAll(); + setTimeout(animate, 1000); +} + +function draw_planet(planet) { + let shadow = new fabric.Shadow({ + color: "white", + blur: 5, + offsetX: 0, + offsetY: 0, + }); + + fabric.Image.fromURL('/assets/planets/planetproto.png', function(img_planet) { + //FABRICJS + img_planet.set({ + selectable: false, + shadow: shadow, + left: planet.position.x/offset.x + w/2, + top: planet.position.y/offset.y+ h/2, + name: planet.name, + type: planet.type + }); + canvas.add(img_planet); + }); +} + +function offsetOrbit(planet) { + if (planet.orbits) { + console.log("Orbits"); + let x = Math.floor(Math.random() * max - Math.random() * max); + let y = Math.floor(Math.random() * max - Math.random() * max); + planet.position.move(new Position(x, y)); + } +} + +export default function system(system, temp_engine) { + temp_engine.after_render((temp_engine) => { + $("#sys-name").text(system); + menu_mod(temp_engine); + canvas = new fabric.Canvas("canvas",{ + width: w, + height: h, + backgroundColor:"rgb(7, 18, 41)", + renderOnAddRemove: false, + hoverCursor :'pointer' + }); + SystemBuilder.get(system, (system) => { + system.list_all((planets) => { + planets.forEach(planet => { + offsetOrbit(planet); + draw_planet(planet); + }); + animate(); + }, (err) => { + console.log(err); + }); + }); + canvas.on('mouse:up', (e) => { + if(e.target.shadow.color == "red"){ + e.target.shadow.color = "white" + } + else{ + e.target.shadow.color = "red" + } + if (last_target) last_target.shadow.color = "white"; + last_target = e.target; + canvas.renderAll(); + }); + $(window).on("resize", () => { + canvas.setWidth((window.innerWidth/10)*9); + canvas.setHeight((window.innerHeight/4)*3); + canvas.renderAll(); + }); + canvas.on("mouse:wheel", (opt) => { + let scale = 1.1; + if (opt.e.deltaY < 0) { + canvas.zoomToPoint(new fabric.Point(canvas.width / 2, canvas.height / 2), canvas.getZoom() * scale); + } else if (opt.e.deltaY > 0) { + canvas.zoomToPoint(new fabric.Point(canvas.width / 2, canvas.height / 2), canvas.getZoom() / scale); + } + }); + }); + temp_engine.render("templates/systems/system.html"); +} \ No newline at end of file diff --git a/js/controllers/systems.js b/js/controllers/systems.js new file mode 100644 index 0000000..10e050f --- /dev/null +++ b/js/controllers/systems.js @@ -0,0 +1,80 @@ +import { SystemBuilder } from "../skama_code/api/system.js"; +import menu_mod from "./menu_mod.js" +import system from "./system.js" + +let canvas; +let last_target; + +let offset = { + x: 2, + y: 2 +}; +let max = 100; +let w = (window.innerWidth/10)*9; +let h = (window.innerHeight/4)*3; + +function animate() { + canvas.renderAll(); + setTimeout(animate, 1000); +} + +function draw_system(system) { + let shadow = new fabric.Shadow({ + color: "white", + blur: 5, + offsetX: 0, + offsetY: 0, + }); + + fabric.Image.fromURL('/assets/systems/galaxie1.png', function(img_planet) { + + img_planet.set({ + selectable: false, + scaleX: 0.05, + scaleY: 0.05, + shadow: shadow, + left: system.position.x/offset.x + w/2, + top: system.position.y/offset.y+ h/2, + name: system.name, + type: system.type + }); + canvas.add(img_planet); + }); +} + +export function systems(temp_engine) { + temp_engine.after_render((temp_engine) => { + menu_mod(temp_engine); + canvas = new fabric.Canvas("canvas",{ + width: w, + height: h, + backgroundColor:"rgb(7, 18, 41)", + renderOnAddRemove: false, + hoverCursor :'pointer' + }); + SystemBuilder.list_all((systems) => { + systems.forEach(system => { + draw_system(system); + }); + animate(); + }); + canvas.on('mouse:up', (e) => { + if (e.target) system(e.target.name, temp_engine); + }); + $(window).on("resize", () => { + canvas.setWidth((window.innerWidth/10)*9); + canvas.setHeight((window.innerHeight/4)*3); + canvas.renderAll(); + }); + canvas.on("mouse:wheel", (opt) => { + console.log(opt.e.clientX); + let scale = 1.1; + if (opt.e.deltaY < 0) { + canvas.zoomToPoint(new fabric.Point(opt.e.clientX / canvas.getZoom(), opt.e.clienY / canvas.getZoom()), canvas.getZoom() * scale); + } else if (opt.e.deltaY > 0) { + canvas.zoomToPoint(new fabric.Point(canvas.width / 2, canvas.height / 2), canvas.getZoom() / scale); + } + }); + }); + temp_engine.render("templates/systems/systems.html"); +} \ No newline at end of file diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..886d57b --- /dev/null +++ b/js/index.js @@ -0,0 +1,9 @@ +// Copyright © 2023 Entreprise SkamKraft +'use strict'; +import { TemplateEngine } from "./skama_code/ui/templeting_engine.js"; +import home from "./controllers/home.js"; + +let temp_engine = new TemplateEngine("html"); +home(temp_engine); + + diff --git a/js/lib/fabric.js b/js/lib/fabric.js new file mode 100644 index 0000000..f679aff --- /dev/null +++ b/js/lib/fabric.js @@ -0,0 +1 @@ +var fabric=fabric||{version:"5.3.0"};if("undefined"!=typeof exports?exports.fabric=fabric:"function"==typeof define&&define.amd&&define([],function(){return fabric}),"undefined"!=typeof document&&"undefined"!=typeof window)document instanceof("undefined"!=typeof HTMLDocument?HTMLDocument:Document)?fabric.document=document:fabric.document=document.implementation.createHTMLDocument(""),fabric.window=window;else{var jsdom=require("jsdom"),virtualWindow=new jsdom.JSDOM(decodeURIComponent("%3C!DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody%3E%3C%2Fbody%3E%3C%2Fhtml%3E"),{features:{FetchExternalResources:["img"]},resources:"usable"}).window;fabric.document=virtualWindow.document,fabric.jsdomImplForWrapper=require("jsdom/lib/jsdom/living/generated/utils").implForWrapper,fabric.nodeCanvas=require("jsdom/lib/jsdom/utils").Canvas,fabric.window=virtualWindow,DOMParser=fabric.window.DOMParser}function resizeCanvasIfNeeded(t){var e=t.targetCanvas,i=e.width,r=e.height,n=t.destinationWidth,s=t.destinationHeight;i===n&&r===s||(e.width=n,e.height=s)}function copyGLTo2DDrawImage(t,e){var i=t.canvas,r=e.targetCanvas,n=r.getContext("2d");n.translate(0,r.height),n.scale(1,-1);var s=i.height-r.height;n.drawImage(i,0,s,r.width,r.height,0,0,r.width,r.height)}function copyGLTo2DPutImageData(t,e){var i=e.targetCanvas.getContext("2d"),r=e.destinationWidth,n=e.destinationHeight,s=r*n*4,o=new Uint8Array(this.imageBuffer,0,s),a=new Uint8ClampedArray(this.imageBuffer,0,s);t.readPixels(0,0,r,n,t.RGBA,t.UNSIGNED_BYTE,o);var c=new ImageData(a,r,n);i.putImageData(c,0,0)}fabric.isTouchSupported="ontouchstart"in fabric.window||"ontouchstart"in fabric.document||fabric.window&&fabric.window.navigator&&0_)for(var C=1,S=d.length;Ct[i-2].x?1:n.x===t[i-2].x?0:-1,c=n.y>t[i-2].y?1:n.y===t[i-2].y?0:-1),r.push(["L",n.x+a*e,n.y+c*e]),r},fabric.util.getPathSegmentsInfo=l,fabric.util.getBoundsOfCurve=function(t,e,i,r,n,s,o,a){var c;if(fabric.cachesBoundsOfCurve&&(c=A.call(arguments),fabric.boundsOfCurveCache[c]))return fabric.boundsOfCurveCache[c];var h,l,u,f,d,g,p,v,m=Math.sqrt,b=Math.min,y=Math.max,_=Math.abs,x=[],C=[[],[]];l=6*t-12*i+6*n,h=-3*t+9*i-9*n+3*o,u=3*i-3*t;for(var S=0;S<2;++S)if(0/g,">")},graphemeSplit:function(t){var e,i=0,r=[];for(i=0;it.x&&this.y>t.y},gte:function(t){return this.x>=t.x&&this.y>=t.y},lerp:function(t,e){return void 0===e&&(e=.5),e=Math.max(Math.min(1,e),0),new i(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)},distanceFrom:function(t){var e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)},midPointFrom:function(t){return this.lerp(t)},min:function(t){return new i(Math.min(this.x,t.x),Math.min(this.y,t.y))},max:function(t){return new i(Math.max(this.x,t.x),Math.max(this.y,t.y))},toString:function(){return this.x+","+this.y},setXY:function(t,e){return this.x=t,this.y=e,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setFromPoint:function(t){return this.x=t.x,this.y=t.y,this},swap:function(t){var e=this.x,i=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=i},clone:function(){return new i(this.x,this.y)}}}("undefined"!=typeof exports?exports:this),function(t){"use strict";var f=t.fabric||(t.fabric={});function d(t){this.status=t,this.points=[]}f.Intersection?f.warn("fabric.Intersection is already defined"):(f.Intersection=d,f.Intersection.prototype={constructor:d,appendPoint:function(t){return this.points.push(t),this},appendPoints:function(t){return this.points=this.points.concat(t),this}},f.Intersection.intersectLineLine=function(t,e,i,r){var n,s=(r.x-i.x)*(t.y-i.y)-(r.y-i.y)*(t.x-i.x),o=(e.x-t.x)*(t.y-i.y)-(e.y-t.y)*(t.x-i.x),a=(r.y-i.y)*(e.x-t.x)-(r.x-i.x)*(e.y-t.y);if(0!==a){var c=s/a,h=o/a;0<=c&&c<=1&&0<=h&&h<=1?(n=new d("Intersection")).appendPoint(new f.Point(t.x+c*(e.x-t.x),t.y+c*(e.y-t.y))):n=new d}else n=new d(0===s||0===o?"Coincident":"Parallel");return n},f.Intersection.intersectLinePolygon=function(t,e,i){var r,n,s,o,a=new d,c=i.length;for(o=0;o=c&&(h.x-=c),h.x<=-c&&(h.x+=c),h.y>=c&&(h.y-=c),h.y<=c&&(h.y+=c),h.x-=o.offsetX,h.y-=o.offsetY,h}function y(t){return t.flipX!==t.flipY}function _(t,e,i,r,n){if(0!==t[e]){var s=n/t._getTransformedDimensions()[r]*t[i];t.set(i,s)}}function x(t,e,i,r){var n,s=e.target,o=s._getTransformedDimensions(0,s.skewY),a=P(e,e.originX,e.originY,i,r),c=Math.abs(2*a.x)-o.x,h=s.skewX;c<2?n=0:(n=v(Math.atan2(c/s.scaleX,o.y/s.scaleY)),e.originX===f&&e.originY===p&&(n=-n),e.originX===g&&e.originY===d&&(n=-n),y(s)&&(n=-n));var l=h!==n;if(l){var u=s._getTransformedDimensions().y;s.set("skewX",n),_(s,"skewY","scaleY","y",u)}return l}function C(t,e,i,r){var n,s=e.target,o=s._getTransformedDimensions(s.skewX,0),a=P(e,e.originX,e.originY,i,r),c=Math.abs(2*a.y)-o.y,h=s.skewY;c<2?n=0:(n=v(Math.atan2(c/s.scaleY,o.x/s.scaleX)),e.originX===f&&e.originY===p&&(n=-n),e.originX===g&&e.originY===d&&(n=-n),y(s)&&(n=-n));var l=h!==n;if(l){var u=s._getTransformedDimensions().x;s.set("skewY",n),_(s,"skewX","scaleX","x",u)}return l}function E(t,e,i,r,n){n=n||{};var s,o,a,c,h,l,u=e.target,f=u.lockScalingX,d=u.lockScalingY,g=n.by,p=w(t,u),v=k(u,g,p),m=e.gestureScale;if(v)return!1;if(m)o=e.scaleX*m,a=e.scaleY*m;else{if(s=P(e,e.originX,e.originY,i,r),h="y"!==g?T(s.x):1,l="x"!==g?T(s.y):1,e.signX||(e.signX=h),e.signY||(e.signY=l),u.lockScalingFlip&&(e.signX!==h||e.signY!==l))return!1;if(c=u._getTransformedDimensions(),p&&!g){var b=Math.abs(s.x)+Math.abs(s.y),y=e.original,_=b/(Math.abs(c.x*y.scaleX/u.scaleX)+Math.abs(c.y*y.scaleY/u.scaleY));o=y.scaleX*_,a=y.scaleY*_}else o=Math.abs(s.x*u.scaleX/c.x),a=Math.abs(s.y*u.scaleY/c.y);O(e)&&(o*=2,a*=2),e.signX!==h&&"y"!==g&&(e.originX=S[e.originX],o*=-1,e.signX=h),e.signY!==l&&"x"!==g&&(e.originY=S[e.originY],a*=-1,e.signY=l)}var x=u.scaleX,C=u.scaleY;return g?("x"===g&&u.set("scaleX",o),"y"===g&&u.set("scaleY",a)):(!f&&u.set("scaleX",o),!d&&u.set("scaleY",a)),x!==u.scaleX||C!==u.scaleY}n.scaleCursorStyleHandler=function(t,e,i){var r=w(t,i),n="";if(0!==e.x&&0===e.y?n="x":0===e.x&&0!==e.y&&(n="y"),k(i,n,r))return"not-allowed";var s=a(i,e);return o[s]+"-resize"},n.skewCursorStyleHandler=function(t,e,i){var r="not-allowed";if(0!==e.x&&i.lockSkewingY)return r;if(0!==e.y&&i.lockSkewingX)return r;var n=a(i,e)%4;return s[n]+"-resize"},n.scaleSkewCursorStyleHandler=function(t,e,i){return t[i.canvas.altActionKey]?n.skewCursorStyleHandler(t,e,i):n.scaleCursorStyleHandler(t,e,i)},n.rotationWithSnapping=b("rotating",m(function(t,e,i,r){var n=e,s=n.target,o=s.translateToOriginPoint(s.getCenterPoint(),n.originX,n.originY);if(s.lockRotation)return!1;var a,c=Math.atan2(n.ey-o.y,n.ex-o.x),h=Math.atan2(r-o.y,i-o.x),l=v(h-c+n.theta);if(0o.r2,h=this.gradientTransform?this.gradientTransform.concat():fabric.iMatrix.concat(),l=-this.offsetX,u=-this.offsetY,f=!!e.additionalTransform,d="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox";if(a.sort(function(t,e){return t.offset-e.offset}),"objectBoundingBox"===d?(l/=t.width,u/=t.height):(l+=t.width/2,u+=t.height/2),"path"===t.type&&"percentage"!==this.gradientUnits&&(l-=t.pathOffset.x,u-=t.pathOffset.y),h[4]-=l,h[5]-=u,s='id="SVGID_'+this.id+'" gradientUnits="'+d+'"',s+=' gradientTransform="'+(f?e.additionalTransform+" ":"")+fabric.util.matrixToSVG(h)+'" ',"linear"===this.type?n=["\n']:"radial"===this.type&&(n=["\n']),"radial"===this.type){if(c)for((a=a.concat()).reverse(),i=0,r=a.length;i\n')}return n.push("linear"===this.type?"\n":"\n"),n.join("")},toLive:function(t){var e,i,r,n=fabric.util.object.clone(this.coords);if(this.type){for("linear"===this.type?e=t.createLinearGradient(n.x1,n.y1,n.x2,n.y2):"radial"===this.type&&(e=t.createRadialGradient(n.x1,n.y1,n.r1,n.x2,n.y2,n.r2)),i=0,r=this.colorStops.length;i\n\n\n'},setOptions:function(t){for(var e in t)this[e]=t[e]},toLive:function(t){var e=this.source;if(!e)return"";if(void 0!==e.src){if(!e.complete)return"";if(0===e.naturalWidth||0===e.naturalHeight)return""}return t.createPattern(e,this.repeat)}})}(),function(t){"use strict";var o=t.fabric||(t.fabric={}),a=o.util.toFixed;o.Shadow?o.warn("fabric.Shadow is already defined."):(o.Shadow=o.util.createClass({color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1,initialize:function(t){for(var e in"string"==typeof t&&(t=this._parseShadow(t)),t)this[e]=t[e];this.id=o.Object.__uid++},_parseShadow:function(t){var e=t.trim(),i=o.Shadow.reOffsetsAndBlur.exec(e)||[];return{color:(e.replace(o.Shadow.reOffsetsAndBlur,"")||"rgb(0,0,0)").trim(),offsetX:parseFloat(i[1],10)||0,offsetY:parseFloat(i[2],10)||0,blur:parseFloat(i[3],10)||0}},toString:function(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")},toSVG:function(t){var e=40,i=40,r=o.Object.NUM_FRACTION_DIGITS,n=o.util.rotateVector({x:this.offsetX,y:this.offsetY},o.util.degreesToRadians(-t.angle)),s=new o.Color(this.color);return t.width&&t.height&&(e=100*a((Math.abs(n.x)+this.blur)/t.width,r)+20,i=100*a((Math.abs(n.y)+this.blur)/t.height,r)+20),t.flipX&&(n.x*=-1),t.flipY&&(n.y*=-1),'\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\t\n\t\n\n'},toObject:function(){if(this.includeDefaultValues)return{color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling};var e={},i=o.Shadow.prototype;return["color","blur","offsetX","offsetY","affectStroke","nonScaling"].forEach(function(t){this[t]!==i[t]&&(e[t]=this[t])},this),e}}),o.Shadow.reOffsetsAndBlur=/(?:\s|^)(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(\d+(?:\.\d*)?(?:px)?)?(?:\s?|$)(?:$|\s)/)}("undefined"!=typeof exports?exports:this),function(){"use strict";if(fabric.StaticCanvas)fabric.warn("fabric.StaticCanvas is already defined.");else{var n=fabric.util.object.extend,t=fabric.util.getElementOffset,h=fabric.util.removeFromArray,a=fabric.util.toFixed,s=fabric.util.transformPoint,o=fabric.util.invertTransform,i=fabric.util.getNodeCanvas,r=fabric.util.createCanvasElement,e=new Error("Could not initialize `canvas` element");fabric.StaticCanvas=fabric.util.createClass(fabric.CommonMethods,{initialize:function(t,e){e||(e={}),this.renderAndResetBound=this.renderAndReset.bind(this),this.requestRenderAllBound=this.requestRenderAll.bind(this),this._initStatic(t,e)},backgroundColor:"",backgroundImage:null,overlayColor:"",overlayImage:null,includeDefaultValues:!0,stateful:!1,renderOnAddRemove:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,imageSmoothingEnabled:!0,viewportTransform:fabric.iMatrix.concat(),backgroundVpt:!0,overlayVpt:!0,enableRetinaScaling:!0,vptCoords:{},skipOffscreen:!0,clipPath:void 0,_initStatic:function(t,e){var i=this.requestRenderAllBound;this._objects=[],this._createLowerCanvas(t),this._initOptions(e),this.interactive||this._initRetinaScaling(),e.overlayImage&&this.setOverlayImage(e.overlayImage,i),e.backgroundImage&&this.setBackgroundImage(e.backgroundImage,i),e.backgroundColor&&this.setBackgroundColor(e.backgroundColor,i),e.overlayColor&&this.setOverlayColor(e.overlayColor,i),this.calcOffset()},_isRetinaScaling:function(){return 1\n'),this._setSVGBgOverlayColor(i,"background"),this._setSVGBgOverlayImage(i,"backgroundImage",e),this._setSVGObjects(i,e),this.clipPath&&i.push("\n"),this._setSVGBgOverlayColor(i,"overlay"),this._setSVGBgOverlayImage(i,"overlayImage",e),i.push(""),i.join("")},_setSVGPreamble:function(t,e){e.suppressPreamble||t.push('\n','\n')},_setSVGHeader:function(t,e){var i,r=e.width||this.width,n=e.height||this.height,s='viewBox="0 0 '+this.width+" "+this.height+'" ',o=fabric.Object.NUM_FRACTION_DIGITS;e.viewBox?s='viewBox="'+e.viewBox.x+" "+e.viewBox.y+" "+e.viewBox.width+" "+e.viewBox.height+'" ':this.svgViewportTransformation&&(i=this.viewportTransform,s='viewBox="'+a(-i[4]/i[0],o)+" "+a(-i[5]/i[3],o)+" "+a(this.width/i[0],o)+" "+a(this.height/i[3],o)+'" '),t.push("\n',"Created with Fabric.js ",fabric.version,"\n","\n",this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),"\n")},createSVGClipPathMarkup:function(t){var e=this.clipPath;return e?(e.clipPathId="CLIPPATH_"+fabric.Object.__uid++,'\n'+this.clipPath.toClipPathSVG(t.reviver)+"\n"):""},createSVGRefElementsMarkup:function(){var s=this;return["background","overlay"].map(function(t){var e=s[t+"Color"];if(e&&e.toLive){var i=s[t+"Vpt"],r=s.viewportTransform,n={width:s.width/(i?r[0]:1),height:s.height/(i?r[3]:1)};return e.toSVG(n,{additionalTransform:i?fabric.util.matrixToSVG(r):""})}}).join("")},createSVGFontFacesMarkup:function(){var t,e,i,r,n,s,o,a,c="",h={},l=fabric.fontPaths,u=[];for(this._objects.forEach(function t(e){u.push(e),e._objects&&e._objects.forEach(t)}),o=0,a=u.length;o',"\n",c,"","\n"].join("")),c},_setSVGObjects:function(t,e){var i,r,n,s=this._objects;for(r=0,n=s.length;r\n")}else t.push('\n")},sendToBack:function(t){if(!t)return this;var e,i,r,n=this._activeObject;if(t===n&&"activeSelection"===t.type)for(e=(r=n._objects).length;e--;)i=r[e],h(this._objects,i),this._objects.unshift(i);else h(this._objects,t),this._objects.unshift(t);return this.renderOnAddRemove&&this.requestRenderAll(),this},bringToFront:function(t){if(!t)return this;var e,i,r,n=this._activeObject;if(t===n&&"activeSelection"===t.type)for(r=n._objects,e=0;e"}}),n(fabric.StaticCanvas.prototype,fabric.Observable),n(fabric.StaticCanvas.prototype,fabric.Collection),n(fabric.StaticCanvas.prototype,fabric.DataURLExporter),n(fabric.StaticCanvas,{EMPTY_JSON:'{"objects": [], "background": "white"}',supports:function(t){var e=r();if(!e||!e.getContext)return null;var i=e.getContext("2d");if(!i)return null;switch(t){case"setLineDash":return void 0!==i.setLineDash;default:return null}}}),fabric.StaticCanvas.prototype.toJSON=fabric.StaticCanvas.prototype.toObject,fabric.isLikelyNode&&(fabric.StaticCanvas.prototype.createPNGStream=function(){var t=i(this.lowerCanvasEl);return t&&t.createPNGStream()},fabric.StaticCanvas.prototype.createJPEGStream=function(t){var e=i(this.lowerCanvasEl);return e&&e.createJPEGStream(t)})}}(),fabric.BaseBrush=fabric.util.createClass({color:"rgb(0, 0, 0)",width:1,shadow:null,strokeLineCap:"round",strokeLineJoin:"round",strokeMiterLimit:10,strokeDashArray:null,limitedToCanvasSize:!1,_setBrushStyles:function(t){t.strokeStyle=this.color,t.lineWidth=this.width,t.lineCap=this.strokeLineCap,t.miterLimit=this.strokeMiterLimit,t.lineJoin=this.strokeLineJoin,t.setLineDash(this.strokeDashArray||[])},_saveAndTransform:function(t){var e=this.canvas.viewportTransform;t.save(),t.transform(e[0],e[1],e[2],e[3],e[4],e[5])},_setShadow:function(){if(this.shadow){var t=this.canvas,e=this.shadow,i=t.contextTop,r=t.getZoom();t&&t._isRetinaScaling()&&(r*=fabric.devicePixelRatio),i.shadowColor=e.color,i.shadowBlur=e.blur*r,i.shadowOffsetX=e.offsetX*r,i.shadowOffsetY=e.offsetY*r}},needsFullRender:function(){return new fabric.Color(this.color).getAlpha()<1||!!this.shadow},_resetShadow:function(){var t=this.canvas.contextTop;t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0},_isOutSideCanvas:function(t){return t.x<0||t.x>this.canvas.getWidth()||t.y<0||t.y>this.canvas.getHeight()}}),fabric.PencilBrush=fabric.util.createClass(fabric.BaseBrush,{decimate:.4,drawStraightLine:!1,straightLineKey:"shiftKey",initialize:function(t){this.canvas=t,this._points=[]},needsFullRender:function(){return this.callSuper("needsFullRender")||this._hasStraightLine},_drawSegment:function(t,e,i){var r=e.midPointFrom(i);return t.quadraticCurveTo(e.x,e.y,r.x,r.y),r},onMouseDown:function(t,e){this.canvas._isMainEvent(e.e)&&(this.drawStraightLine=e.e[this.straightLineKey],this._prepareForDrawing(t),this._captureDrawingPath(t),this._render())},onMouseMove:function(t,e){if(this.canvas._isMainEvent(e.e)&&(this.drawStraightLine=e.e[this.straightLineKey],(!0!==this.limitedToCanvasSize||!this._isOutSideCanvas(t))&&this._captureDrawingPath(t)&&1"},getObjectScaling:function(){if(!this.group)return{scaleX:this.scaleX,scaleY:this.scaleY};var t=x.util.qrDecompose(this.calcTransformMatrix());return{scaleX:Math.abs(t.scaleX),scaleY:Math.abs(t.scaleY)}},getTotalObjectScaling:function(){var t=this.getObjectScaling(),e=t.scaleX,i=t.scaleY;if(this.canvas){var r=this.canvas.getZoom(),n=this.canvas.getRetinaScaling();e*=r*n,i*=r*n}return{scaleX:e,scaleY:i}},getObjectOpacity:function(){var t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t},_set:function(t,e){var i="scaleX"===t||"scaleY"===t,r=this[t]!==e,n=!1;return i&&(e=this._constrainScale(e)),"scaleX"===t&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof x.Shadow?"dirty"===t&&this.group&&this.group.set("dirty",e):e=new x.Shadow(e),this[t]=e,r&&(n=this.group&&this.group.isOnACache(),-1=t.x&&n.left+n.width<=e.x&&n.top>=t.y&&n.top+n.height<=e.y},containsPoint:function(t,e,i,r){var n=this._getCoords(i,r),s=(e=e||this._getImageLines(n),this._findCrossPoints(t,e));return 0!==s&&s%2==1},isOnScreen:function(t){if(!this.canvas)return!1;var e=this.canvas.vptCoords.tl,i=this.canvas.vptCoords.br;return!!this.getCoords(!0,t).some(function(t){return t.x<=i.x&&t.x>=e.x&&t.y<=i.y&&t.y>=e.y})||(!!this.intersectsWithRect(e,i,!0,t)||this._containsCenterOfCanvas(e,i,t))},_containsCenterOfCanvas:function(t,e,i){var r={x:(t.x+e.x)/2,y:(t.y+e.y)/2};return!!this.containsPoint(r,null,!0,i)},isPartiallyOnScreen:function(t){if(!this.canvas)return!1;var e=this.canvas.vptCoords.tl,i=this.canvas.vptCoords.br;return!!this.intersectsWithRect(e,i,!0,t)||this.getCoords(!0,t).every(function(t){return(t.x>=i.x||t.x<=e.x)&&(t.y>=i.y||t.y<=e.y)})&&this._containsCenterOfCanvas(e,i,t)},_getImageLines:function(t){return{topline:{o:t.tl,d:t.tr},rightline:{o:t.tr,d:t.br},bottomline:{o:t.br,d:t.bl},leftline:{o:t.bl,d:t.tl}}},_findCrossPoints:function(t,e){var i,r,n,s=0;for(var o in e)if(!((n=e[o]).o.y=t.y&&n.d.y>=t.y||(n.o.x===n.d.x&&n.o.x>=t.x?r=n.o.x:(0,i=(n.d.y-n.o.y)/(n.d.x-n.o.x),r=-(t.y-0*t.x-(n.o.y-i*n.o.x))/(0-i)),r>=t.x&&(s+=1),2!==s)))break;return s},getBoundingRect:function(t,e){var i=this.getCoords(t,e);return h.makeBoundingBoxFromPoints(i)},getScaledWidth:function(){return this._getTransformedDimensions().x},getScaledHeight:function(){return this._getTransformedDimensions().y},_constrainScale:function(t){return Math.abs(t)\n')}},toSVG:function(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})},toClipPathSVG:function(t){return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})},_createBaseClipPathSVGMarkup:function(t,e){var i=(e=e||{}).reviver,r=e.additionalTransform||"",n=[this.getSvgTransform(!0,r),this.getSvgCommons()].join(""),s=t.indexOf("COMMON_PARTS");return t[s]=n,i?i(t.join("")):t.join("")},_createBaseSVGMarkup:function(t,e){var i,r,n=(e=e||{}).noStyle,s=e.reviver,o=n?"":'style="'+this.getSvgStyles()+'" ',a=e.withShadow?'style="'+this.getSvgFilter()+'" ':"",c=this.clipPath,h=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",l=c&&c.absolutePositioned,u=this.stroke,f=this.fill,d=this.shadow,g=[],p=t.indexOf("COMMON_PARTS"),v=e.additionalTransform;return c&&(c.clipPathId="CLIPPATH_"+fabric.Object.__uid++,r='\n'+c.toClipPathSVG(s)+"\n"),l&&g.push("\n"),g.push("\n"),i=[o,h,n?"":this.addPaintOrder()," ",v?'transform="'+v+'" ':""].join(""),t[p]=i,f&&f.toLive&&g.push(f.toSVG(this)),u&&u.toLive&&g.push(u.toSVG(this)),d&&g.push(d.toSVG(this)),c&&g.push(r),g.push(t.join("")),g.push("\n"),l&&g.push("\n"),s?s(g.join("")):g.join("")},addPaintOrder:function(){return"fill"!==this.paintFirst?' paint-order="'+this.paintFirst+'" ':""}})}(),function(){var n=fabric.util.object.extend,r="stateProperties";function s(e,t,i){var r={};i.forEach(function(t){r[t]=e[t]}),n(e[t],r,!0)}fabric.util.object.extend(fabric.Object.prototype,{hasStateChanged:function(t){var e="_"+(t=t||r);return Object.keys(this[e]).length\n']}}),s.Line.ATTRIBUTE_NAMES=s.SHARED_ATTRIBUTES.concat("x1 y1 x2 y2".split(" ")),s.Line.fromElement=function(t,e,i){i=i||{};var r=s.parseAttributes(t,s.Line.ATTRIBUTE_NAMES),n=[r.x1||0,r.y1||0,r.x2||0,r.y2||0];e(new s.Line(n,o(r,i)))},s.Line.fromObject=function(t,e){var i=r(t,!0);i.points=[t.x1,t.y1,t.x2,t.y2],s.Object._fromObject("Line",i,function(t){delete t.points,e&&e(t)},"points")})}("undefined"!=typeof exports?exports:this),function(t){"use strict";var s=t.fabric||(t.fabric={}),o=s.util.degreesToRadians;s.Circle?s.warn("fabric.Circle is already defined."):(s.Circle=s.util.createClass(s.Object,{type:"circle",radius:0,startAngle:0,endAngle:360,cacheProperties:s.Object.prototype.cacheProperties.concat("radius","startAngle","endAngle"),_set:function(t,e){return this.callSuper("_set",t,e),"radius"===t&&this.setRadius(e),this},toObject:function(t){return this.callSuper("toObject",["radius","startAngle","endAngle"].concat(t))},_toSVG:function(){var t,e=(this.endAngle-this.startAngle)%360;if(0===e)t=["\n'];else{var i=o(this.startAngle),r=o(this.endAngle),n=this.radius;t=['\n"]}return t},_render:function(t){t.beginPath(),t.arc(0,0,this.radius,o(this.startAngle),o(this.endAngle),!1),this._renderPaintInOrder(t)},getRadiusX:function(){return this.get("radius")*this.get("scaleX")},getRadiusY:function(){return this.get("radius")*this.get("scaleY")},setRadius:function(t){return this.radius=t,this.set("width",2*t).set("height",2*t)}}),s.Circle.ATTRIBUTE_NAMES=s.SHARED_ATTRIBUTES.concat("cx cy r".split(" ")),s.Circle.fromElement=function(t,e){var i,r=s.parseAttributes(t,s.Circle.ATTRIBUTE_NAMES);if(!("radius"in(i=r)&&0<=i.radius))throw new Error("value of `r` attribute is required and can not be negative");r.left=(r.left||0)-r.radius,r.top=(r.top||0)-r.radius,e(new s.Circle(r))},s.Circle.fromObject=function(t,e){s.Object._fromObject("Circle",t,e)})}("undefined"!=typeof exports?exports:this),function(t){"use strict";var i=t.fabric||(t.fabric={});i.Triangle?i.warn("fabric.Triangle is already defined"):(i.Triangle=i.util.createClass(i.Object,{type:"triangle",width:100,height:100,_render:function(t){var e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,i),t.lineTo(0,-i),t.lineTo(e,i),t.closePath(),this._renderPaintInOrder(t)},_toSVG:function(){var t=this.width/2,e=this.height/2;return["']}}),i.Triangle.fromObject=function(t,e){return i.Object._fromObject("Triangle",t,e)})}("undefined"!=typeof exports?exports:this),function(t){"use strict";var r=t.fabric||(t.fabric={}),e=2*Math.PI;r.Ellipse?r.warn("fabric.Ellipse is already defined."):(r.Ellipse=r.util.createClass(r.Object,{type:"ellipse",rx:0,ry:0,cacheProperties:r.Object.prototype.cacheProperties.concat("rx","ry"),initialize:function(t){this.callSuper("initialize",t),this.set("rx",t&&t.rx||0),this.set("ry",t&&t.ry||0)},_set:function(t,e){switch(this.callSuper("_set",t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this},getRx:function(){return this.get("rx")*this.get("scaleX")},getRy:function(){return this.get("ry")*this.get("scaleY")},toObject:function(t){return this.callSuper("toObject",["rx","ry"].concat(t))},_toSVG:function(){return["\n']},_render:function(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,e,!1),t.restore(),this._renderPaintInOrder(t)}}),r.Ellipse.ATTRIBUTE_NAMES=r.SHARED_ATTRIBUTES.concat("cx cy rx ry".split(" ")),r.Ellipse.fromElement=function(t,e){var i=r.parseAttributes(t,r.Ellipse.ATTRIBUTE_NAMES);i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,e(new r.Ellipse(i))},r.Ellipse.fromObject=function(t,e){r.Object._fromObject("Ellipse",t,e)})}("undefined"!=typeof exports?exports:this),function(t){"use strict";var s=t.fabric||(t.fabric={}),o=s.util.object.extend;s.Rect?s.warn("fabric.Rect is already defined"):(s.Rect=s.util.createClass(s.Object,{stateProperties:s.Object.prototype.stateProperties.concat("rx","ry"),type:"rect",rx:0,ry:0,cacheProperties:s.Object.prototype.cacheProperties.concat("rx","ry"),initialize:function(t){this.callSuper("initialize",t),this._initRxRy()},_initRxRy:function(){this.rx&&!this.ry?this.ry=this.rx:this.ry&&!this.rx&&(this.rx=this.ry)},_render:function(t){var e=this.rx?Math.min(this.rx,this.width/2):0,i=this.ry?Math.min(this.ry,this.height/2):0,r=this.width,n=this.height,s=-this.width/2,o=-this.height/2,a=0!==e||0!==i,c=.4477152502;t.beginPath(),t.moveTo(s+e,o),t.lineTo(s+r-e,o),a&&t.bezierCurveTo(s+r-c*e,o,s+r,o+c*i,s+r,o+i),t.lineTo(s+r,o+n-i),a&&t.bezierCurveTo(s+r,o+n-c*i,s+r-c*e,o+n,s+r-e,o+n),t.lineTo(s+e,o+n),a&&t.bezierCurveTo(s+c*e,o+n,s,o+n-c*i,s,o+n-i),t.lineTo(s,o+i),a&&t.bezierCurveTo(s,o+c*i,s+c*e,o,s+e,o),t.closePath(),this._renderPaintInOrder(t)},toObject:function(t){return this.callSuper("toObject",["rx","ry"].concat(t))},_toSVG:function(){return["\n']}}),s.Rect.ATTRIBUTE_NAMES=s.SHARED_ATTRIBUTES.concat("x y rx ry width height".split(" ")),s.Rect.fromElement=function(t,e,i){if(!t)return e(null);i=i||{};var r=s.parseAttributes(t,s.Rect.ATTRIBUTE_NAMES);r.left=r.left||0,r.top=r.top||0,r.height=r.height||0,r.width=r.width||0;var n=new s.Rect(o(i?s.util.object.clone(i):{},r));n.visible=n.visible&&0\n']},commonRender:function(t){var e,i=this.points.length,r=this.pathOffset.x,n=this.pathOffset.y;if(!i||isNaN(this.points[i-1].y))return!1;t.beginPath(),t.moveTo(this.points[0].x-r,this.points[0].y-n);for(var s=0;s"},toObject:function(t){return n(this.callSuper("toObject",t),{path:this.path.map(function(t){return t.slice()})})},toDatalessObject:function(t){var e=this.toObject(["sourcePath"].concat(t));return e.sourcePath&&delete e.path,e},_toSVG:function(){return["\n"]},_getOffsetTransform:function(){var t=f.Object.NUM_FRACTION_DIGITS;return" translate("+e(-this.pathOffset.x,t)+", "+e(-this.pathOffset.y,t)+")"},toClipPathSVG:function(t){var e=this._getOffsetTransform();return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})},toSVG:function(t){var e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})},complexity:function(){return this.path.length},_calcDimensions:function(){for(var t,e,i=[],r=[],n=0,s=0,o=0,a=0,c=0,h=this.path.length;c"},addWithUpdate:function(t){var e=!!this.group;return this._restoreObjectsState(),h.util.resetObjectTransform(this),t&&(e&&h.util.removeTransformFromObject(t,this.group.calcTransformMatrix()),this._objects.push(t),t.group=this,t._set("canvas",this.canvas)),this._calcBounds(),this._updateObjectsCoords(),this.dirty=!0,e?this.group.addWithUpdate():this.setCoords(),this},removeWithUpdate:function(t){return this._restoreObjectsState(),h.util.resetObjectTransform(this),this.remove(t),this._calcBounds(),this._updateObjectsCoords(),this.setCoords(),this.dirty=!0,this},_onObjectAdded:function(t){this.dirty=!0,t.group=this,t._set("canvas",this.canvas)},_onObjectRemoved:function(t){this.dirty=!0,delete t.group},_set:function(t,e){var i=this._objects.length;if(this.useSetOnGroup)for(;i--;)this._objects[i].setOnGroup(t,e);if("canvas"===t)for(;i--;)this._objects[i]._set(t,e);h.Object.prototype._set.call(this,t,e)},toObject:function(r){var n=this.includeDefaultValues,t=this._objects.filter(function(t){return!t.excludeFromExport}).map(function(t){var e=t.includeDefaultValues;t.includeDefaultValues=n;var i=t.toObject(r);return t.includeDefaultValues=e,i}),e=h.Object.prototype.toObject.call(this,r);return e.objects=t,e},toDatalessObject:function(r){var t,e=this.sourcePath;if(e)t=e;else{var n=this.includeDefaultValues;t=this._objects.map(function(t){var e=t.includeDefaultValues;t.includeDefaultValues=n;var i=t.toDatalessObject(r);return t.includeDefaultValues=e,i})}var i=h.Object.prototype.toDatalessObject.call(this,r);return i.objects=t,i},render:function(t){this._transformDone=!0,this.callSuper("render",t),this._transformDone=!1},shouldCache:function(){var t=h.Object.prototype.shouldCache.call(this);if(t)for(var e=0,i=this._objects.length;e\n"],i=0,r=this._objects.length;i\n"),e},getSvgStyles:function(){var t=void 0!==this.opacity&&1!==this.opacity?"opacity: "+this.opacity+";":"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")},toClipPathSVG:function(t){for(var e=[],i=0,r=this._objects.length;i"},shouldCache:function(){return!1},isOnACache:function(){return!1},_renderControls:function(t,e,i){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,this.callSuper("_renderControls",t,e),void 0===(i=i||{}).hasControls&&(i.hasControls=!1),i.forActiveSelection=!0;for(var r=0,n=this._objects.length;r\n','\t\n',"\n"),o=' clip-path="url(#imageCrop_'+c+')" '}if(this.imageSmoothing||(a='" image-rendering="optimizeSpeed'),i.push("\t\n"),this.stroke||this.strokeDashArray){var h=this.fill;this.fill=null,t=["\t\n'],this.fill=h}return e="fill"!==this.paintFirst?e.concat(t,i):e.concat(i,t)},getSrc:function(t){var e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src"):e.src:this.src||""},setSrc:function(t,i,r){return fabric.util.loadImage(t,function(t,e){this.setElement(t,r),this._setWidthHeight(),i&&i(this,e)},this,r&&r.crossOrigin),this},toString:function(){return'#'},applyResizeFilters:function(){var t=this.resizeFilter,e=this.minimumScaleTrigger,i=this.getTotalObjectScaling(),r=i.scaleX,n=i.scaleY,s=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||e=t;for(var a=["highp","mediump","lowp"],c=0;c<3;c++)if(void 0,i="precision "+a[c]+" float;\nvoid main(){}",r=(e=s).createShader(e.FRAGMENT_SHADER),e.shaderSource(r,i),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)){fabric.webGlPrecision=a[c];break}}return this.isSupported=o},(fabric.WebglFilterBackend=t).prototype={tileSize:2048,resources:{},setupGLContext:function(t,e){this.dispose(),this.createWebGLCanvas(t,e),this.aPosition=new Float32Array([0,0,0,1,1,0,1,1]),this.chooseFastestCopyGLTo2DMethod(t,e)},chooseFastestCopyGLTo2DMethod:function(t,e){var i,r=void 0!==window.performance;try{new ImageData(1,1),i=!0}catch(t){i=!1}var n="undefined"!=typeof ArrayBuffer,s="undefined"!=typeof Uint8ClampedArray;if(r&&i&&n&&s){var o=fabric.util.createCanvasElement(),a=new ArrayBuffer(t*e*4);if(fabric.forceGLPutImageData)return this.imageBuffer=a,void(this.copyGLTo2D=copyGLTo2DPutImageData);var c,h,l={imageBuffer:a,destinationWidth:t,destinationHeight:e,targetCanvas:o};o.width=t,o.height=e,c=window.performance.now(),copyGLTo2DDrawImage.call(l,this.gl,l),h=window.performance.now()-c,c=window.performance.now(),copyGLTo2DPutImageData.call(l,this.gl,l),window.performance.now()-c 0.0) {\n"+this.fragmentSource[t]+"}\n}"},retrieveShader:function(t){var e,i=this.type+"_"+this.mode;return t.programCache.hasOwnProperty(i)||(e=this.buildSource(this.mode),t.programCache[i]=this.createProgram(t.context,e)),t.programCache[i]},applyTo2d:function(t){var e,i,r,n,s,o,a,c=t.imageData.data,h=c.length,l=1-this.alpha;e=(a=new f.Color(this.color).getSource())[0]*this.alpha,i=a[1]*this.alpha,r=a[2]*this.alpha;for(var u=0;u'},_getCacheCanvasDimensions:function(){var t=this.callSuper("_getCacheCanvasDimensions"),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t},_render:function(t){var e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")},_renderText:function(t){"stroke"===this.paintFirst?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))},_setTextStyles:function(t,e,i){if(t.textBaseline="alphabetical",this.path)switch(this.pathAlign){case"center":t.textBaseline="middle";break;case"ascender":t.textBaseline="top";break;case"descender":t.textBaseline="bottom"}t.font=this._getFontDeclaration(e,i)},calcTextWidth:function(){for(var t=this.getLineWidth(0),e=1,i=this._textLines.length;ethis.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=e):(this.selectionStart=e,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===r||(this.restartCursorIfNeeded(),this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}},_setEditingProps:function(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0},fromStringToGraphemeSelection:function(t,e,i){var r=i.slice(0,t),n=fabric.util.string.graphemeSplit(r).length;if(t===e)return{selectionStart:n,selectionEnd:n};var s=i.slice(t,e);return{selectionStart:n,selectionEnd:n+fabric.util.string.graphemeSplit(s).length}},fromGraphemeToStringSelection:function(t,e,i){var r=i.slice(0,t).join("").length;return t===e?{selectionStart:r,selectionEnd:r}:{selectionStart:r,selectionEnd:r+i.slice(t,e).join("").length}},_updateTextarea:function(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){var t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}},updateFromTextArea:function(){if(this.hiddenTextarea){this.cursorOffsetCache={},this.text=this.hiddenTextarea.value,this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords());var t=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value);this.selectionEnd=this.selectionStart=t.selectionEnd,this.inCompositionMode||(this.selectionStart=t.selectionStart),this.updateTextareaPosition()}},updateTextareaPosition:function(){if(this.selectionStart===this.selectionEnd){var t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}},_calcTextareaPosition:function(){if(!this.canvas)return{x:1,y:1};var t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),i=this.get2DCursorLocation(t),r=i.lineIndex,n=i.charIndex,s=this.getValueOfPropertyAt(r,n,"fontSize")*this.lineHeight,o=e.leftOffset,a=this.calcTransformMatrix(),c={x:e.left+o,y:e.top+e.topOffset+s},h=this.canvas.getRetinaScaling(),l=this.canvas.upperCanvasEl,u=l.width/h,f=l.height/h,d=u-s,g=f-s,p=l.clientWidth/u,v=l.clientHeight/f;return c=fabric.util.transformPoint(c,a),(c=fabric.util.transformPoint(c,this.canvas.viewportTransform)).x*=p,c.y*=v,c.x<0&&(c.x=0),c.x>d&&(c.x=d),c.y<0&&(c.y=0),c.y>g&&(c.y=g),c.x+=this.canvas._offset.left,c.y+=this.canvas._offset.top,{left:c.x+"px",top:c.y+"px",fontSize:s+"px",charHeight:s}},_saveEditingProps:function(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}},_restoreEditingProps:function(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor))},exitEditing:function(){var t=this._textBeforeEdit!==this.text,e=this.hiddenTextarea;return this.selected=!1,this.isEditing=!1,this.selectionEnd=this.selectionStart,e&&(e.blur&&e.blur(),e.parentNode&&e.parentNode.removeChild(e)),this.hiddenTextarea=null,this.abortCursorAnimation(),this._restoreEditingProps(),this._currentCursorOpacity=0,this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire("modified"),this.canvas&&(this.canvas.off("mouse:move",this.mouseMoveHandler),this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this},_removeExtraneousStyles:function(){for(var t in this.styles)this._textLines[t]||delete this.styles[t]},removeStyleFromTo:function(t,e){var i,r,n=this.get2DCursorLocation(t,!0),s=this.get2DCursorLocation(e,!0),o=n.lineIndex,a=n.charIndex,c=s.lineIndex,h=s.charIndex;if(o!==c){if(this.styles[o])for(i=a;it?this.selectionStart=t:this.selectionStart<0&&(this.selectionStart=0),this.selectionEnd>t?this.selectionEnd=t:this.selectionEnd<0&&(this.selectionEnd=0)}})}(),fabric.util.object.extend(fabric.IText.prototype,{initDoubleClickSimulation:function(){this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown)},onMouseDown:function(t){if(this.canvas){this.__newClickTime=+new Date;var e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),this._stopEvent(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastIsEditing=this.isEditing,this.__lastSelected=this.selected}},isTripleClick:function(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y},_stopEvent:function(t){t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation()},initCursorSelectionHandlers:function(){this.initMousedownHandler(),this.initMouseupHandler(),this.initClicks()},doubleClickHandler:function(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))},tripleClickHandler:function(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))},initClicks:function(){this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler)},_mouseDownHandler:function(t){!this.canvas||!this.editable||t.e.button&&1!==t.e.button||(this.__isMousedown=!0,this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(t.e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()))},_mouseDownHandlerBefore:function(t){!this.canvas||!this.editable||t.e.button&&1!==t.e.button||(this.selected=this===this.canvas._activeObject)},initMousedownHandler:function(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore)},initMouseupHandler:function(){this.on("mouseup",this.mouseUpHandler)},mouseUpHandler:function(t){if(this.__isMousedown=!1,!(!this.editable||this.group||t.transform&&t.transform.actionPerformed||t.e.button&&1!==t.e.button)){if(this.canvas){var e=this.canvas._activeObject;if(e&&e!==this)return}this.__lastSelected&&!this.__corner?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(t.e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0}},setCursorByClick:function(t){var e=this.getSelectionStartFromPointer(t),i=this.selectionStart,r=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(i,r,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())},getSelectionStartFromPointer:function(t){for(var e,i=this.getLocalPointer(t),r=0,n=0,s=0,o=0,a=0,c=0,h=this._textLines.length;cthis._text.length&&(a=this._text.length),a}}),fabric.util.object.extend(fabric.IText.prototype,{initHiddenTextarea:function(){this.hiddenTextarea=fabric.document.createElement("textarea"),this.hiddenTextarea.setAttribute("autocapitalize","off"),this.hiddenTextarea.setAttribute("autocorrect","off"),this.hiddenTextarea.setAttribute("autocomplete","off"),this.hiddenTextarea.setAttribute("spellcheck","false"),this.hiddenTextarea.setAttribute("data-fabric-hiddentextarea",""),this.hiddenTextarea.setAttribute("wrap","off");var t=this._calcTextareaPosition();this.hiddenTextarea.style.cssText="position: absolute; top: "+t.top+"; left: "+t.left+"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: "+t.fontSize+";",this.hiddenTextareaContainer?this.hiddenTextareaContainer.appendChild(this.hiddenTextarea):fabric.document.body.appendChild(this.hiddenTextarea),fabric.util.addListener(this.hiddenTextarea,"keydown",this.onKeyDown.bind(this)),fabric.util.addListener(this.hiddenTextarea,"keyup",this.onKeyUp.bind(this)),fabric.util.addListener(this.hiddenTextarea,"input",this.onInput.bind(this)),fabric.util.addListener(this.hiddenTextarea,"copy",this.copy.bind(this)),fabric.util.addListener(this.hiddenTextarea,"cut",this.copy.bind(this)),fabric.util.addListener(this.hiddenTextarea,"paste",this.paste.bind(this)),fabric.util.addListener(this.hiddenTextarea,"compositionstart",this.onCompositionStart.bind(this)),fabric.util.addListener(this.hiddenTextarea,"compositionupdate",this.onCompositionUpdate.bind(this)),fabric.util.addListener(this.hiddenTextarea,"compositionend",this.onCompositionEnd.bind(this)),!this._clickHandlerInitialized&&this.canvas&&(fabric.util.addListener(this.canvas.upperCanvasEl,"click",this.onClick.bind(this)),this._clickHandlerInitialized=!0)},keysMap:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorRight",36:"moveCursorLeft",37:"moveCursorLeft",38:"moveCursorUp",39:"moveCursorRight",40:"moveCursorDown"},keysMapRtl:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorLeft",36:"moveCursorRight",37:"moveCursorRight",38:"moveCursorUp",39:"moveCursorLeft",40:"moveCursorDown"},ctrlKeysMapUp:{67:"copy",88:"cut"},ctrlKeysMapDown:{65:"selectAll"},onClick:function(){this.hiddenTextarea&&this.hiddenTextarea.focus()},onKeyDown:function(t){if(this.isEditing){var e="rtl"===this.direction?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown&&(t.ctrlKey||t.metaKey)))return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),33<=t.keyCode&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}},onKeyUp:function(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())},onInput:function(t){var e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),this.isEditing){var i,r,n,s,o,a=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,c=this._text.length,h=a.length,l=h-c,u=this.selectionStart,f=this.selectionEnd,d=u!==f;if(""===this.hiddenTextarea.value)return this.styles={},this.updateFromTextArea(),this.fire("changed"),void(this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll()));var g=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),p=u>g.selectionStart;d?(i=this._text.slice(u,f),l+=f-u):h=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)},moveCursorUp:function(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorUpOrDown("Up",t)},_moveCursorUpOrDown:function(t,e){var i=this["get"+t+"CursorOffset"](e,"right"===this._selectionDirection);e.shiftKey?this.moveCursorWithShift(i):this.moveCursorWithoutShift(i),0!==i&&(this.setSelectionInBoundaries(),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorWithShift:function(t){var e="left"===this._selectionDirection?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),0!==t},moveCursorWithoutShift:function(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),0!==t},moveCursorLeft:function(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorLeftOrRight("Left",t)},_move:function(t,e,i){var r;if(t.altKey)r=this["findWordBoundary"+i](this[e]);else{if(!t.metaKey&&35!==t.keyCode&&36!==t.keyCode)return this[e]+="Left"===i?-1:1,!0;r=this["findLineBoundary"+i](this[e])}if(void 0!==r&&this[e]!==r)return this[e]=r,!0},_moveLeft:function(t,e){return this._move(t,e,"Left")},_moveRight:function(t,e){return this._move(t,e,"Right")},moveCursorLeftWithoutShift:function(t){var e=!0;return this._selectionDirection="left",this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e},moveCursorLeftWithShift:function(t){return"right"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection="left",this._moveLeft(t,"selectionStart")):void 0},moveCursorRight:function(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)},_moveCursorLeftOrRight:function(t,e){var i="moveCursor"+t+"With";this._currentCursorOpacity=1,e.shiftKey?i+="Shift":i+="outShift",this[i](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorRightWithShift:function(t){return"left"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection="right",this._moveRight(t,"selectionEnd")):void 0},moveCursorRightWithoutShift:function(t){var e=!0;return this._selectionDirection="right",this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e},removeChars:function(t,e){void 0===e&&(e=t+1),this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()},insertChars:function(t,e,i,r){void 0===r&&(r=i),i",t.textSpans.join(""),"\n"]},_getSVGTextAndBg:function(t,e){var i,r=[],n=[],s=t;this._setSVGBg(n);for(var o=0,a=this._textLines.length;o",fabric.util.string.escapeXml(t),""].join("")},_setSVGTextLineText:function(t,e,i,r){var n,s,o,a,c,h=this.getHeightOfLine(e),l=-1!==this.textAlign.indexOf("justify"),u="",f=0,d=this._textLines[e];r+=h*(1-this._fontSizeFraction)/this.lineHeight;for(var g=0,p=d.length-1;g<=p;g++)c=g===p||this.charSpacing,u+=d[g],o=this.__charBounds[e][g],0===f?(i+=o.kernedWidth-o.width,f+=o.width):f+=o.kernedWidth,l&&!c&&this._reSpaceAndTab.test(d[g])&&(c=!0),c||(n=n||this.getCompleteStyleDeclaration(e,g),s=this.getCompleteStyleDeclaration(e,g+1),c=fabric.util.hasStyleChanged(n,s,!0)),c&&(a=this._getStyleDeclaration(e,g)||{},t.push(this._createTextCharSpan(u,a,i,r)),u="",n=s,i+=f,f=0)},_pushTextBgRect:function(t,e,i,r,n,s){var o=fabric.Object.NUM_FRACTION_DIGITS;t.push("\t\t\n')},_setSVGTextLineBg:function(t,e,i,r){for(var n,s,o=this._textLines[e],a=this.getHeightOfLine(e)/this.lineHeight,c=0,h=0,l=this.getValueOfPropertyAt(e,0,"textBackgroundColor"),u=0,f=o.length;uthis.width&&this._set("width",this.dynamicMinWidth),-1!==this.textAlign.indexOf("justify")&&this.enlargeSpaces(),this.height=this.calcTextHeight(),this.saveState({propertySet:"_dimensionAffectingProps"}))},_generateStyleMap:function(t){for(var e=0,i=0,r=0,n={},s=0;sthis.dynamicMinWidth&&(this.dynamicMinWidth=g-v+r),o},isEndOfWrapping:function(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line},missingNewlineOffset:function(t){return this.splitByGrapheme?this.isEndOfWrapping(t)?1:0:1},_splitTextIntoLines:function(t){for(var e=b.Text.prototype._splitTextIntoLines.call(this,t),i=this._wrapText(e.lines,this.width),r=new Array(i.length),n=0;n { + let agent = new Agent(reponse.data.agent, reponse.data.token) + callback(agent); + }, + error: (err) => { + error_handler(["Name already took."]) + } + }); + } + + 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, end = false) { + this.list(20, 1, (agents, meta) => { + let maxPage = meta.total / 20; + this.#r_listing(2, maxPage, agents, callback, end); + }); + } + + static #r_listing(page, maxPage, agents, callback, end) { + if (page < maxPage) { + this.list(20, page++,() => { + setTimeout(() => { + if (!end) { + callback(agents); + agents = []; + } + this.#r_listing(page++, maxPage, agents, callback, end); + }, 1000); + }, agents); + } else { + callback(agents); + } + } +} + + + diff --git a/js/skama_code/api/config.js b/js/skama_code/api/config.js new file mode 100644 index 0000000..8658ac2 --- /dev/null +++ b/js/skama_code/api/config.js @@ -0,0 +1,7 @@ +// Copyright © 2023 Entreprise SkamKraft +'use strict'; + +export const SpaceTraders = { + host: "https://api.spacetraders.io/v2", + limit_max: 20, +} \ No newline at end of file diff --git a/js/skama_code/api/planet.js b/js/skama_code/api/planet.js new file mode 100644 index 0000000..c4c085a --- /dev/null +++ b/js/skama_code/api/planet.js @@ -0,0 +1,71 @@ +// 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; + } +} \ No newline at end of file diff --git a/js/skama_code/api/system.js b/js/skama_code/api/system.js new file mode 100644 index 0000000..6f9ad8a --- /dev/null +++ b/js/skama_code/api/system.js @@ -0,0 +1,135 @@ +// Copyright © 2023 Entreprise SkamKraft +'use strict'; + +import { SpaceTraders } from "./config.js"; +import { Position } from "../commun/position.js"; +import { Planet } from "./planet.js"; + +export class System { + constructor(data) { + this.name = data.symbol; + this.sector = data.sectorSymbol; + this.type = data.type; + this.position = new Position(data.x, data.y); + this.factions = data.factions; + } + + get(name, callback, error_handler) { + const url = `${SpaceTraders.host}/systems/${this.name}/waypoints/${name}`; + $.ajax({ + url: url, + method: "GET", + success: (reponse) => { + let planet = new Planet(reponse.data); + callback(planet); + }, + error: (err) => { + error_handler("Planet not found"); + } + }); + } + + list(limit, page, callback, planets = []) { + const url = `${SpaceTraders.host}/systems/${this.name}/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); + } + }); + } + + list_all(callback, end = false) { + this.list(20, 1, (planets, meta) => { + let maxPage = meta.total / 20; + this.#r_listing(2, maxPage, planets, callback, end); + }); + } + + #r_listing(page, maxPage, planets, callback, end) { + if (page < maxPage) { + this.list(20, page++, () => { + setTimeout(() => { + if (!end) { + callback(planets); + planets = []; + } + this.#r_listing(page++, maxPage, planets, callback, end); + }, 1000); + }, planets); + } else { + callback(planets); + } + } +} + +export class SystemBuilder { + static parse_system_name(name) { + return name.split("-").slice(-1, 2).join("-"); + } + + static get(name, callback, error_handler) { + const url = `${SpaceTraders.host}/systems/${name}/`; + $.ajax({ + url: url, + method: "GET", + success: (reponse) => { + let system = new System(reponse.data); + callback(system); + }, + error: (err) => { + error_handler("System not found"); + } + }); + } + + static list(limit, page, callback, systems = []) { + const url = `${SpaceTraders.host}/systems/` + $.ajax({ + url: url, + method: "GET", + data: { + limit: limit, + page: page + }, + success: (reponse) => { + reponse.data.forEach(system => { + systems.push(new System(system)); + }); + callback(systems, reponse.meta); + } + }); + } + + static list_all(callback, end = false) { + this.list(20, 1, (systems, meta) => { + let maxPage = meta.total / 20; + this.#r_listing(2, maxPage, systems, callback, end); + }); + } + + static #r_listing(page, maxPage, systems, callback, end) { + if (page < maxPage) { + this.list(20, page++, () => { + setTimeout(() => { + if (!end) { + console.log(systems); + callback(systems); + systems = []; + } + this.#r_listing(page++, maxPage, systems, callback, end); + }, 1000); + }, systems); + } else { + callback(systems); + } + } +} \ No newline at end of file diff --git a/js/skama_code/auth/auth.js b/js/skama_code/auth/auth.js new file mode 100644 index 0000000..4ce4f41 --- /dev/null +++ b/js/skama_code/auth/auth.js @@ -0,0 +1,89 @@ +// Copyright © 2023 Entreprise SkamKraft +'use strict'; +import { AgentBuilder } from '../api/agent.js' +import Strategie from '../commun/strategie.js'; + +let strategies = { + register: [ + { + name: "name", + 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; + } + + 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); + AgentBuilder.get(token, this.validated, this.error_handler); + } + } + + relog() { + if(this.#is_login()) { + AgentBuilder.get(localStorage.getItem("token"), this.validated, this.error_handler); + return true; + } + return false; + } + + register(new_agent) { + let validateur = new Strategie(this.strategies.register); + validateur.validate("name", new_agent.name); + validateur.validate("faction", new_agent.faction); + if (validateur.errors.length > 0) this.error_handler(validateur.errors); + else { + AgentBuilder.create(new_agent.name, new_agent.faction, (agent) => { + if (this.store) localStorage.setItem("token", agent.token); + this.validated(agent); + }, this.error_handler); + } + } + + unload_token() { + if(this.#is_login()) localStorage.removeItem("token"); + } + + #is_login() { + if (localStorage.getItem("token")) return true + return false + } +} \ No newline at end of file diff --git a/js/skama_code/commun/position.js b/js/skama_code/commun/position.js new file mode 100644 index 0000000..b8c5275 --- /dev/null +++ b/js/skama_code/commun/position.js @@ -0,0 +1,18 @@ +// 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) + } + + move(position) { + this.x += position.x; + this.y += position.y; + } +} \ No newline at end of file diff --git a/js/skama_code/commun/strategie.js b/js/skama_code/commun/strategie.js new file mode 100644 index 0000000..79966c3 --- /dev/null +++ b/js/skama_code/commun/strategie.js @@ -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; + } +} \ No newline at end of file diff --git a/js/skama_code/commun/timer.js b/js/skama_code/commun/timer.js new file mode 100644 index 0000000..1891f15 --- /dev/null +++ b/js/skama_code/commun/timer.js @@ -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); + } + } +} \ No newline at end of file diff --git a/js/skama_code/rendering/canvas_render.js b/js/skama_code/rendering/canvas_render.js new file mode 100644 index 0000000..e69de29 diff --git a/js/skama_code/ui/menu.js b/js/skama_code/ui/menu.js new file mode 100644 index 0000000..e69de29 diff --git a/js/skama_code/ui/modal.js b/js/skama_code/ui/modal.js new file mode 100644 index 0000000..98890a3 --- /dev/null +++ b/js/skama_code/ui/modal.js @@ -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 = ""; + } + + load(template) { + this.template_engine.get_template((reponse) => { + $(this.tag).prepend(` + + ${reponse} + + `); + }, 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(); + } +} \ No newline at end of file diff --git a/js/skama_code/ui/templeting_engine.js b/js/skama_code/ui/templeting_engine.js new file mode 100644 index 0000000..924ca37 --- /dev/null +++ b/js/skama_code/ui/templeting_engine.js @@ -0,0 +1,43 @@ +// 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); + if (this.after_render_callback) this.after_render_callback(this); + }, 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); + } + + after_render(callback) { + this.after_render_callback = callback; + } +} diff --git a/js/test/tests.js b/js/test/tests.js new file mode 100644 index 0000000..bdc4eb7 --- /dev/null +++ b/js/test/tests.js @@ -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(` +

${time}

+ `); + }); + template_engine.render("templates/login.html"); + + let modal = new Modal("test-modal", template_engine); + modal.add_class("ext-modal") + + modal.load("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; \ No newline at end of file diff --git a/login.html b/login.html deleted file mode 100644 index 053d1c7..0000000 --- a/login.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - Skamkraft - - - - - - - - - - - - - -
-
- Bienvenue sur Skamkraft,
Entrez votre token pour continuer -
- - - -
- - - - diff --git a/register.html b/register.html deleted file mode 100644 index 36aebfa..0000000 --- a/register.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - Skamkraft - - - - - - - - - - - - - -
-
- Bienvenue sur Skamkraft,
- Entrez votre symbol pour continuer -
- - - - -
- - - - diff --git a/scripts/api.js b/scripts/api.js deleted file mode 100644 index b328163..0000000 --- a/scripts/api.js +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft - -"use strict"; - -const spacetradersApiUrl = "https://api.spacetraders.io/v2/"; - -const REQUEST = async (url, method, headers, data) => { - try { - const response = await $.ajax(url, { - method, - headers, - data, - }); - - return response.data; - } catch (error) { - return error; - } -}; - -export default { - Agent: { - create: (symbol, faction) => { - const url = `${spacetradersApiUrl}register`; - const headers = { "Content-Type": "application/json" }; - const data = JSON.stringify({ symbol, faction }); - - return REQUEST(url, "POST", headers, data); - }, - - get: (token) => { - const url = `${spacetradersApiUrl}my/agent`; - const headers = { - Accept: "application/json", - Authorization: `Bearer ${token}`, - }; - - return REQUEST(url, "GET", headers); - }, - - getPublic: (symbol) => { - const url = `${spacetradersApiUrl}agents/${symbol}`; - const headers = { Accept: "application/json" }; - - return REQUEST(url, "GET", headers); - }, - - list: (limit, page) => { - const url = `${spacetradersApiUrl}agents`; - const headers = { Accept: "application/json" }; - const data = { limit, page }; - - return REQUEST(url, "GET", headers, data); - }, - }, - - Faction: { - list: (limit, page) => { - const url = `${spacetradersApiUrl}factions`; - const headers = { Accept: "application/json" }; - const data = { limit, page }; - - return REQUEST(url, "GET", headers, data); - }, - }, - - System: { - list: (limit, page) => { - const url = `${spacetradersApiUrl}systems/`; - const headers = { Accept: "application/json" }; - const data = { limit, page }; - - return REQUEST(url, "GET", headers, data); - }, - - get: (symbol) => { - const url = `${spacetradersApiUrl}systems/${symbol}`; - const headers = { Accept: "application/json" }; - - return REQUEST(url, "GET", headers); - }, - }, - - Waypoint: { - list: (limit, page, systemSymbol) => { - const url = `${spacetradersApiUrl}systems/${systemSymbol}/waypoints`; - const headers = { Accept: "application/json" }; - const data = { limit, page }; - - return REQUEST(url, "GET", headers, data); - }, - - get: (systemSymbol, waypointSymbol, token) => { - const url = `${spacetradersApiUrl}systems/${systemSymbol}/waypoints/${waypointSymbol}/market`; - const headers = { - Accept: "application/json", - Authorization: `Bearer ${token}`, - }; - - return REQUEST(url, "GET", headers); - }, - }, - - Contract: { - list: (token) => { - const url = `${spacetradersApiUrl}my/contracts/`; - const headers = { - Accept: "application/json", - Authorization: `Bearer ${token}`, - }; - - return REQUEST(url, "GET", headers); - }, - - get: async (contratId, token) => { - const url = `${spacetradersApiUrl}my/contracts/${contratId}`; - const headers = { - Accept: "application/json", - Authorization: `Bearer ${token}`, - }; - - return REQUEST(url, "GET", headers); - }, - - accept: async (contratId, token) => { - const url = `${spacetradersApiUrl}my/contracts/${contratId}/accept`; - const headers = { - 'Content-Type': 'application/json', - Accept: "application/json", - Authorization: `Bearer ${token}`, - }; - - return REQUEST(url, "POST", headers); - } - }, -}; diff --git a/scripts/auth.js b/scripts/auth.js deleted file mode 100644 index f633cf8..0000000 --- a/scripts/auth.js +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright © 2023 Entreprise SkamCraft - -"use strict"; - -import SpaceTraders from "./api.js"; - -const $inputToken = $("#input-token"); -const $inputSymbol = $("#input-symbol"); -const $inputFaction = $("#input-faction"); -const $alert = document.querySelector("#box-alert"); -const $error = $("#error-message"); - -const showError = (message) => { - $alert.removeAttribute("hidden"); - $error.text(message); -}; - -const redirectToIndex = () => { - window.location.href = "/index.html"; -}; - -export default { - login: async () => { - const token = $inputToken.val(); - - if (!token) { - showError("Token manquant"); - return; - } - - try { - await SpaceTraders.Agent.get(token); - localStorage.setItem("token", token); - redirectToIndex(); - } catch { - showError("Token invalide"); - } - }, - - register: async () => { - const symbol = $inputSymbol.val(); - - if (!symbol) { - showError("Symbol manquant"); - return; - } - - const faction = $inputFaction.val(); - - console.log(faction); - - if (!faction) { - showError("Faction manquante"); - return; - } - - try { - const agent = await SpaceTraders.Agent.create(symbol, faction); - - if (agent.token !== undefined) { - localStorage.setItem("token", agent.token); - redirectToIndex(); - } else { - showError("Symbol ou faction invalide"); - } - } catch (error) { - console.log(error) - showError("Erreur lors de l'inscription"); - } - }, - - isLogin: async () => { - const token = localStorage.getItem("token"); - - if (!token) return false; - - try { - await SpaceTraders.Agent.get(token); - return true; - } catch { - return false; - } - }, -}; diff --git a/scripts/main.js b/scripts/main.js deleted file mode 100644 index 68a64a8..0000000 --- a/scripts/main.js +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright © 2023 Entreprise SkamCraft - -"use strict"; - -import AUTH from "./auth.js"; -import SpaceTraders from "./api.js"; - -$(document).ready(async function () { - //Auth - if (document.URL.includes("login.html")) { - $("#btn-login").on("click", () => { - AUTH.login(); - }); - return; - } - - if (document.URL.includes("register.html")) { - const factions = await SpaceTraders.Faction.list(10, 1); - factions.forEach((faction) => { - const option = ``; - $("#group-faction").append(option); - }); - - $("#btn-register").on("click", () => { - AUTH.register(); - }); - return; - } - - if (!(await AUTH.isLogin())) window.location.href = "login.html"; - - agent(); - - //Buttons - $("#btn-contract").on("click", () => { - contract(); - }); - $("#btn-faction").on("click", () => { }); - $("#btn-ship").on("click", () => { }); - $("#btn-system").on("click", () => { }); - $("#btn-logout").on("click", () => { - logout(); - }); -}); - -function loadPage(page) { - $("main").load(`templates/${page}.html`); -} - -function logout() { - localStorage.removeItem("token"); - window.location.href = "login.html"; -} - -async function agent() { - let token = localStorage.getItem("token"); - let agent = await SpaceTraders.Agent.get(token); - - $("#credits").text(agent.credits.toLocaleString() + " $"); -} - -async function contract() { - - const token = localStorage.getItem("token"); - const contracts = await SpaceTraders.Contract.list(token); - - $('main').empty() - - contracts.forEach(contrat => { - let img - let status - let card - console.log(contrat) - if (contrat.type = "PROCUREMENT") { - img = "/img/procurement.png" - } - else if (contrat.type = "TRANSPORT") { - img = "/img/transportation.png" - } - else { - img = "/img/shuttle.png" - } - if (contrat.accepted) { - status = "accepted" - card = - ` -
- -
-
${contrat.factionSymbol}
-

${contrat.deadlineToAccept}

-

Status : ${status}

- -
-
- ` - } - else { - status = "on hold" - card = - ` -
- -
-
${contrat.factionSymbol}
-

${contrat.deadlineToAccept}

-

Status : ${status}

-

Revenu : ${contrat.terms.payment.onAccepted} $

- - -
-
- ` - } - - - - $('main').append(card) - - - $('#btn-infos').on('click', async function () { - const token = localStorage.getItem("token"); - const contrat = await SpaceTraders.Contract.get($(this).attr('contratID'), token); - const modal = ` - ` - $('main').append(modal) - }) - - $('#btn-accept').on('click', async function () { - console.log("test") - const token = localStorage.getItem("token"); - await SpaceTraders.Contract.accept($(this).attr('contratID'), token); - $("#status").html("Status : accepté"); - this.remove(); - }) - - }) -} diff --git a/templates/faction.html b/templates/faction.html deleted file mode 100644 index c5b5593..0000000 --- a/templates/faction.html +++ /dev/null @@ -1 +0,0 @@ -