From ca594a713c109f0677979ea049e23b6bc0460ae6 Mon Sep 17 00:00:00 2001 From: Achyut Reddy Date: Thu, 4 Dec 2014 21:32:18 -0500 Subject: [PATCH] Add persistent data functionality for high score --- appinfo.json | 52 ++++++++++--------- resources/{ => images}/helicopter.png | Bin resources/{ => images}/helicopter_tilt.png | Bin src/helicopter.c | 7 +++ wscript | 57 +++++++++++++++++++++ 5 files changed, 92 insertions(+), 24 deletions(-) rename resources/{ => images}/helicopter.png (100%) rename resources/{ => images}/helicopter_tilt.png (100%) create mode 100644 wscript diff --git a/appinfo.json b/appinfo.json index 644a1ad..56edb57 100644 --- a/appinfo.json +++ b/appinfo.json @@ -1,28 +1,32 @@ { - "uuid": "d0c1bba9-48cc-4edc-8a58-54eeed7575f5", - "shortName": "Helibble", - "longName": "Helibble", - "companyName": "MakeAwesomeHappen", - "versionCode": 1, - "versionLabel": "1.0.0", - "watchapp": { - "watchface": false - }, - "appKeys": { - "dummy": 0 - }, - "resources": { - "media": [ - { - "type": "png", - "name": "IMAGE_HELI", - "file": "helicopter.png" + "appKeys": { + "dummy": 0 }, - { - "type": "png", - "name": "IMAGE_HELI_TILT", - "file": "helicopter_tilt.png" + "capabilities": [ + "" + ], + "companyName": "MakeAwesomeHappen", + "longName": "Helibble", + "projectType": "native", + "resources": { + "media": [ + { + "file": "images/helicopter_tilt.png", + "name": "IMAGE_HELI_TILT", + "type": "png" + }, + { + "file": "images/helicopter.png", + "name": "IMAGE_HELI", + "type": "png" + } + ] + }, + "shortName": "Helibble", + "uuid": "d0c1bba9-48cc-4edc-8a58-54eeed7575f5", + "versionCode": 1, + "versionLabel": "1.1", + "watchapp": { + "watchface": false } - ] - } } diff --git a/resources/helicopter.png b/resources/images/helicopter.png similarity index 100% rename from resources/helicopter.png rename to resources/images/helicopter.png diff --git a/resources/helicopter_tilt.png b/resources/images/helicopter_tilt.png similarity index 100% rename from resources/helicopter_tilt.png rename to resources/images/helicopter_tilt.png diff --git a/src/helicopter.c b/src/helicopter.c index f347d4b..ca5b2a1 100644 --- a/src/helicopter.c +++ b/src/helicopter.c @@ -22,6 +22,8 @@ char best_score_str[20]; #define REFRESH_RATE 50 #define MIN_HEIGHT 70 + +#define PERSIST_SCORE 0 int c = 1; @@ -244,10 +246,15 @@ static void init(void) { window_set_fullscreen(window, true); window_stack_push(window, animated); light_enable(true); + if (persist_exists(PERSIST_SCORE)) { + // Load stored count + best_score = persist_read_int(PERSIST_SCORE); + } } static void deinit(void) { window_destroy(window); + persist_write_int(PERSIST_SCORE, best_score); } int main(void) { diff --git a/wscript b/wscript new file mode 100644 index 0000000..fbc4753 --- /dev/null +++ b/wscript @@ -0,0 +1,57 @@ + +# +# This file is the default set of rules to compile a Pebble project. +# +# Feel free to customize this to your needs. +# + +import os.path +try: + from sh import CommandNotFound, jshint, cat, ErrorReturnCode_2 + hint = jshint +except (ImportError, CommandNotFound): + hint = None + +top = '.' +out = 'build' + +def options(ctx): + ctx.load('pebble_sdk') + +def configure(ctx): + ctx.load('pebble_sdk') + global hint + if hint is not None: + hint = hint.bake(['--config', 'pebble-jshintrc']) + +def build(ctx): + if False and hint is not None: + try: + hint([node.abspath() for node in ctx.path.ant_glob("src/**/*.js")], _tty_out=False) # no tty because there are none in the cloudpebble sandbox. + except ErrorReturnCode_2 as e: + ctx.fatal("\nJavaScript linting failed (you can disable this in Project Settings):\n" + e.stdout) + + # Concatenate all our JS files (but not recursively), and only if any JS exists in the first place. + ctx.path.make_node('src/js/').mkdir() + js_paths = ctx.path.ant_glob(['src/*.js', 'src/**/*.js']) + if js_paths: + ctx(rule='cat ${SRC} > ${TGT}', source=js_paths, target='pebble-js-app.js') + has_js = True + else: + has_js = False + + ctx.load('pebble_sdk') + + ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), + target='pebble-app.elf') + + if os.path.exists('worker_src'): + ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), + target='pebble-worker.elf') + ctx.pbl_bundle(elf='pebble-app.elf', + worker_elf='pebble-worker.elf', + js='pebble-js-app.js' if has_js else []) + else: + ctx.pbl_bundle(elf='pebble-app.elf', + js='pebble-js-app.js' if has_js else []) +