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

Webpack: ES6 import + const + let #95

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6261de5
Fix typo (change DECK_DEFINITONS to DECK_DEFINITIONS)
wmakley Oct 13, 2019
830a6cf
add .editorconfig
wmakley Oct 13, 2019
643fea4
apparently the line endings are crlf
wmakley Oct 13, 2019
59177cf
ignore .idea
wmakley Oct 13, 2019
b2b71aa
make crlf the default only for .js and .html
wmakley Oct 13, 2019
7c62505
fix implicit global variable
wmakley Oct 13, 2019
8ce3eb8
Merge branch 'fix-typo'
wmakley Oct 13, 2019
7c3cee2
fix implicit global variable
wmakley Oct 13, 2019
713d2e6
fix more implicit globals
wmakley Oct 13, 2019
aeca11f
Merge branch 'minor-bug-fixes'
wmakley Oct 13, 2019
d32ffe6
WIP initial webpack implementation
wmakley Oct 13, 2019
50dbbce
fix implicit global variables
wmakley Oct 13, 2019
ab6cb21
avoid variable re-declaration
wmakley Oct 13, 2019
33e2dd2
shift does not take any arguments
wmakley Oct 13, 2019
73b9aef
Merge branch 'minor-bug-fixes'
wmakley Oct 13, 2019
ad971bc
fix more implicit variable re-declaration
wmakley Oct 13, 2019
4b9f3b7
fix typo
wmakley Oct 13, 2019
c4c9114
replace all == with === to avoid accidental type coercion
wmakley Oct 14, 2019
fc5105d
zIndex property is a string, so let's be explicit about the type coer…
wmakley Oct 14, 2019
f10c3ac
Merge branch 'minor-bug-fixes'
wmakley Oct 14, 2019
e6ad42b
Merge branch 'opinionated-bug-fixes'
wmakley Oct 14, 2019
478c4b8
Merge branch 'master' into ES6
wmakley Oct 14, 2019
1a9b05b
completely rework app to use webpack, const/let, and ES6 modules and …
wmakley Oct 14, 2019
7f025f4
set license to MIT (for what it's worth)
wmakley Oct 16, 2019
70cd07e
allow serving index.html via webpack-dev-server
wmakley Oct 20, 2019
32779df
fix image references
wmakley Oct 25, 2019
4219e81
attempt to improve PWA features and add a service worker
wmakley Oct 25, 2019
fab727a
add all images to service worker precached assets
wmakley Oct 26, 2019
bf4f128
add http-server for testing PWA functionality
wmakley Oct 26, 2019
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
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf

[{*.js,*.html}]
end_of_line = crlf

[package.json]
indent_size = 2
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_config.yml
app.manifest
web.config
web.config
.idea
node_modules
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# Gloomy Companion

## About the fork

I want to add the following features:

1. Sort monster decks by initiative.
2. Sort player icons in between the monster decks.

In the process I ended up implementing webpack and ES6 and fixing small bugs.

## Original intro

This is a web-app for managing the monster ability decks in the board game [Gloomhaven](https://boardgamegeek.com/boardgame/174430/gloomhaven)

You can run it from the web directly on <https://johreh.github.io/gloomycompanion/>.

You can also download it and run it locally without internet connection. Click __Clone or download__ above, then __Download ZIP__. Unpack the ZIP and start the app by opening `index.html`.

If you want to add new cards, you need to update [`cards.js`](cards.js). The decks has the following syntax:
If you want to add new cards, you need to update [`cards.js`](src/cards.js). The decks have the following syntax:

```json
```javascript
{ name: "Name of monster"
, cards:
[ [false, "42", "* First line", "** sub-line 1", "** sub-line 2", "* Second line"]
Expand All @@ -19,11 +30,15 @@ If you want to add new cards, you need to update [`cards.js`](cards.js). The dec

The value in the first column is `true` if the deck shall be reshuffled after that card, `false` otherwise. The second colum is card initiative value. The following values is the card text, one row per column.

A single `*` means a top-level action. Double asterisk `**` means it modifies the previous action. Commonly used text snippets can be expanded using macros. E.g. `%move%` expands to the text _Move_ followed by the move icon, `%immobilize%` expands to _IMMOBILIZE_ followed by the immobilization icon. The list of available macros can be seen in [`macros.js`](macros.js).
A single `*` means a top-level action. Double asterisk `**` means it modifies the previous action. Commonly used text snippets can be expanded using macros. E.g. `%move%` expands to the text _Move_ followed by the move icon, `%immobilize%` expands to _IMMOBILIZE_ followed by the immobilization icon. The list of available macros can be seen in [`macros.js`](src/macros.js).

## Development

* Clone the repository
* Run the [`gen-manifest.sh`](gen-manifest.sh) script (Linux and MacOS only; you'll have to make the `app.manifest` by hand if you are running Windows)
* `npm install`
* `npm run dev-server`

## PWA Development and Testing

Any time a source/asset file is added or removed, re-run the above manifest generation script. Or manually make the appropriate change to the manifest instead.
1. `npm run http-server`
2. Browse to http://localhost:8080 and use Chrome developer tools for auditing and debugging.
12 changes: 0 additions & 12 deletions app.webmanifest

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
16 changes: 5 additions & 11 deletions index.html → dist/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html manifest="app.manifest">
<html lang="en">
<head>
<title>Gloomy Companion</title>
<link rel="apple-touch-icon" sizes="192x192" href="images/icon.png" />
<link rel="icon" type="image/png" sizes="192x192" href="images/icon.png" />
<link rel="manifest" href="app.webmanifest" />
<link rel="manifest" href="manifest.json" />
<link rel="stylesheet" href="cards.css" />
<link rel="stylesheet" href="style.css" />
<meta charset="UTF-8">
Expand All @@ -13,16 +13,10 @@
<meta name="apple-mobile-web-app-title" content="Gloomy Companion" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript" src="cards.js"></script>
<script type="text/javascript" src="scenarios.js"></script>
<script type="text/javascript" src="macros.js"></script>
<script type="text/javascript" src="modifiers.js"></script>
<script type="text/javascript" src="monster_stats.js"></script>
<script type="text/javascript" src="logic.js"></script>
<script type="text/javascript" src="ui.js"></script>
<meta name="theme-color" content="#731819" />
<script type="text/javascript" src="main.js"></script>
</head>
<body onload="init(); init_ui();">
<body>
<div class="panecontainer">
<div id="settingspane" class="pane expanded">
<ul class="tabcontainer">
Expand Down
1 change: 1 addition & 0 deletions dist/main.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions dist/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"short_name": "Gloomy Companion",
"name": "Gloomy Companion",
"start_url": "index.html",
"scope": ".",
"display": "standalone",
"icons": [
{
"src": "/images/icon.png",
"sizes": "192x192",
"type": "image/png"
}
],
"background_color": "#000",
"theme_color": "#731819",
"service_worker": {
"src": "/service-worker.js"
}
}
146 changes: 146 additions & 0 deletions dist/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// https://googlechrome.github.io/samples/service-worker/basic/

/*
Copyright 2016 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Names of the two caches used in this version of the service worker.
// Change to v2, etc. when you update any of the local resources, which will
// in turn trigger the install event again.
const PRECACHE = 'precache-v1';
const RUNTIME = 'runtime';

// A list of local resources we always want to be cached.
const PRECACHE_URLS = [
'index.html',
'./', // Alias for index.html
'cards.css',
'style.css',
'main.js',
'Philosopher-Bold.ttf',
'PirataOne-Gloomhaven.ttf',
'images/add_target.svg',
'images/air.svg',
'images/any_element.svg',
'images/aoe-4-with-black.svg',
'images/aoe-circle-with-middle-black.svg',
'images/aoe-circle-with-side-black.svg',
'images/aoe-circle.svg',
'images/aoe-line-3-with-black.svg',
'images/aoe-line-4-with-black.svg',
'images/aoe-line-6-with-black.svg',
'images/aoe-triangle-2-side-with-black.svg',
'images/aoe-triangle-2-side.svg',
'images/aoe-triangle-3-side-with-corner-black.svg',
'images/aoe1.svg',
'images/aoe2.svg',
'images/attack.svg',
'images/attack_mod_+0.jpg',
'images/attack_mod_+1.jpg',
'images/attack_mod_+2.jpg',
'images/attack_mod_-1.jpg',
'images/attack_mod_-2.jpg',
'images/attack_mod_2x.jpg',
'images/attack_mod_back.jpg',
'images/attack_mod_bless.jpg',
'images/attack_mod_curse.jpg',
'images/attack_mod_null.jpg',
'images/back.jpg',
'images/back.svg',
'images/bless.svg',
'images/curse.svg',
'images/dark.svg',
'images/disarm.svg',
'images/draw-two.svg',
'images/earth.svg',
'images/elderDrake.special1Area.svg',
'images/fire.svg',
'images/fly.svg',
'images/front.jpg',
'images/heal.svg',
'images/ice.svg',
'images/icon.png',
'images/immobilize.svg',
'images/inoxBodyguard.special1Area.svg',
'images/invisibility.svg',
'images/jump.svg',
'images/light.svg',
'images/loot.svg',
'images/minus-circle.svg',
'images/move.svg',
'images/muddle.svg',
'images/pierce.svg',
'images/plus-circle.svg',
'images/poison.svg',
'images/push.svg',
'images/range.svg',
'images/retaliate.svg',
'images/settings.svg',
'images/shield.svg',
'images/shuffle-black.svg',
'images/shuffle.svg',
'images/sightlessEye.special1Area.svg',
'images/sightlessEye.special2Area.svg',
'images/strengthen.svg',
'images/stun.svg',
'images/target.svg',
'images/use_element.svg',
'images/wound.svg'
];

// The install handler takes care of precaching the resources we always need.
self.addEventListener('install', event => {
event.waitUntil(
caches.open(PRECACHE)
.then(cache => cache.addAll(PRECACHE_URLS))
.then(self.skipWaiting())
);
});

// The activate handler takes care of cleaning up old caches.
self.addEventListener('activate', event => {
const currentCaches = [PRECACHE, RUNTIME];
event.waitUntil(
caches.keys().then(cacheNames => {
return cacheNames.filter(cacheName => !currentCaches.includes(cacheName));
}).then(cachesToDelete => {
return Promise.all(cachesToDelete.map(cacheToDelete => {
return caches.delete(cacheToDelete);
}));
}).then(() => self.clients.claim())
);
});

// The fetch handler serves responses for same-origin resources from a cache.
// If no response is found, it populates the runtime cache with the response
// from the network before returning it to the page.
self.addEventListener('fetch', event => {
// Skip cross-origin requests, like those for Google Analytics.
if (event.request.url.startsWith(self.location.origin)) {
event.respondWith(
caches.match(event.request).then(cachedResponse => {
if (cachedResponse) {
return cachedResponse;
}

return caches.open(RUNTIME).then(cache => {
return fetch(event.request).then(response => {
// Put a copy of the response in the runtime cache.
return cache.put(event.request, response.clone()).then(() => {
return response;
});
});
});
})
);
}
});
File renamed without changes.
16 changes: 0 additions & 16 deletions gen-manifest.sh

This file was deleted.

Loading