Skip to content

Commit

Permalink
goban code successfully broken out, pending npm publishing before we …
Browse files Browse the repository at this point in the history
…merge
  • Loading branch information
anoek committed Oct 3, 2019
1 parent e3be059 commit 4f2a07b
Show file tree
Hide file tree
Showing 20 changed files with 392 additions and 1,392 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ typings
*.swo
webpack-stats.json
analyze.json
stats.json
src/components/base
.vscode
todo
Expand All @@ -15,6 +16,7 @@ how_to_add_a_new_language.txt
.DS_Store
/.alm/
package-lock.json
report.*.json



Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 1 addition & 1 deletion Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function min_styl(done) {
function background_webpack(done) {
function spawn_webpack() {
let env = process.env;
let webpack = spawn('node', ['node_modules/webpack/bin/webpack.js', '--watch', '--progress', '--colors'], { stdio: 'inherit' })
let webpack = spawn('npm', ['run', 'webpack-watch'], { stdio: 'inherit' })

webpack.on('exit', spawn_webpack);
}
Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ PATH:=node_modules/.bin/:$(PATH)


dev: node_modules
NODE_PATH=$(NODE_PATH) PATH=$(PATH) supervisor -w Gulpfile.js,webpack.config.js,tsconfig.json supervisor -w Gulpfile.js -x gulp --
npm run dev

node_modules:
npm install yarn
npm install supervisor
NODE_PATH=$(NODE_PATH) PATH=$(PATH) yarn install
npm run yarn install

pretty prettier:
npm run prettytsx
npm run prettyts

lint tslint:
NODE_PATH=$(NODE_PATH) PATH=$(PATH) tslint --project tsconfig.json
npm run tslint -- --project tsconfig.json

min: minjs mincss

mincss:
NODE_PATH=$(NODE_PATH) PATH=$(PATH) gulp min_styl
npm run gulp min_styl
@echo 'gzipped ogs.min.css: ' `gzip -9 dist/ogs.min.css -c | wc -c`

minjs:
NODE_PATH=$(NODE_PATH) PATH=$(PATH) PRODUCTION=true webpack --optimize-minimize --devtool=source-map --display-modules
npm run webpack -- --mode production --optimize-minimize --devtool=source-map --display-modules
@echo 'gzipped ogs.min.js: ' `gzip -9 dist/ogs.min.js -c | wc -c`
@echo 'gzipped vendor.min.js: ' `gzip -9 dist/vendor.min.js -c | wc -c`

analyze:
#NODE_PATH=$(NODE_PATH) PATH=$(PATH) PRODUCTION=true webpack --optimize-minimize --devtool=source-map --profile --json > analyze.json
#npm run webpack-bundle-analyzer dist/ analyze.json
npm run webpack-bundle-analyzer analyze.json dist/
ANALYZE=true npm run analyze

#NODE_PATH=$(NODE_PATH) PATH=$(PATH) PRODUCTION=true webpack --optimize-minimize --devtool=source-map --profile --json > analyze.json
#npm run webpack-bundle-analyzer dist/ analyze.json

.PHONY: dev lint tslint min minjs mincss

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
"license": "AGPL-3.0",
"private": true,
"scripts": {
"dev": "gulp",
"dev": "supervisor -w Gulpfile.js,webpack.config.js,tsconfig.json supervisor -w Gulpfile.js -x gulp --",
"prettytsx": "prettier --write 'src/**/*.tsx'",
"prettyts": "prettier --write 'src/**/*.ts'",
"webpack": "webpack",
"webpack-bundle-analyzer": "webpack-bundle-analyzer"
"webpack-watch": "webpack --watch --progress --colors",
"yarn": "yarn",
"tslint": "tslint",
"gulp": "gulp",
"analyze": "webpack --mode production --profile --optimize-minimize --devtool=source-map"
},
"browserslist": [
"defaults"
Expand Down Expand Up @@ -40,7 +44,7 @@
"tslint": "^5.20.0",
"typescript": "^3.6.3",
"webpack": "^4.41.0",
"webpack-bundle-analyzer": "",
"webpack-bundle-analyzer": "^3.5.2",
"webpack-cli": "^3.3.9",
"xgettext-js": "^1.1.0",
"yarn": "^1.19.0"
Expand All @@ -66,7 +70,7 @@
"jsonwebtoken": "^8.5.1",
"markdown-it": "^8.4.2",
"moment": "^2.24.0",
"ogs-goban": "file:../ogs-goban",
"goban": "file:../goban",
"prop-types": "^15.5.0",
"query-string": "^5.0.1",
"react": "^16.9.0",
Expand All @@ -84,10 +88,8 @@
"react-virtualized": "^9.21.0",
"redux": "^3.7.2",
"sanitize-html": "^1.14.1",
"slugify": "^1.3.4",
"ts-md5": "^1.2.5",
"valid-url": "^1.0.9",
"webpack-bundle-analyzer": "^3.4.1",
"whatwg-fetch": "^3.0.0"
}
}
99 changes: 99 additions & 0 deletions src/lib/configure-goban.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2012-2019 Online-Go.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import * as preferences from "preferences";
import * as data from "data";
import {get_clock_drift, get_network_latency, termination_socket} from 'sockets';
import {current_language} from "translate";
import {Goban, GoEngine, sfx, GoThemes} from 'goban';

window['Goban'] = Goban;
window['GoThemes'] = GoThemes;
window['GoEngine'] = GoEngine;
window['sfx'] = sfx;

data.setDefault("custom.black", "#000000");
data.setDefault("custom.white", "#FFFFFF");
data.setDefault("custom.board", "#DCB35C");
data.setDefault("custom.line", "#000000");

export function configure_goban() {
Goban.setHooks({
defaultConfig: () => {
return {
server_socket : termination_socket,
player_id : (data.get("user").anonymous ? 0 : data.get("user").id),
};
},

getCoordinateDisplaySystem: ():'A1'|'1-1' => {
switch (preferences.get('board-labeling')) {
case 'A1':
return 'A1';
case '1-1':
return '1-1';
default: // auto
switch (current_language) {
case 'ko':
case 'ja':
case 'zh-cn':
return '1-1';
default:
return 'A1';
}
}
},

isAnalysisDisabled: (goban:Goban, perGameSettingAppliesToNonPlayers = false):boolean => {
// The player's preference setting to always disable analysis overrides the per-game setting for
// their own games.
if (preferences.get("always-disable-analysis") && goban.isParticipatingPlayer()) {
return true;
}

// If the user hasn't enabled the always-disable-analysis option (or they do not participate in this game),
// we check the per-game setting.
if (perGameSettingAppliesToNonPlayers) {
// This is used for the SGF download which is disabled even for users that are not
// participating in the game (or not signed in)
return goban.engine.config.original_disable_analysis;
} else {
return goban.engine.config.disable_analysis;
}
},

getClockDrift: ():number => get_clock_drift(),
getNetworkLatency: ():number => get_network_latency(),
getLocation: ():string => window.location.pathname,
getShowMoveNumbers: ():boolean => !!preferences.get("show-move-numbers"),
getShowVariationMoveNumbers: ():boolean => preferences.get("show-variation-move-numbers"),
getMoveTreeNumbering: ():string => preferences.get("move-tree-numbering"),
getCDNReleaseBase: ():string => data.get('config.cdn_release'),
getSoundEnabled: ():boolean => !!preferences.get('sound-enabled'),
getSoundVolume: ():number => preferences.get('sound-volume') as number,

watchSelectedThemes: (cb) => preferences.watchSelectedThemes(cb),
getSelectedThemes: () => preferences.getSelectedThemes(),

discBlackStoneColor: ():string => data.get("custom.black"),
discBlackTextColor: ():string => data.get("custom.white"),
discWhiteStoneColor: ():string => data.get("custom.white"),
discWhiteTextColor: ():string => data.get("custom.black"),
plainBoardColor: ():string => data.get("custom.board"),
plainBoardLineColor: ():string => data.get("custom.line"),
});
}
146 changes: 0 additions & 146 deletions src/lib/goban-themes/board_plain.ts

This file was deleted.

Loading

0 comments on commit 4f2a07b

Please sign in to comment.