Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
application cache support.
Browse files Browse the repository at this point in the history
Manticore should now behave like an offline application when installed
on a users iOS (or other appcache supprting) device.

the manifest file is automatically generated by the makefile now too,
so it should correctly update when the project is built
  • Loading branch information
brehaut committed Sep 1, 2014
1 parent fb71c64 commit dc251d5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ out/*
/static/js/main.js.map
/static/data/custom.json
/manticore-release.zip
/manifest.appcache
69 changes: 51 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,61 @@
build_stock: build
rm target/static/data/custom.json
SRC_ROOT = src
STATIC_ROOT = static
TARGET_ROOT = target

build: clean bundle_contrib_js
mkdir -p target/static/{css,js,data,images}
cp static/data/* target/static/data/
cp static/css/* target/static/css/
cp static/js/* target/static/js/
cp static/images/* target/static/images/
cp index.html target/
tsc src/ts/manticore.ts --removeComments --out target/static/js/main.js

release: build_stock
echo '{"campaign": [\n ["Example monster", 1, "normal", "troop", ["test", "tags"]]\n]}\n' > target/static/data/custom.json
zip manticore-release.zip -r target
SCRIPTS = $(STATIC_ROOT)/js
STYLES = $(STATIC_ROOT)/css
IMAGES = $(STATIC_ROOT)/images
DATA = $(STATIC_ROOT)/data

MANIFEST = manifest.appcache

TS_APP_SRC = $(SRC_ROOT)/ts/manticore.ts
TS_APP_OUT = $(SCRIPTS)/main.js

default: build_stock

clean:
rm -rf target
rm -rf $(TARGET_ROOT)
rm static/js/*

bundle_contrib_js:
cat src/js/contrib/* > static/js/contrib.js
cat src/js/contrib/* > $(SCRIPTS)/contrib.js

manifest:
echo "CACHE MANIFEST\n\n# Generated:" > $(MANIFEST)
date -u +#\ %Y%m%d:%H%M%S >> $(MANIFEST)
echo >> $(MANIFEST)$

cat $(SRC_ROOT)/manifest-static >> $(MANIFEST);
for file in $(SCRIPTS)/*; do echo $$file >> $(MANIFEST); done
echo $(TS_APP_OUT) >> $(MANIFEST)
for file in $(STYLES)/*; do echo $$file >> $(MANIFEST); done
for file in $(DATA)/*; do echo $$file >> $(MANIFEST); done
for file in $(IMAGES)/*; do echo $$file >> $(MANIFEST); done


build_ts:
tsc $(SRC_ROOT)/ts/manticore.ts --removeComments --out $(TARGET_ROOT)/$(STATIC_ROOT)/js/main.js


bundle_all: clean bundle_contrib_js build_ts manifest
mkdir -p $(TARGET_ROOT)/$(STATIC_ROOT)/{css,js,data,images}
cp $(DATA)/* $(TARGET_ROOT)/$(DATA)/
cp $(STYLES)/* $(TARGET_ROOT)/$(STYLES)/
cp $(SCRIPTS)/* $(TARGET_ROOT)/$(SCRIPTS)/
cp $(IMAGES)/* $(TARGET_ROOT)/$(IMAGES)/
cp $(MANIFEST) $(TARGET_ROOT)/
cp index.html $(TARGET_ROOT)/

build_stock: bundle_all manifest
rm target/static/data/custom.json

release: clean build_stock manifest
echo '{"campaign": [\n ["Example monster", 1, "normal", "troop", ["test", "tags"]]\n]}\n' > $(TARGET_ROOT)/$(DATA)/custom.json
zip manticore-release.zip -r target

watch: bundle_contrib_js
tsc -w src/ts/manticore.ts --sourcemap --out static/js/main.js
watch: bundle_contrib_js manifest
tsc -w $(TS_APP_SRC) --sourcemap --out static/js/main.js

server:
python -m SimpleHTTPServer
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html manifest="manifest.appcache">
<head>
<meta charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=Alegreya:400italic,700italic,400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
Expand Down
1 change: 1 addition & 0 deletions src/manifest-static
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://fonts.googleapis.com/css?family=Alegreya:400italic,700italic,400,700&subset=latin,latin-ext
2 changes: 1 addition & 1 deletion src/ts/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ module manticore.interface {


// show a loading bezel while the json data is loading.
function loadingUI(root, promise) {
function loadingUI(root, promise) {
var loading = DOM.div({"class": "loading"}, [DOM.text(_("Loading..."))])
root.appendChild(loading);

Expand Down
10 changes: 10 additions & 0 deletions src/ts/manticore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ module manticore {
bestiary.allocationsForParty
);
});

// appcache management
function updateReady (e?) {
applicationCache.swapCache();
}

applicationCache.addEventListener("updateready", updateReady);
if(window.applicationCache.status === window.applicationCache.UPDATEREADY) {
updateReady();
}
}
2 changes: 1 addition & 1 deletion static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ body > section {
}

body > footer {
background: rgba(40, 15, 7, 1);;
background: rgba(40, 15, 7, 1);
color: #F2F2EB;
font-size: 0.9em;
margin-top: 3em;
Expand Down

0 comments on commit dc251d5

Please sign in to comment.