Add start of ship editing grid
This commit is contained in:
parent
b88c0eb358
commit
2fbabc785e
16 changed files with 249 additions and 18 deletions
|
@ -1,10 +1,66 @@
|
|||
import * as game from './index.mjs';
|
||||
import * as graphics from '../graphics/index.mjs';
|
||||
import * as world from '../world/index.mjs';
|
||||
import * as consts from '../consts.mjs';
|
||||
|
||||
export let tiles = new Map();
|
||||
export let width = 0;
|
||||
export let height = 0;
|
||||
export let position = [0, 0];
|
||||
export let bounds = [0, 0, 0, 0];
|
||||
export let currentModule = null;
|
||||
|
||||
export function init() {
|
||||
graphics.setZoom(20);
|
||||
let ship = world.playerShip;
|
||||
let modules = ship.modules;
|
||||
let margin = consts.EDIT_MARGIN;
|
||||
|
||||
modules.forEach(m => {
|
||||
let pos = [m.x, m.y];
|
||||
tiles.set(posId(...pos), new Tile(...pos, m));
|
||||
});
|
||||
|
||||
let [sx, ex, sy, ey] = getBoundaries();
|
||||
[width, height] = [ex - sx + margin * 2 + 1, ey - sy + margin * 2 + 1];
|
||||
position = [sx - margin, sy - margin];
|
||||
let neededZoom = graphics.canvas.width / (Math.max(width, height) + 10);
|
||||
|
||||
graphics.changePerspective('planet', 0, -5);
|
||||
graphics.setZoom(neededZoom);
|
||||
}
|
||||
|
||||
export function end() {
|
||||
|
||||
}
|
||||
|
||||
export function getTile(x, y) {
|
||||
let id = posId(x, y);
|
||||
if (!tiles.has(id))
|
||||
tiles.set(id, new Tile(x, y, null));
|
||||
return tiles.get(id);
|
||||
}
|
||||
|
||||
function posId(x, y) {
|
||||
return `${x}.${y}`;
|
||||
}
|
||||
|
||||
function getBoundaries() {
|
||||
return [0, 0, 0, 2];
|
||||
}
|
||||
|
||||
class Tile {
|
||||
constructor(x, y, module) {
|
||||
this.module = module;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
get valid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
get drawPos() {
|
||||
let [px, py] = pos;
|
||||
return [this.x + px, this.y + py];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ export function launchShip() {
|
|||
}
|
||||
|
||||
export function editShip() {
|
||||
console.log('a');
|
||||
graphics.changePerspective('parent', -5, 0);
|
||||
game.state.editing = true;
|
||||
edit.init();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue