Start moving to vue
This commit is contained in:
parent
c96c6c8dd0
commit
fe01205341
39 changed files with 456 additions and 344 deletions
5
.postcssrc
Normal file
5
.postcssrc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"plugins": {
|
||||
"autoprefixer": {}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,8 @@
|
|||
Functions to visualize the map and boards for gaia project inside html canvas
|
||||
|
||||
```bash
|
||||
npm run webpack
|
||||
npm install
|
||||
npm run serve
|
||||
```
|
||||
|
||||
And open dist/public/index.html
|
||||
And open localhost:8080 in the browser.
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation: */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "../../build", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
// "strict": true /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
]
|
||||
}
|
||||
26
package.json
26
package.json
|
|
@ -5,8 +5,7 @@
|
|||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"webpack": "webpack-cli",
|
||||
"watch-front": "webpack-cli --watch"
|
||||
"serve": "vue-cli-service serve"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
@ -27,22 +26,21 @@
|
|||
"@types/jquery": "^3.3.1",
|
||||
"@types/node": "^10.5.2",
|
||||
"@types/pixi.js": "^4.7.2",
|
||||
"@vue/cli-plugin-typescript": "^3.0.0-rc.5",
|
||||
"@vue/cli-service": "^3.0.0-rc.5",
|
||||
"bootstrap": "^4.0.0",
|
||||
"copy-webpack-plugin": "^4.5.1",
|
||||
"css-loader": "^1.0.0",
|
||||
"extract-text-webpack-plugin": "^4.0.0-beta.0",
|
||||
"file-loader": "^1.1.11",
|
||||
"html-webpack-plugin": "^3.0.6",
|
||||
"jquery": "^3.3.1",
|
||||
"node-sass": "^4.7.2",
|
||||
"popper.js": "^1.12.9",
|
||||
"resolve-url-loader": "^2.3.0",
|
||||
"sass-loader": "^7.0.3",
|
||||
"style-loader": "^0.21.0",
|
||||
"ts-loader": "^4.4.1",
|
||||
"typescript": "^2.7.2",
|
||||
"url-loader": "^1.0.1",
|
||||
"webpack": "^4.1.1",
|
||||
"webpack-cli": "^3.0.8"
|
||||
}
|
||||
"vue": "^2.5.16",
|
||||
"vue-property-decorator": "^7.0.0",
|
||||
"vuex": "^3.0.1"
|
||||
},
|
||||
"browserslist": [
|
||||
"> 1%",
|
||||
"last 2 versions",
|
||||
"not ie <= 8"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
38
src/App.vue
Normal file
38
src/App.vue
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<template>
|
||||
<div id="app">
|
||||
<Navbar/>
|
||||
<Alert/>
|
||||
<main class="container-fluid">
|
||||
<Game/>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Vue } from 'vue-property-decorator';
|
||||
import Navbar from '@/components/Navbar.vue';
|
||||
import Alert from '@/components/Alert.vue';
|
||||
import Game from '@/components/Game.vue';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
Navbar,
|
||||
Alert,
|
||||
Game
|
||||
},
|
||||
})
|
||||
export default class App extends Vue {
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@import "./stylesheets/frontend.scss";
|
||||
|
||||
#app {
|
||||
// font-family: 'Avenir', Helvetica, Arial, sans-serif;
|
||||
// -webkit-font-smoothing: antialiased;
|
||||
// -moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
@ -2,10 +2,8 @@ import "jquery";
|
|||
import "bootstrap";
|
||||
import "../stylesheets/frontend.scss";
|
||||
import { showError, removeError } from "./utils";
|
||||
import MapRenderer from "../../renderers/map";
|
||||
import ResearchRenderer from "../../renderers/research";
|
||||
import Renderer from "../../renderers";
|
||||
import { AvailableCommand, Command, factions, Building, ResearchField, tiles, Booster, Federation, BoardAction, Event } from "@gaia-project/engine";
|
||||
import { AvailableCommand, Command, factions, Building, tiles, Booster, Federation, Event } from "@gaia-project/engine";
|
||||
import { CubeCoordinates } from "hexagrid";
|
||||
import { buildingName } from "../../data/building";
|
||||
import { factionColor } from "../../graphics/utils";
|
||||
55
src/components/Alert.vue
Normal file
55
src/components/Alert.vue
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<template>
|
||||
<div class="container">
|
||||
<div :class="['alert', 'alert-warning', 'fade', {show: !dismissed}]" role="alert" v-if="error" @transitionend="removeError">
|
||||
{{error}}
|
||||
<button type="button" class="close" aria-label="Fermer" @click="dismissed=true">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div :class="['alert', 'alert-info', 'fade', {show: !infoDismissed}]" role="alert" v-if="info" @transitionend="removeInfo">
|
||||
{{info}}
|
||||
<button type="button" class="close" aria-label="Fermer" @click="infoDismissed=true">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue'
|
||||
import { Component } from 'vue-property-decorator';
|
||||
|
||||
@Component<Alert>({
|
||||
watch: {
|
||||
error(val) {
|
||||
this.dismissed = false;
|
||||
},
|
||||
|
||||
info(val) {
|
||||
this.infoDismissed = false;
|
||||
}
|
||||
}
|
||||
})
|
||||
export default class Alert extends Vue {
|
||||
get error() {
|
||||
return this.$store.state.error;
|
||||
}
|
||||
|
||||
get info() {
|
||||
return this.$store.state.info;
|
||||
}
|
||||
|
||||
removeError() {
|
||||
this.$store.commit('removeError');
|
||||
}
|
||||
|
||||
removeInfo() {
|
||||
this.$store.commit('removeInfo');
|
||||
}
|
||||
|
||||
dismissed = false;
|
||||
infoDismissed = false;
|
||||
}
|
||||
|
||||
</script>
|
||||
48
src/components/Commands.vue
Normal file
48
src/components/Commands.vue
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<template>
|
||||
<div id="move">
|
||||
<div id="move-title">
|
||||
<span v-if="init">Pick the number of players</span>
|
||||
</div>
|
||||
<div id="move-buttons">
|
||||
<div v-if="init">
|
||||
<button class='btn btn-secondary mr-2 mb-2 move-button' v-for="i in [2,3,4,5]" :data-command="`init ${i} randomSeed`">{{i}} players</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue'
|
||||
import { Component } from 'vue-property-decorator';
|
||||
import { AvailableCommand, Command } from '@gaia-project/engine';
|
||||
|
||||
@Component<Commands>({
|
||||
watch: {
|
||||
availableCommands(this: Commands, val) {
|
||||
this.loadCommands(val);
|
||||
}
|
||||
}
|
||||
})
|
||||
export default class Commands extends Vue {
|
||||
loadCommands(val: AvailableCommand[]) {
|
||||
console.log(val);
|
||||
}
|
||||
|
||||
get availableCommands() {
|
||||
return this.$store.state.game.data.availableCommands;
|
||||
}
|
||||
|
||||
get command(): AvailableCommand {
|
||||
return this.availableCommands ? this.availableCommands[0] : null;
|
||||
}
|
||||
|
||||
get init() {
|
||||
return !this.command || this.command.name === Command.Init;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
83
src/components/Game.vue
Normal file
83
src/components/Game.vue
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="row">
|
||||
<canvas id="map">
|
||||
</canvas>
|
||||
</div>
|
||||
<div id="errors"></div>
|
||||
<div class="row mt-2">
|
||||
<div class="col-md-6 order-2 order-md-1">
|
||||
<div v-for="(player, index) in data.players" :id="'p'+(index+1)">
|
||||
<div class="text"></div>
|
||||
<div class="tiles"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 order-1 order-md-2" id="move-panel">
|
||||
<Commands/>
|
||||
<div>
|
||||
<form id="move-form" @submit.prevent="submit">
|
||||
<div class="form-group">
|
||||
<label for="moves">Moves</label>
|
||||
<textarea class="form-control" rows="4" id="moves" v-model="moveList"></textarea>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-primary d-block ml-auto" value="Execute">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tooltip bs-tooltip-left" id="tooltip-canvas" role="tooltip">
|
||||
<div class="arrow"></div>
|
||||
<div class="tooltip-inner">
|
||||
Some tooltip text!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import * as $ from 'jquery';
|
||||
import Vue from 'vue'
|
||||
import { Component } from 'vue-property-decorator';
|
||||
import { Data } from '@/data';
|
||||
import Commands from './Commands.vue';
|
||||
|
||||
@Component<Game>({
|
||||
computed: {
|
||||
data() {
|
||||
return this.$store.state.game.data;
|
||||
}
|
||||
},
|
||||
created(this: Game) {
|
||||
this.submit();
|
||||
},
|
||||
components: {
|
||||
Commands
|
||||
}
|
||||
})
|
||||
export default class Game extends Vue {
|
||||
public moveList = "";
|
||||
|
||||
submit() {
|
||||
const text = this.moveList.trim();
|
||||
const data = {
|
||||
moves: text ? text.split("\n") : []
|
||||
}
|
||||
|
||||
$.post("http://localhost:9508/",
|
||||
data,
|
||||
data => {
|
||||
this.$store.commit('removeError');
|
||||
this.$store.commit('receiveData', data);
|
||||
},
|
||||
"json"
|
||||
).fail((error, status, exception) => {
|
||||
if (error.status === 0) {
|
||||
this.$store.commit("error", "Are you sure gaia engine is running on port 9508?");
|
||||
} else {
|
||||
this.$store.commit("error", "Error " + error.status + ": " + error.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
23
src/components/Navbar.vue
Normal file
23
src/components/Navbar.vue
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<template>
|
||||
<nav class="navbar navbar-dark bg-primary navbar-expand-sm navbar-fixed-top mb-3" id="navbar">
|
||||
<a class="navbar-brand" href="/" @click.prevent>Gaia project</a>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue'
|
||||
import { Component } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class Navbar extends Vue {
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
.navbar {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
import {Player, AdvTechTilePos, AdvTechTile, TechTile, TechTilePos, ScoringTile, FinalTile} from "@gaia-project/engine";
|
||||
import {Player, AdvTechTile, TechTile, TechTilePos, ScoringTile, FinalTile, AvailableCommand} from "@gaia-project/engine";
|
||||
|
||||
export interface AugmentedPlayer extends Player {
|
||||
progress: {[key in FinalTile]: number};
|
||||
}
|
||||
|
||||
export interface Data {
|
||||
availableCommands: AvailableCommand[];
|
||||
players: AugmentedPlayer[];
|
||||
round: number;
|
||||
techTiles: {
|
||||
13
src/main.ts
Normal file
13
src/main.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import 'jquery';
|
||||
import 'popper.js';
|
||||
import 'bootstrap';
|
||||
import Vue from 'vue';
|
||||
import App from './App.vue';
|
||||
import store from './store';
|
||||
|
||||
Vue.config.productionTip = false;
|
||||
|
||||
new Vue({
|
||||
store,
|
||||
render: (h) => h(App),
|
||||
}).$mount('#app');
|
||||
|
|
@ -1,119 +1,119 @@
|
|||
import * as PIXI from "pixi.js";
|
||||
import {GaiaHexData, Planet, Faction, GaiaHex} from "@gaia-project/engine";
|
||||
import { CubeCoordinates, Grid, Direction } from "hexagrid";
|
||||
import PlanetRenderer from "./planet";
|
||||
import BuildingRenderer from "./building";
|
||||
import {hexCenter, corners} from '../graphics/hex';
|
||||
import { factionColor } from "../graphics/utils";
|
||||
|
||||
const hexData = {
|
||||
radius: 16,
|
||||
border: {
|
||||
width: 1,
|
||||
color: 0x666666,
|
||||
},
|
||||
background: 0x172E62,
|
||||
backgroundHighlight: 0xF0F0F0,
|
||||
backgroundQicHighlight: 0x91ffc4
|
||||
};
|
||||
|
||||
type ZonesOfInterest = Array<{coord: CubeCoordinates, qic: boolean, hint?: string}>;
|
||||
|
||||
export default class MapRenderer extends PIXI.Graphics {
|
||||
map: Grid<GaiaHex>;
|
||||
zonesOfInterest: ZonesOfInterest = [];
|
||||
factions: Faction[] = [];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
render(map: Array<CubeCoordinates & {data: GaiaHexData}>, factions: Faction[], zonesOfInterest?: ZonesOfInterest) {
|
||||
const hexes = map.map(elem => new GaiaHex(elem.q, elem.r, elem.data));
|
||||
this.map = new Grid<GaiaHex>(...hexes);
|
||||
this.zonesOfInterest = zonesOfInterest;
|
||||
this.factions = factions;
|
||||
|
||||
this.clear();
|
||||
// Remove existing tooltips
|
||||
for (const child of this.children) {
|
||||
this.emit("tooltip-remove", child);
|
||||
}
|
||||
this.removeChildren();
|
||||
|
||||
for (const hex of this.map.values()) {
|
||||
const ofInterest = zonesOfInterest && zonesOfInterest.find(zone => zone.coord.q === hex.q && zone.coord.r === hex.r);
|
||||
this.drawHex(hex, !!ofInterest, ofInterest && ofInterest.qic, ofInterest && ofInterest.hint);
|
||||
};
|
||||
}
|
||||
|
||||
drawHex(hex: GaiaHex, ofInterest = false, qic = false, hint = null) {
|
||||
const graphics = new PIXI.Graphics();
|
||||
|
||||
const point = hexCenter(hex, hexData.radius);
|
||||
// separate the first from the other corners
|
||||
const [firstCorner, ...otherCorners] = corners(hexData.radius);
|
||||
const vertices = [firstCorner, ...otherCorners, firstCorner];
|
||||
|
||||
graphics.lineStyle(hexData.border.width, 0xFFFFFF, 0.7);
|
||||
graphics.beginFill(ofInterest ? (qic ? hexData.backgroundQicHighlight : hexData.backgroundHighlight) : hexData.background);
|
||||
graphics.drawPolygon([].concat(...vertices.map(p => [p.x, p.y])));
|
||||
graphics.endFill();
|
||||
|
||||
// Draw individual sides
|
||||
graphics.lineStyle(hexData.border.width, hexData.border.color);
|
||||
[Direction.NorthWest, Direction.North, Direction.NorthEast, Direction.SouthEast, Direction.South, Direction.SouthWest].forEach((direction, i) => {
|
||||
const neighbour = this.map.neighbour(hex, direction);
|
||||
|
||||
// Don't draw side if sector is different
|
||||
if (!neighbour || neighbour.data.sector === hex.data.sector) {
|
||||
graphics.drawPolygon([vertices[i].x, vertices[i].y, vertices[i+1].x, vertices[i+1].y]);
|
||||
}
|
||||
});
|
||||
|
||||
if (hex.data.federations) {
|
||||
let radius = hexData.radius;
|
||||
|
||||
// Draw an inner border for each player using the hex for their own federation
|
||||
for (const player of hex.data.federations) {
|
||||
radius -= 1;
|
||||
|
||||
const [firstCorner, ...otherCorners] = corners(radius);
|
||||
graphics.lineStyle(1, factionColor(this.factions[player]));
|
||||
graphics.drawPolygon([].concat(...[firstCorner, ...otherCorners, firstCorner].map(p => [p.x, p.y])));
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw planet if there */
|
||||
if (hex.data.planet !== Planet.Empty) {
|
||||
const planetGraphics = new PlanetRenderer(hex.data.planet, hexData.radius, hexData.border.width);
|
||||
graphics.addChild(planetGraphics);
|
||||
}
|
||||
|
||||
/* Draw building if there */
|
||||
if (hex.data.building) {
|
||||
const building = new BuildingRenderer(hex.data.building, this.factions[hex.data.player], hexData.radius, hexData.border.width);
|
||||
graphics.addChild(building);
|
||||
}
|
||||
|
||||
[graphics.x, graphics.y] = [point.x, point.y];
|
||||
|
||||
graphics.interactive = true;
|
||||
if (ofInterest) {
|
||||
graphics.cursor = "pointer";
|
||||
graphics.on("click", () => {
|
||||
this.emit("hexClick", hex);
|
||||
});
|
||||
}
|
||||
if (hint) {
|
||||
graphics.on("mouseover", () => {
|
||||
this.emit("tooltip", graphics, hint);
|
||||
});
|
||||
graphics.on("mouseout", () => {
|
||||
this.emit("tooltip-remove", graphics);
|
||||
});
|
||||
}
|
||||
|
||||
this.addChild(graphics);
|
||||
}
|
||||
import * as PIXI from "pixi.js";
|
||||
import {GaiaHexData, Planet, Faction, GaiaHex} from "@gaia-project/engine";
|
||||
import { CubeCoordinates, Grid, Direction } from "hexagrid";
|
||||
import PlanetRenderer from "./planet";
|
||||
import BuildingRenderer from "./building";
|
||||
import {hexCenter, corners} from '../graphics/hex';
|
||||
import { factionColor } from "../graphics/utils";
|
||||
|
||||
const hexData = {
|
||||
radius: 16,
|
||||
border: {
|
||||
width: 1,
|
||||
color: 0x666666,
|
||||
},
|
||||
background: 0x172E62,
|
||||
backgroundHighlight: 0xF0F0F0,
|
||||
backgroundQicHighlight: 0x91ffc4
|
||||
};
|
||||
|
||||
type ZonesOfInterest = Array<{coord: CubeCoordinates, qic: boolean, hint?: string}>;
|
||||
|
||||
export default class MapRenderer extends PIXI.Graphics {
|
||||
map: Grid<GaiaHex>;
|
||||
zonesOfInterest: ZonesOfInterest = [];
|
||||
factions: Faction[] = [];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
render(map: Array<CubeCoordinates & {data: GaiaHexData}>, factions: Faction[], zonesOfInterest?: ZonesOfInterest) {
|
||||
const hexes = map.map(elem => new GaiaHex(elem.q, elem.r, elem.data));
|
||||
this.map = new Grid<GaiaHex>(...hexes);
|
||||
this.zonesOfInterest = zonesOfInterest;
|
||||
this.factions = factions;
|
||||
|
||||
this.clear();
|
||||
// Remove existing tooltips
|
||||
for (const child of this.children) {
|
||||
this.emit("tooltip-remove", child);
|
||||
}
|
||||
this.removeChildren();
|
||||
|
||||
for (const hex of this.map.values()) {
|
||||
const ofInterest = zonesOfInterest && zonesOfInterest.find(zone => zone.coord.q === hex.q && zone.coord.r === hex.r);
|
||||
this.drawHex(hex, !!ofInterest, ofInterest && ofInterest.qic, ofInterest && ofInterest.hint);
|
||||
};
|
||||
}
|
||||
|
||||
drawHex(hex: GaiaHex, ofInterest = false, qic = false, hint = null) {
|
||||
const graphics = new PIXI.Graphics();
|
||||
|
||||
const point = hexCenter(hex, hexData.radius);
|
||||
// separate the first from the other corners
|
||||
const [firstCorner, ...otherCorners] = corners(hexData.radius);
|
||||
const vertices = [firstCorner, ...otherCorners, firstCorner];
|
||||
|
||||
graphics.lineStyle(hexData.border.width, 0xFFFFFF, 0.7);
|
||||
graphics.beginFill(ofInterest ? (qic ? hexData.backgroundQicHighlight : hexData.backgroundHighlight) : hexData.background);
|
||||
graphics.drawPolygon([].concat(...vertices.map(p => [p.x, p.y])));
|
||||
graphics.endFill();
|
||||
|
||||
// Draw individual sides
|
||||
graphics.lineStyle(hexData.border.width, hexData.border.color);
|
||||
[Direction.NorthWest, Direction.North, Direction.NorthEast, Direction.SouthEast, Direction.South, Direction.SouthWest].forEach((direction, i) => {
|
||||
const neighbour = this.map.neighbour(hex, direction);
|
||||
|
||||
// Don't draw side if sector is different
|
||||
if (!neighbour || neighbour.data.sector === hex.data.sector) {
|
||||
graphics.drawPolygon([vertices[i].x, vertices[i].y, vertices[i+1].x, vertices[i+1].y]);
|
||||
}
|
||||
});
|
||||
|
||||
if (hex.data.federations) {
|
||||
let radius = hexData.radius;
|
||||
|
||||
// Draw an inner border for each player using the hex for their own federation
|
||||
for (const player of hex.data.federations) {
|
||||
radius -= 1;
|
||||
|
||||
const [firstCorner, ...otherCorners] = corners(radius);
|
||||
graphics.lineStyle(1, factionColor(this.factions[player]));
|
||||
graphics.drawPolygon([].concat(...[firstCorner, ...otherCorners, firstCorner].map(p => [p.x, p.y])));
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw planet if there */
|
||||
if (hex.data.planet !== Planet.Empty) {
|
||||
const planetGraphics = new PlanetRenderer(hex.data.planet, hexData.radius, hexData.border.width);
|
||||
graphics.addChild(planetGraphics);
|
||||
}
|
||||
|
||||
/* Draw building if there */
|
||||
if (hex.data.building) {
|
||||
const building = new BuildingRenderer(hex.data.building, this.factions[hex.data.player], hexData.radius, hexData.border.width);
|
||||
graphics.addChild(building);
|
||||
}
|
||||
|
||||
[graphics.x, graphics.y] = [point.x, point.y];
|
||||
|
||||
graphics.interactive = true;
|
||||
if (ofInterest) {
|
||||
graphics.cursor = "pointer";
|
||||
graphics.on("click", () => {
|
||||
this.emit("hexClick", hex);
|
||||
});
|
||||
}
|
||||
if (hint) {
|
||||
graphics.on("mouseover", () => {
|
||||
this.emit("tooltip", graphics, hint);
|
||||
});
|
||||
graphics.on("mouseout", () => {
|
||||
this.emit("tooltip-remove", graphics);
|
||||
});
|
||||
}
|
||||
|
||||
this.addChild(graphics);
|
||||
}
|
||||
}
|
||||
32
src/store.ts
Normal file
32
src/store.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import { Data } from './data';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
export default new Vuex.Store({
|
||||
state: {
|
||||
game: {data: {players: []}} as {data: Data},
|
||||
error: null as string,
|
||||
info: null as string,
|
||||
errorIssued: null as Date,
|
||||
infoIssued: null as Date
|
||||
},
|
||||
mutations: {
|
||||
receiveData: (state, data: Data) => {
|
||||
state.game.data = data;
|
||||
},
|
||||
|
||||
error: (state, error: string) => { state.error = error; state.errorIssued = new Date(); },
|
||||
info: (state, info: string) => { state.info = info; state.infoIssued = new Date(); },
|
||||
removeError: state => state.error = state.errorIssued = null,
|
||||
removeInfo: state => state.info = state.infoIssued = null
|
||||
},
|
||||
actions: {
|
||||
|
||||
},
|
||||
getters: {
|
||||
data: state => state.game.data,
|
||||
availableCommands: state => state.game.data.availableCommands
|
||||
}
|
||||
});
|
||||
|
|
@ -35,10 +35,6 @@ canvas#map {
|
|||
@extend .mb-2;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.tooltip#tooltip-canvas {
|
||||
opacity: 1;
|
||||
display: none;
|
||||
|
|
@ -1,55 +1,25 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation: */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"target": "es2017",
|
||||
"module": "es2015",
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
// "strict": true /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
}
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
"baseUrl": ".",
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.vue",
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
3
vue.config.js
Normal file
3
vue.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
lintOnSave: false
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
const webpack = require("webpack");
|
||||
const path = require("path");
|
||||
|
||||
const distDir = path.join(__dirname, "dist/public/");
|
||||
|
||||
module.exports = {
|
||||
context: path.join(__dirname, 'app/assets'),
|
||||
resolve: {
|
||||
extensions: ['.ts', '.tsx', '.js', '.jsx']
|
||||
},
|
||||
output: {
|
||||
path: distDir,
|
||||
filename: "javascript/[name].js"
|
||||
},
|
||||
entry: {
|
||||
main: "./typescript/index"
|
||||
},
|
||||
mode: "development",
|
||||
devtool: "source-map",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
use: "ts-loader?configFile=app/assets/tsconfig.json"
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
use: ["css-loader", "resolve-url-loader"],
|
||||
fallback: "style-loader"
|
||||
})
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
use: [{
|
||||
loader: "css-loader"
|
||||
}, {
|
||||
loader: "resolve-url-loader"
|
||||
}, {
|
||||
loader: "sass-loader?sourceMap"
|
||||
}],
|
||||
fallback: "style-loader"
|
||||
})
|
||||
},
|
||||
{
|
||||
test: /\.(ttf|eot|svg|jpg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
||||
use: "file-loader?publicPath=../&name=./files/[hash].[ext]"
|
||||
},
|
||||
{
|
||||
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
||||
use: "url-loader?publicPath=../&name=./files/[hash].[ext]&limit=10000&mimetype=application/font-woff"
|
||||
},
|
||||
{
|
||||
test: /\.png$/,
|
||||
use: "url-loader?publicPath=../&name=./files/[hash].[ext]&limit=10000&mimetype=image/png"
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
// new CopyWebpackPlugin([{
|
||||
// context: __dirname,
|
||||
// from: "node_modules/jquery/dist/jquery.min.js",
|
||||
// to: "javascript"
|
||||
// }, {
|
||||
// context: __dirname,
|
||||
// from: "node_modules/popper.js/dist/umd/popper.min.js",
|
||||
// to: "javascript"
|
||||
// }, {
|
||||
// from: 'images/profile-joined-litnovel.png',
|
||||
// to: 'images'
|
||||
// }]),
|
||||
new webpack.ProvidePlugin({
|
||||
$: 'jquery',
|
||||
jQuery: 'jquery',
|
||||
'window.jQuery': 'jquery',
|
||||
'@gaia-project/engine': null,
|
||||
// Popper: ['popper.js', 'default']
|
||||
}),
|
||||
new ExtractTextPlugin("stylesheets/styles.css"),
|
||||
new HtmlWebpackPlugin({
|
||||
template: 'views/index.html',
|
||||
filename: path.join(distDir, 'index.html')
|
||||
}),
|
||||
// Ignore code that the gaia project engine doesn't run as a dependency
|
||||
// new webpack.IgnorePlugin(/^\.\/app$/, /@gaia-project(\/|\\)engine(\/|\\)dist$/)
|
||||
],
|
||||
// externals: {
|
||||
// jquery: 'jQuery'
|
||||
// }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue