Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple new features #164

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# Configure editors!
root = true

# Unix-style newlines with a newline ending every file
# Unix-style newlines using UTF-8 encoding with 2 space indentations
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,ts}]
charset = utf-8
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{*.json,.travis.yml}]
indent_style = space
indent_size = 2

36 changes: 36 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
* text=auto

.editorconfig text eol=lf
.gitattributes text eol=lf
.gitconfig text eol=lf
.gitignore text eol=lf
.jsbeautifyrc text eol=lf
*.css text eol=lf
*.htm text eol=lf diff=html
*.html text eol=lf diff=html
*.js text eol=lf
*.json text eol=lf
*.js.map text eol=lf
*.md text eol=lf
*.sh text eol=lf
*.ts text eol=lf
*.tsx text eol=lf
*.d.ts text eol=lf
*.txt text eol=lf
*.xml text eol=lf
*.yml text eol=lf

battlecode-client-17 binary
*.asar binary
*.bin binary
*.dat binary
*.dll binary
*.exe binary
*.gif binary diff=exif
*.jpg binary diff=exif
*.jpeg binary diff=exif
*.pak binary
*.png binary diff=exif
*.so binary
*.svg binary diff=exif

6 changes: 6 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[diff "exif"]
binary = true
# npm install --save-dev exif-cli
textconv = exif
#caches blob results, but be sure to run `git update-ref -d refs/notes/textconv/exif` if exif-cli is updated
cachetextconv = true
36 changes: 36 additions & 0 deletions .jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"indent_size": 2,
"indent_char": " ",
"eol": "\n",
"indent_level": 0,
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 2,
"jslint_happy": false,
"space_after_anon_function": false,
"brace_style": "collapse,preserve-inline",
"keep_array_indentation": false,
"keep_function_indentation": false,
"space_before_conditional": true,
"space_in_paren ": false,
"space_in_empty_paren ": false,
"break_chained_methods": true,
"eval_code": false,
"unescape_strings": true,
"wrap_line_length": 0,
"wrap_attributes": "auto",
"wrap_attributes_indent_size": 4,
"e4x": false,
"end_with_newline": true,
"comma_first": false,
"operator_position": "before-newline",
"html":{
"indent_inner_html": true,
"unformatted": ["inline"],
"content_unformatted": ["pre"],
"extra_liners": ["head","body","/html"]
},
"css":{
"newline_between_rules": true
}
}
173 changes: 125 additions & 48 deletions electron-main.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,64 @@
// This is the electron 'main' file.
// All it does is launch a pseudo-browser that runs battlecode.

var electron = require('electron');
const electron = require('electron');
const {BrowserWindow} = require('electron');
const {ipcMain} = require('electron');
const path = require('path');
const url = require('url');

// Module to create native browser window.
var BrowserWindow = electron.BrowserWindow;

var path = require('path');
var url = require('url');

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow;

//define global variables that can be accessed in all contexts
global.appWindow = mainWindow;
global.appParameters = {params: process.argv};


initApp();


// Setup the application, including the event listeners that trigger the creation of the GUI
function initApp() {

//Place any electron methods that need to be executed before the ready event here:
// for example: electron.app.disableHardwareAcceleration();


//Place electron app events here:

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
electron.app.on('ready', createWindow);

// Quit when all windows are closed.
electron.app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
electron.app.quit();
}
});

electron.app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
});
}

// Sets up and initializes the BrowserWindow used for displaying the content
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1600, height: 1000});

// and load the index.html of the app.
// Create the browser window but don't show it to the user yet
mainWindow = new BrowserWindow({width: 1600, height: 1000, show: false, defaultEncoding: 'UTF-8'});

// Load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
Expand All @@ -27,46 +68,82 @@ function createWindow () {
}
}));

// Open the DevTools.
// mainWindow.webContents.openDevTools();
// Tells chromium to render the webpage content 60 times a second
// This is not to be confused with the renderer FPS which is handled independently
mainWindow.webContents.setFrameRate(60);

// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should devare the corresponding element.
mainWindow = null;
});
// Register the event listeners for mainWindow that render and show it to the user
registerEventListenersForMainWindow();

// Clicking on a URL with target="_blank" should use your computer's
// default browser.
mainWindow.webContents.on('new-window', function(event, url){
event.preventDefault();
electron.shell.openExternal(url);
});
// Tell the main context to start listening for renderer request events
registerEventListenersForRendererRequestEvents();
}

// Registers the event listeners that activate upon the MainWindow DOM loading completion (aka, the HTML has finished
// being loaded). The event listeners begin the window render, and then show the window to the user upon the completion
// of that render.
function registerEventListenersForMainWindow(){

//Wait for the window render to finish before showing the window to the user
mainWindow.once('ready-to-show', function () {
// And then triggers the show
mainWindow.show();
});

// Wait for the window to be shown before starting the match
mainWindow.once('show', function () {
mainWindow.webContents.send('client-ready', 'true');

// Open the DevTools.
//mainWindow.webContents.openDevTools();
});

// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should devare the corresponding element.
mainWindow = null;
});

// Clicking on a URL with target="_blank" should use your computer's
// default browser.
mainWindow.webContents.on('new-window', function(event, url){
event.preventDefault();
electron.shell.openExternal(url);
});
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
electron.app.on('ready', createWindow);

// Quit when all windows are closed.
electron.app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
electron.app.quit();
}
});

electron.app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

// Registers event listeners that perform certain tasks for the renderer thread when they
// receive a 'renderer-request' event with a matching message type.
// Currently the supported request messages are: 'block-power-save' and 'unblock-power-save'
// The renderer thread can register for a callback 'renderer-request-response' event containing the
// original message + a boolean result field that represent success (true) or failure (false)
function registerEventListenersForRendererRequestEvents(){

var powerBlockId = null;

ipcMain.on('renderer-request', (event, message) => {
if(message.type === 'block-power-save'){
if(powerBlockId === null){
powerBlockId = powerSaveBlocker.start("prevent-display-sleep");
message.result = true;
}else{
console.warn("The 'block-power-save' request was unsuccessful.");
message.result = false;
}
}
else if(message.type === 'unblock-power-save'){
if(powerBlockId !== null){
powerSaveBlocker.stop(powerBlockId);
powerBlockId = null;
message.result = true;
}else{
console.warn("The 'unblock-power-save' request was unsuccessful.");
message.result = false;
}
}
event.sender.send('renderer-request-response', message);
});
}
13 changes: 8 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Battlecode Client</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Graduate">
<link rel="preconnect dns-prefetch" href="https://fonts.googleapis.com" crossorigin="anonymous">
<link rel="preconnect dns-prefetch" href="https://fonts.gstatic.com" crossorigin="anonymous">
<link rel="stylesheet preload" href="https://fonts.googleapis.com/css?family=Graduate&subset=latin">
</head>
<body>
<div id='client'/>
<script type="text/javascript" src="bc17/bundle.js" charset="utf-8"></script>
<div id='client'></div>
<script type="text/javascript" src="./bc17/bundle.js"></script>
<script type="text/javascript">
window.battleClient = window.battlecode.mount(
document.getElementById('client'),
{ websocketURL: "ws://localhost:6175" }
{ Socketurl: "ws://localhost:6175" }
);
</script>
</body>
Expand Down
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"private": "true",
"scripts": {
"test": "true",
"clean": "rm -rf out outtest bc17",
"lint": "tslint \"**/*.ts\" -e \"out/**\"",
"clean": "rm -rf out outtest bc17 dist",
"lint": "tslint \"/src/**/*.ts\" -e \"out/**\"",
"format-in-place": "js-beautify --editorconfig -f ./*.js ./*.html src/static/css/*.css -r && tsfmt -r",
"build": "webpack",
"prod": "webpack",
"watch": "echo '--- open localhost:8080 in your browser ---' && webpack-dev-server --env.dev",
Expand All @@ -24,25 +25,36 @@
},
"homepage": "https://github.com/battlecode/battlecode-client-17#readme",
"dependencies": {
"battlecode-playback": "git+ssh://[email protected]/battlecode/battlecode-playback.git#7bf19912b098bcf6e3d637d90f050b27b6bac815",
"battlecode-playback": "battlecode/battlecode-playback#7bf19912b098bcf6e3d637d90f050b27b6bac815",
"file-loader": "^0.9.0",
"file-url": "^2.0.0",
"nomnom": "^1.8.1",
"url-loader": "^0.5.7",
"victor": "^1.1.0"
},
"devDependencies": {
"@types/blue-tape": "^0.1.30",
"@types/electron": "^1.4.30",
"@types/file-url": "^1.0.28",
"@types/nomnom": "^0.0.28",
"@types/victor": "^0.2.28",
"awesome-typescript-loader": "^3.0.0-beta.17",
"copy-webpack-plugin": "^4.0.0",
"css-loader": "^0.26.1",
"electron": "^1.4.13",
"electron-builder": "^10.13.1",
"file-loader": "^0.9.0",
"exif-cli": "0.0.2",
"imagemin-webpack-plugin": "^1.4.4",
"img-loader": "^1.3.1",
"js-beautify": "^1.6.8",
"minimatch": "^3.0.3",
"style-loader": "^0.13.1",
"ts-loader": "^0.8.2",
"tslint": "^3.15.1",
"typescript": "^2.1.4",
"url-loader": "^0.5.7",
"webpack": "^2.2.0-rc.2",
"typescript-formatter": "^4.0.1",
"uglify-js": "mishoo/UglifyJS2#harmony",
"webpack": "^v2.2.0-rc.7",
"webpack-dev-server": "^2.2.0-rc.0",
"webpack-merge": "^2.0.0"
},
Expand Down
Loading