From ebf8e01dd514b55d915a46222a380f0b49f45d20 Mon Sep 17 00:00:00 2001 From: Paul Cockrell Date: Mon, 6 Apr 2020 16:11:05 +0100 Subject: [PATCH 01/11] Tidy up code --- apps/marioclock/marioclock-app.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/apps/marioclock/marioclock-app.js b/apps/marioclock/marioclock-app.js index 51f7b916b..dabe7ad9e 100644 --- a/apps/marioclock/marioclock-app.js +++ b/apps/marioclock/marioclock-app.js @@ -1,6 +1,6 @@ /** * BangleJS MARIO CLOCK - * + * * + Original Author: Paul Cockrell https://github.com/paulcockrell * + Created: April 2020 * + Based on Espruino Mario Clock V3 https://github.com/paulcockrell/espruino-mario-clock @@ -90,20 +90,13 @@ function incrementTimer() { function drawBackground() { // Clear screen - if (nightMode) { - g.setColor(NIGHT); - } else { - g.setColor(LIGHTEST); - } + const bgColor = (nightMode) ? NIGHT : LIGHTEST; + g.setColor(bgColor); g.fillRect(0, 10, W, H); - // set cloud colors - if (nightMode) { - g.setColor(DARKEST); - } else { - g.setColor(LIGHT); - } - // draw clouds + // set cloud colors and draw clouds + const cloudColor = (nightMode) ? DARK : LIGHT; + g.setColor(cloudColor); g.fillRect(0, 10, g.getWidth(), 15); g.fillRect(0, 17, g.getWidth(), 17); g.fillRect(0, 19, g.getWidth(), 19); @@ -124,14 +117,15 @@ function drawFloor() { function drawPyramid() { const pPol = [pyramidSprite.x + 10, H - 6, pyramidSprite.x + 50, pyramidSprite.height, pyramidSprite.x + 90, H - 6]; // Pyramid poly - g.setColor(LIGHT); + const color = (nightMode) ? DARK : LIGHT; + g.setColor(color); g.fillPoly(pPol); pyramidSprite.x -= 1; // Reset and randomize pyramid if off-screen if (pyramidSprite.x < - 100) { pyramidSprite.x = 90; - pyramidSprite.height = Math.floor(Math.random() * (60 /* max */ - 25 /* min */ + 1) + 25 /* min */); + pyramidSprite.height = genRanNum(25, 60); } } @@ -146,7 +140,7 @@ function drawTreesFrame(x, y) { function generateTreeSprite() { return { x: 90, - y: Math.floor(Math.random() * (60 /* max */ - 30 /* min */ + 1) + 30 /* min */) + y: genRanNum(30, 60) }; } @@ -257,10 +251,10 @@ function drawCharacter(date, character) { } switch(characterSprite.character) { - case("toad"): + case(TOAD): drawToadFrame(characterSprite.frameIdx, characterSprite.x, characterSprite.y); break; - case("mario"): + case(MARIO): default: drawMarioFrame(characterSprite.frameIdx, characterSprite.x, characterSprite.y); } From 44fff4a8555069dcfae77e50cb58221683faf6bf Mon Sep 17 00:00:00 2001 From: Paul Cockrell Date: Mon, 6 Apr 2020 16:36:18 +0100 Subject: [PATCH 02/11] Add README to Mario Clock. Add README viewer to App installer --- apps/marioclock/README.md | 17 +++++++++++++++++ index.html | 1 + js/index.js | 9 +++++++++ 3 files changed, 27 insertions(+) create mode 100644 apps/marioclock/README.md diff --git a/apps/marioclock/README.md b/apps/marioclock/README.md new file mode 100644 index 000000000..7078f52b4 --- /dev/null +++ b/apps/marioclock/README.md @@ -0,0 +1,17 @@ +# Mario Clock +Let's go back in time with this Gameboy inspired Mario retro clock. + +Enjoy watching Mario, or one of the other game characters run through a level while showing you the time and date. + +## Features + +* Multiple characters - swipe the screen right to change the character +* Night and Day modes - swipe left to toggle mode +* Smooth animation +* Awesome 8-bit style grey-scale graphics +* Mario jumps to change the time, every minute +* You can make Mario jump by pressing the top button (Button 1) on the watch + +## Requests + +If you have any feature requests, please open an issue at the authors [https://github.com/paulcockrell](Github page) diff --git a/index.html b/index.html index 6e1a9b554..0c528c5a7 100644 --- a/index.html +++ b/index.html @@ -133,5 +133,6 @@ + diff --git a/js/index.js b/js/index.js index 60b66436a..674c6e284 100644 --- a/js/index.js +++ b/js/index.js @@ -23,6 +23,13 @@ function showChangeLog(appid) { httpGet(`apps/${appid}/ChangeLog`). then(show).catch(()=>show("No Change Log available")); } +function showReadme(appid) { + var app = appNameToApp(appid); + function show(contents) { + showPrompt(app.name + " README", marked(contents), {ok: true}).catch(() => {}); + } + httpGet(`apps/${appid}/README.md`).then(show).catch(()=>show("No README available")); +} function handleCustomApp(appTemplate) { // Pops up an IFRAME that allows an app to be customised if (!appTemplate.custom) throw new Error("App doesn't have custom HTML"); @@ -175,12 +182,14 @@ function refreshLibrary() { var version = getVersionInfo(app, appInstalled); var versionInfo = version.text; if (versionInfo) versionInfo = " ("+versionInfo+")"; + var readme = `Read me`; return `
${escapeHtml(app.name)}

${escapeHtml(app.name)} ${versionInfo}

+

${readme}

${escapeHtml(app.description)}

See the code on GitHub
From 65078cffef117ebcabcea382017572c34f38379e Mon Sep 17 00:00:00 2001 From: Paul Cockrell Date: Mon, 6 Apr 2020 16:49:42 +0100 Subject: [PATCH 03/11] Add argument to not escape html (in case of markdown->html for README --- js/index.js | 3 ++- js/ui.js | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/js/index.js b/js/index.js index 674c6e284..d2da0338f 100644 --- a/js/index.js +++ b/js/index.js @@ -26,7 +26,8 @@ function showChangeLog(appid) { function showReadme(appid) { var app = appNameToApp(appid); function show(contents) { - showPrompt(app.name + " README", marked(contents), {ok: true}).catch(() => {}); + if (!contents) return; + showPrompt(app.name + " README", marked(contents), {ok: true}, false).catch(() => {}); } httpGet(`apps/${appid}/README.md`).then(show).catch(()=>show("No README available")); } diff --git a/js/ui.js b/js/ui.js index c88091872..8048bbf93 100644 --- a/js/ui.js +++ b/js/ui.js @@ -97,8 +97,10 @@ function showToast(message, type) { } /// Show a yes/no prompt -function showPrompt(title, text, buttons) { +function showPrompt(title, text, buttons, shouldEscapeHtml) { if (!buttons) buttons={yes:1,no:1}; + if (!shouldEscapeHtml) shouldEscapeHtml = true; + return new Promise((resolve,reject) => { var modal = htmlElement(`