import menu_mod from "./menu_mod.js"; import { Modal } from "../skama_code/ui/modal.js"; import { Ship } from "../skama_code/api/ship.js"; export default (temp_engine) => { let modal = new Modal("ship-modal", temp_engine); let slideIndex = 1; temp_engine.after_render((temp_engine) => { menu_mod(temp_engine); $("body").css("background-image", "url('/assets/spaceships/hangar.png')") modal.load("templates/ships/ships_modal.html"); Ship.list((ships) => { ships.forEach(ship => { $(".block-ships").prepend( `
${ship.symbol}
` ) }); showSlides(1) temp_engine.add_event(".reg", "click", (e) => { const id_ship = $(e.target).attr("data-symbol"); ships.forEach(ship =>{ if(ship.symbol==id_ship) { $(".infos").html(""); $(".infos").append(`

Name : ${ship.registration.name}

`); $(".infos").append(`

Faction : ${ship.registration.factionSymbol}

`); $(".infos").append(`

Role : ${ship.registration.role}

`); } }) modal.show(); }); temp_engine.add_event(".nav", "click", (e) => { const id_ship = $(e.target).attr("data-symbol"); ships.forEach(ship =>{ if(ship.symbol==id_ship) { $(".infos").html(""); $(".infos").append(`

Current system : ${ship.nav.systemSymbol}

`); $(".infos").append(`

Current waypoint : ${ship.nav.waypointSymbol}

`); $(".infos").append(`

Current status : ${ship.nav.status}

`); $(".infos").append(`

Flight mode : ${ship.nav.flightMode}

`); } }) modal.show(); }); temp_engine.add_event(".crew", "click", (e) => { const id_ship = $(e.target).attr("data-symbol"); ships.forEach(ship =>{ if(ship.symbol==id_ship) { $(".infos").html(""); $(".infos").append(`

Current member : ${ship.crew.current}

`); $(".infos").append(`

Capacity : ${ship.crew.capacity}

`); $(".infos").append(`

required member : ${ship.crew.required}

`); $(".infos").append(`

Moral : ${ship.crew.morale}

`); } }) modal.show(); }); temp_engine.add_event(".frame", "click", (e) => { const id_ship = $(e.target).attr("data-symbol"); ships.forEach(ship =>{ if(ship.symbol==id_ship) { $(".infos").html(""); $(".infos").append(`

Name : ${ship.frame.name}

`); $(".infos").append(`

Description : ${ship.frame.description}

`); $(".infos").append(`

Fuel capacity : ${ship.frame.fuelCapacity}

`); $(".infos").append(`

Condition : ${ship.frame.condition}

`); $(".infos").append(`

Power : ${ship.frame.requirements.power}

`); $(".infos").append(`

Crew : ${ship.frame.requirements.crew}

`); } }) modal.show(); }); temp_engine.add_event(".react", "click", (e) => { const id_ship = $(e.target).attr("data-symbol"); ships.forEach(ship =>{ if(ship.symbol==id_ship) { $(".infos").html(""); $(".infos").append(`

Name : ${ship.reactor.name}

`); $(".infos").append(`

Description : ${ship.reactor.description}

`); $(".infos").append(`

Condition : ${ship.reactor.condition}

`); $(".infos").append(`

Power : ${ship.reactor.powerOutput}

`); $(".infos").append(`

Crew : ${ship.reactor.requirements.crew}

`); } }) modal.show(); }); temp_engine.add_event(".engine", "click", (e) => { const id_ship = $(e.target).attr("data-symbol"); ships.forEach(ship =>{ if(ship.symbol==id_ship) { $(".infos").html(""); $(".infos").append(`

Name : ${ship.engine.name}

`); $(".infos").append(`

Description : ${ship.engine.description}

`); $(".infos").append(`

Condition : ${ship.engine.condition}

`); $(".infos").append(`

Speed : ${ship.engine.speed}

`); $(".infos").append(`

Crew : ${ship.engine.requirements.crew}

`); $(".infos").append(`

Power : ${ship.engine.requirements.power}

`); } }) modal.show(); }); temp_engine.add_event(".fuel", "click", (e) => { const id_ship = $(e.target).attr("data-symbol"); ships.forEach(ship =>{ if(ship.symbol==id_ship) { $(".infos").html(""); $(".infos").append(`

current fuel : ${ship.fuel.current}

`); $(".infos").append(`

Description : ${ship.fuel.capacity}

`); $(".infos").append(`

Condition : ${ship.fuel.consumed.amount}

`); $(".infos").append(`

Speed : ${ship.fuel.consumed.timestamp}

`); } }) modal.show(); }); $(".ships-list").on("click", (e) => { const id_ship = $(e.target).attr("data-id"); ships.forEach(ship =>{ if(ship.symbol==id_ship) { } }) }); }); function showSlides(n) { let i; slideIndex += n; let slides = $(".ships-list"); if (slideIndex > slides.length) slideIndex = 1; if (slideIndex < 1) {slideIndex = slides.length} for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } slides[slideIndex-1].style.display = "block"; let img = slideIndex[slideIndex - 1].children(".imgShip"); if (n > 0) { img.animate({left: '250px'}) } else { } } temp_engine.add_event(".btn-close", "click", () => { modal.close(); }); temp_engine.add_event(".prev", "click", () => { showSlides(-1); }); temp_engine.add_event(".next", "click", () => { showSlides(1); }); }); temp_engine.render("templates/ships/ships.html"); };