Librarried (#7)

This commit is contained in:
gavin
2018-07-24 01:03:03 +00:00
committed by Gitea
parent 2c19266ca6
commit 18f978cc8a
6 changed files with 29 additions and 46 deletions

1
.gitignore vendored
View File

@@ -8,4 +8,5 @@ node_modules/*
hexmine hexmine
public/js/main.js public/js/main.js
public/js/tessellate.js

View File

@@ -2,7 +2,7 @@
"name": "tessellate", "name": "tessellate",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "webpack.config.js", "main": "./public/js/tessellate.js",
"scripts": { "scripts": {
"build": "webpack --mode production", "build": "webpack --mode production",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"

View File

@@ -10,6 +10,7 @@
<body> <body>
<div id="container" style="width: 100vw; height: 100vh;"></div> <div id="container" style="width: 100vw; height: 100vh;"></div>
<script src="js/tessellate.js"></script>
<script src="js/main.js"></script> <script src="js/main.js"></script>
</body> </body>
</html> </html>

View File

@@ -1,9 +1,3 @@
import Tessellate from './tessellate.js';
import {utils} from './tessellate.js';
import {DrawCircle, DrawHexagon, DrawSquare} from './tessellate.js';
import {Cell} from './tessellate.js';
const DEFAULTS = { const DEFAULTS = {
board: Tessellate.BOARD_STYLES.HEX, board: Tessellate.BOARD_STYLES.HEX,
style: Tessellate.DRAW_STYLES.FILL, style: Tessellate.DRAW_STYLES.FILL,
@@ -21,7 +15,7 @@ class Demo {
'draw', 'draw',
].map(method => this[method] = this[method].bind(this)); ].map(method => this[method] = this[method].bind(this));
const queryStringObj = utils.getQueryStringObj(); const queryStringObj = Tessellate.utils.getQueryStringObj();
this.settings = Object.assign({}, DEFAULTS, queryStringObj); this.settings = Object.assign({}, DEFAULTS, queryStringObj);
@@ -34,17 +28,10 @@ class Demo {
tap: this.onTap, tap: this.onTap,
draw: this.draw, draw: this.draw,
}, this.settings)); }, this.settings));
this.circle = new DrawCircle();
this.square = new DrawSquare();
this.hexagon = new DrawHexagon();
this.tiles = ['circle', 'hexagon', 'square'];
this.styles = ['filled', 'outline'];
} }
setOriginTile() { setOriginTile() {
this.map['0,0'] = new Cell({ this.map['0,0'] = new Tessellate.Cell({
x: 0, x: 0,
y: 0, y: 0,
scale: 1, scale: 1,
@@ -57,10 +44,10 @@ class Demo {
alpha: 1, alpha: 1,
}); });
utils.rangeInclusive(0, 5) Tessellate.utils.rangeInclusive(0, 5)
.map(interval => interval ? interval * 0.2 : 0.01) .map(interval => interval ? interval * 0.2 : 0.01)
.forEach(interval => { .forEach(interval => {
this.taps.push(new Cell({ this.taps.push(new Tessellate.Cell({
x: 0, x: 0,
y: 0, y: 0,
scale: interval, scale: interval,
@@ -82,26 +69,26 @@ class Demo {
tap.tile.x, tap.tile.x,
tap.tile.y, tap.tile.y,
utils.random(Tessellate.DRAW_STYLES), Tessellate.utils.random(Tessellate.DRAW_STYLES),
utils.random(Tessellate.TILE_STYLES), Tessellate.utils.random(Tessellate.TILE_STYLES),
utils.random(Tessellate.TILE_ORIENTATIONS), Tessellate.utils.random(Tessellate.TILE_ORIENTATIONS),
)); ));
} }
createTile(x, y, drawStyle, tileStyle, orientation) { createTile(x, y, drawStyle, tileStyle, orientation) {
return new Cell({ return new Tessellate.Cell({
x, y, x, y,
scale: utils.random(7, 9) / 10, scale: Tessellate.utils.random(7, 9) / 10,
drawStyle, drawStyle,
tileStyle, tileStyle,
orientation, orientation,
red: utils.random(255), red: Tessellate.utils.random(255),
green: utils.random(255), green: Tessellate.utils.random(255),
blue: utils.random(255), blue: Tessellate.utils.random(255),
alpha: utils.random(25,75)/100 alpha: Tessellate.utils.random(25,75)/100
}); });
} }

View File

@@ -1,8 +1,5 @@
import * as utils from './utils'; import * as utils from './utils';
export {utils};
import * as funky from './funky'; import * as funky from './funky';
export {funky};
import OnTap from './onTap.js'; import OnTap from './onTap.js';
import Point from './point.js'; import Point from './point.js';
@@ -11,10 +8,8 @@ import Sketch from './sketch.js';
import DrawCircle from './drawCircle.js'; import DrawCircle from './drawCircle.js';
import DrawSquare from './drawSquare.js'; import DrawSquare from './drawSquare.js';
import DrawHexagon from './drawHexagon.js'; import DrawHexagon from './drawHexagon.js';
export {DrawCircle, DrawHexagon, DrawSquare};
import Cell from './cell.js'; import Cell from './cell.js';
export {Cell};
import CartographerFlatXY from './cartographerFlatXY.js'; import CartographerFlatXY from './cartographerFlatXY.js';
import CartographerPointyXY from './cartographerPointyXY.js'; import CartographerPointyXY from './cartographerPointyXY.js';
@@ -61,13 +56,18 @@ function selectCartographer(board, orientation) {
} }
} }
export default class Tessellate { export class Tessellate {
static get TILES() {return TILES}
static get TILE_STYLES() {return TILE_STYLES} static get TILE_STYLES() {return TILE_STYLES}
static get BOARD_STYLES() {return BOARD_STYLES} static get BOARD_STYLES() {return BOARD_STYLES}
static get TILE_ORIENTATIONS() {return TILE_ORIENTATIONS} static get TILE_ORIENTATIONS() {return TILE_ORIENTATIONS} // TODO: rename to ORIENTATION_STYLES
static get DRAW_STYLES() {return DRAW_STYLES} static get DRAW_STYLES() {return DRAW_STYLES}
static get TILES() {return TILES}
static get Cell() {return Cell}
static get utils() {return utils}
static get funky() {return funky}
constructor(settings) { constructor(settings) {
[ [
'checkSettings', 'checkSettings',

View File

@@ -1,11 +1,14 @@
var path = require('path'); var path = require('path');
module.exports = { module.exports = {
entry: path.join(__dirname, 'src', 'main.js'), entry: {
main: [path.join(__dirname, 'src', 'main.js')],
Tessellate: [path.join(__dirname, 'src', 'tessellate.js')],
},
output: { output: {
libraryTarget: 'this', libraryTarget: 'this',
path: path.join(__dirname, 'public', 'js'), path: path.join(__dirname, 'public', 'js'),
filename: 'main.js' filename: '[name].js'
}, },
devtool: 'inline-source-map', devtool: 'inline-source-map',
module: { module: {
@@ -18,14 +21,5 @@ module.exports = {
} }
] ]
} }
// module: {
// loaders: [{
// test: path.join(__dirname, 'src'),
// loader: 'babel-loader',
// query: {
// presets: ['es2015']
// }
// }]
// }
}; };