xtruan 2 лет назад
Родитель
Сommit
229c7bd3a0
4 измененных файлов с 61 добавлено и 93 удалено
  1. 1 1
      .github/workflows/build.yml
  2. 3 3
      .github/workflows/release.yml
  3. 13 69
      README.md
  4. 44 20
      views/flipchess_scene_1.c

+ 1 - 1
.github/workflows/build.yml

@@ -23,7 +23,7 @@ jobs:
       - name: Checkout flip-chess
         uses: actions/checkout@v3
         with:
-          path: 'applications_user/flip-chess'
+          path: 'applications_user/flipper-chess'
       - name: Build FAPs
         run: ./fbt COMPACT=1 DEBUG=0 faps
       - name: Check flip-chess Built

+ 3 - 3
.github/workflows/release.yml

@@ -22,11 +22,11 @@ jobs:
       - name: Checkout flip-chess
         uses: actions/checkout@v3
         with:
-          path: 'applications_user/flip-chess'
+          path: 'applications_user/flipper-chess'
       - name: Build FAPs
         run: ./fbt COMPACT=1 DEBUG=0 faps
       - name: Check flip-chess Built
-        run: test -f build/f7-firmware-C/.extapps/flip-chess.fap
+        run: test -f build/f7-firmware-C/.extapps/flipchess.fap
       - name: Get Tag
         id: tag
         uses: dawidd6/action-get-tag@v1
@@ -36,7 +36,7 @@ jobs:
         uses: softprops/action-gh-release@v1
         with:
           files: |
-            build/f7-firmware-C/.extapps/flip-chess.fap
+            build/f7-firmware-C/.extapps/flipchess.fap
             applications_user/flip-chess/README.md
           name: ${{steps.tag.outputs.tag}}
           body: Built against Flipper Zero firmware v${{ env.firmware_version }}

+ 13 - 69
README.md

@@ -1,77 +1,21 @@
-# flip-chess - BIP32/39/44
+# flipper-chess
 
-[![Build](https://github.com/xtruan/flip-chess/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/xtruan/flip-chess/actions/workflows/build.yml)
+Flipper Zero Chess game.
 
-## Crypto toolkit for Flipper Zero
-- Last built against `0.86.1` Flipper Zero firmware release
-- Using Trezor crypto libs from `core/v2.5.3` release
-- Included in [RogueMaster Custom Firmware](https://github.com/RogueMaster/flipperzero-firmware-wPlugins)
+### Installation
 
-### DONATE IF YOU FIND THE APP USEFUL
-  - ETH (or ERC-20): `xtruan.eth` or `0xa9Ad79502cdaf4F6881f3C2ef260713e5B771CE2`
-  - BTC: `16RP5Ui5QrWrVh2rR7NKAPwE5A4uFjCfbs`
+- Download [last release fap file](https://github.com/xtruan/flipper-chess/releases/latest)
+- Copy fap file to the apps folder of your Flipper SD card
 
-## Background
+### Usage
 
-The goal of this project is to see how much crypto functionality can be brought to the Flipper Zero.
+- Start "Chess" plugin
 
-## How to install on Flipper Zero
-- If you do not have one, download a Flipper Zero firmware to get the `fbt` build tool
-- Plug your Flipper Zero in via USB
-- Copy the contents of this folder into the `applications_user` folder of your firmware
-- Modify the `site_scons/cc.scons` file in the Flipper Zero firmware to add the `"-Os"` flag
+### Build
 
-Then run the command: 
- ```
-./fbt COMPACT=1 DEBUG=0 launch_app APPSRC=applications_user/flip-chess
- ```
-The application will be compiled and copied onto your device
+- Recursively clone your base firmware (official or not)
+- Clone this repository in `applications_user`
+- Build with `./fbt fap_dist APPSRC=applications_user/flipper-chess`
+- Retrieve build fap in dist subfolders
 
-## Status
-
-### Complete
-
-- Trezor crypto C code ported into `crypto` subfolder
-  - Adapted to use Flipper hardware RNG (see `crypto/rand.c`)
-  - Imports and some C library functions modified for compatibility with FBT
-- Navigation and UI adapted from FAP Boilerplate app
-- BIP39 mnemonic generation
-  - 24, 18, or 12 words configured in settings
-- BIP39 mnemonic to BIP39 seed generation
-- Hierarchical Deterministic (HD) wallet generation from seed
-  - Generation of offline `m/44'/0'/0'/0` BTC wallet
-  - Generation of offline `m/44'/60'/0'/0` ETH wallet (coded from the $SPORK Castle of ETHDenver 2023!)
-  - Generation of offline `m/44'/3'/0'/0` DOGE wallet
-  - Similar features to: https://iancoleman.io/bip39/
-- Saving wallets to SD card
-  - Wallets are saved to SD card upon creation in `apps_data/flipchess`
-      - NOTE: `apps_data` folder must already exist on SD card!
-  - Saved wallets can be viewed between app runs
-  - Wallets are encrypted with a randomly generated key, and that key is also encrypted
-      - `.flipchess.dat` and `.flipchess.key` files are both required to be in `apps_data/flipchess`
-      - Backups of both these files `.flipchess.dat.bak` and `.flipchess.key.bak` are also maintained
-      - If you want to externally back up your wallet, I recommend copying all these files, and storing the `key` and `dat` files seperately
-  - NOTE: The wallets should be decently tough to crack off of a Flipper, however any Flipper with the app installed can load a wallet in the `apps_data/flipchess` directory if both the `key` and `dat` file are present. Therefore, it is HIGHLY RECOMMENDED to use the BIP39 passphrase functionality and store the passphrase in your brain or on paper separately from the Flipper!
-- BIP39 passphrase support
-  - Configured in settings, not persisted between runs for security
-- Import your own mnemonic
-  - Lots of typing required but you can now use the wallet with an existing mnemonic you have saved
-  - Useful to convert paper backup to keys and receive addresses without relying on a laptop or phone
-- Improved receive address generation features
-  - Addresses are now generated at the same time as other pieces of wallet info
-    - This slows down initial wallet load, but makes UI much more responsive
-  - QR code files are now generated for each address and stored in the `apps_data/flipchess` directory
-    - This app is required to view the QR code files: https://github.com/bmatcuk/flipperzero-qrcode (included in RM firmware)
-    - NOTE: This happens during the `View Wallet` step; you must view a wallet after generating/importing a wallet in order to ensure the address QR files are correct
-- Broke out crypto functionality into its own library using `fap_private_libs` feature
-
-### Work in Progress
-
-- More coin types
-  - Support for more custom BIP32 wallet paths
-
-### (FAR) Future
-
-- Custom wallet security
-  - User specified password
-- USB/Bluetooth wallet functionality
+(More info about build tool [here](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/fbt.md))

+ 44 - 20
views/flipchess_scene_1.c

@@ -49,7 +49,8 @@ typedef struct {
     int16_t random960PosNumber;
 
     //uint8_t picture[SCL_BOARD_PICTURE_WIDTH * SCL_BOARD_PICTURE_WIDTH];
-    uint8_t selected;
+    uint8_t squareSelected;
+    uint8_t squareSelectedLast;
     char* msg;
 
     SCL_SquareSet squareSet;
@@ -135,7 +136,7 @@ void flipchess_drawBoard(FlipChessScene1Model* model) {
     SCL_drawBoard(
         model->game.board,
         flipchess_putImagePixel,
-        model->selected,
+        model->squareSelected,
         model->moveHighlight,
         model->paramFlipBoard);
 }
@@ -208,7 +209,7 @@ uint8_t flipchess_turn(FlipChessScene1Model* model) {
     // }
 
     if(model->game.state != SCL_GAME_STATE_PLAYING || model->paramExit)
-        return 4;
+        return FlipChessStatusReturn;
 
     //uint8_t squareFrom = 0;
     //uint8_t squareTo = 0;
@@ -225,19 +226,20 @@ uint8_t flipchess_turn(FlipChessScene1Model* model) {
         // else if(stringsEqual(string, "quit", 5))
         //     break;
         // else {
-        //squareFrom = selected; //SCL_stringToSquare(string);
-        //squareTo = selected; //SCL_stringToSquare(string + 2);
+        //squareFrom = squareSelected; //SCL_stringToSquare(string);
+        //squareTo = squareSelected; //SCL_stringToSquare(string + 2);
 
         //uint8_t r =
         //    SCL_stringToMove(string, &squareFrom, &squareTo, &movePromote);
 
-        if (model->turnState == 0 && model->selected != 255) {
-            model->squareFrom = model->selected;
+        if (model->turnState == 0 && model->squareSelected != 255) {
+            model->squareFrom = model->squareSelected;
             model->turnState = 1;
-        } else if (model->turnState == 1 && model->selected != 255) {
-            model->squareTo = model->selected;
+        } else if (model->turnState == 1 && model->squareSelected != 255) {
+            model->squareTo = model->squareSelected;
             model->turnState = 2;
-            model->selected = 255;
+            model->squareSelectedLast = model->squareSelected;
+            model->squareSelected = 255;
         }
 
         if(model->turnState == 1 && model->squareFrom != 255) {
@@ -380,8 +382,9 @@ static int flipchess_scene_1_model_init(
     memcpy(model->startState, &emptyStartState, sizeof(SCL_Board));
     model->random960PosNumber = -1;
 
-    model->selected = 255;
-    model->msg = "Flip Chess";
+    model->squareSelected = 255;
+    model->squareSelectedLast = 255;
+    model->msg = "init";
 
     SCL_SquareSet emptySquareSet = SCL_SQUARE_SET_EMPTY;
     memcpy(model->moveHighlight, &emptySquareSet, sizeof(SCL_SquareSet));
@@ -457,6 +460,8 @@ static int flipchess_scene_1_model_init(
         return FlipChessStatusReturn;
     }
 
+    model->msg = (SCL_boardWhitesTurn(model->game.board) ? "white to move" : "black to move");
+
     // 0 = success
     return FlipChessStatusSuccess;
 }
@@ -482,7 +487,11 @@ bool flipchess_scene_1_input(InputEvent* event, void* context) {
                 instance->view,
                 FlipChessScene1Model * model,
                 {
-                    model->selected = (model->selected + 1) % 64;
+                    if (model->squareSelectedLast != 255 && model->squareSelected == 255) {
+                        model->squareSelected = model->squareSelectedLast;
+                    } else {
+                        model->squareSelected = (model->squareSelected + 1) % 64;
+                    }
                     flipchess_drawBoard(model);
                 },
                 true);
@@ -492,7 +501,11 @@ bool flipchess_scene_1_input(InputEvent* event, void* context) {
                 instance->view,
                 FlipChessScene1Model * model,
                 {
-                    model->selected = (model->selected + 56) % 64;
+                    if (model->squareSelectedLast != 255 && model->squareSelected == 255) {
+                        model->squareSelected = model->squareSelectedLast;
+                    } else {
+                        model->squareSelected = (model->squareSelected + 56) % 64;
+                    }
                     flipchess_drawBoard(model);
                 },
                 true);
@@ -502,7 +515,11 @@ bool flipchess_scene_1_input(InputEvent* event, void* context) {
                 instance->view,
                 FlipChessScene1Model * model,
                 {
-                    model->selected = (model->selected + 63) % 64;
+                    if (model->squareSelectedLast != 255 && model->squareSelected == 255) {
+                        model->squareSelected = model->squareSelectedLast;
+                    } else {
+                        model->squareSelected = (model->squareSelected + 63) % 64;
+                    }
                     flipchess_drawBoard(model);
                 },
                 true);
@@ -511,8 +528,11 @@ bool flipchess_scene_1_input(InputEvent* event, void* context) {
             with_view_model(
                 instance->view,
                 FlipChessScene1Model * model,
-                {
-                    model->selected = (model->selected + 8) % 64;
+                {if (model->squareSelectedLast != 255 && model->squareSelected == 255) {
+                        model->squareSelected = model->squareSelectedLast;
+                    } else {
+                        model->squareSelected = (model->squareSelected + 8) % 64;
+                    }
                     flipchess_drawBoard(model);
                 },
                 true);
@@ -521,8 +541,12 @@ bool flipchess_scene_1_input(InputEvent* event, void* context) {
             with_view_model(
                 instance->view, FlipChessScene1Model * model, 
                 { 
-                    flipchess_turn(model);
-                    flipchess_drawBoard(model);
+                    uint8_t status = flipchess_turn(model);
+                    if(status == FlipChessStatusReturn) {
+                        instance->callback(FlipChessCustomEventScene1Back, instance->context);
+                    } else {
+                        flipchess_drawBoard(model);
+                    }
                 }, 
                 true);
             break;
@@ -538,7 +562,7 @@ void flipchess_scene_1_exit(void* context) {
     FlipChessScene1* instance = (FlipChessScene1*)context;
 
     with_view_model(
-        instance->view, FlipChessScene1Model * model, { model->selected = 255; }, true);
+        instance->view, FlipChessScene1Model * model, { model->squareSelected = 255; }, true);
 }
 
 void flipchess_scene_1_enter(void* context) {