From 77ca544884356c0b3897482ef99aa48e0cafe269 Mon Sep 17 00:00:00 2001
From: Tt <505623963@qq.com>
Date: Sat, 4 Nov 2023 11:04:29 +0800
Subject: [PATCH] =?UTF-8?q?02=E6=95=B0=E6=8D=AE=E4=B8=8A=E4=BC=A0=E6=B7=BB?=
 =?UTF-8?q?=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 assets/sn02_danci/scene/sn02_danci.ts | 63 ++++++++++++++++++---------
 1 file changed, 43 insertions(+), 20 deletions(-)

diff --git a/assets/sn02_danci/scene/sn02_danci.ts b/assets/sn02_danci/scene/sn02_danci.ts
index 8cda23a..ed2a0db 100644
--- a/assets/sn02_danci/scene/sn02_danci.ts
+++ b/assets/sn02_danci/scene/sn02_danci.ts
@@ -109,6 +109,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
                     .sort(() => Math.random() - 0.5)
             }
         })
+        this.setTotalCount(this.wordDataList.length)
         console.log(data);
     }
 
@@ -130,40 +131,62 @@ export default class SceneComponent extends MyCocosSceneComponent {
         this.resetView();
         this.showWord();
     }
-    sendData(score) {
+
+
+    private rightCount: number;
+    private errorCount: number;
+    private totalCount: number;
+
+    addRightCount() {
+        if (!this.rightCount) this.rightCount = 0;
+        this.rightCount++;
+    }
+    addErrorCount() {
+        if (!this.errorCount) this.errorCount = 0;
+        this.errorCount++;
+    }
+    setTotalCount(val) {
+        this.totalCount = val;
+    }
+    sendData() {
         return new Promise(res => {
+            if (!this.totalCount) this.totalCount = this.rightCount + this.errorCount;
+            if (!this.totalCount) console.error('未设置总计数');
+            if (this.totalCount && !this.rightCount && !this.errorCount) {
+                this.rightCount = this.totalCount;
+                this.errorCount = 0;
+            }
             let upData: any = {
-                word_count: this.data.word_count || 0,
-                sentence_count: this.data.sentence_count || 0,
-                zi_count: this.data.zi_count || 0,
-                score: score,
+                right_count: this.rightCount || 0,
+                wrong_count: this.errorCount || 0,
+                total_count: this.totalCount || 0,
             };
+            upData.score = upData.right_count || 0;
             let recordList = pg.hw.getRecord();
             if (recordList && recordList.length > 0) {
-                upData.recordList = recordList
+                upData.result = recordList
             }
-            const middleLayer = cc.find('middleLayer').getComponent('middleLayer');
             console.log('upload->' + JSON.stringify(upData))
+            if (!cc.find('middleLayer')) return;
+            const middleLayer = cc.find('middleLayer').getComponent('middleLayer');
             middleLayer.onHomeworkFinish(upData, () => {
                 res('');
             })
         })
     }
+
     gameOver() {
-        this.sendData(this.wordDataList.length * 3).then(() => {
-        })
-        this.scheduleOnce(() => {
-            this.onDestroy();
+        this.sendData().then(() => {
+            if (!cc.find('middleLayer')) return;
             const middleLayer = cc.find('middleLayer');
-            if (!middleLayer) return;
-            const middleLayerComponent = middleLayer.getComponent('middleLayer');
-            middleLayerComponent.saveGolds(this.wordDataList.length * 3); // 保存金币数量;num 是获得金币的数量,数字类型;
-            middleLayerComponent.goNextPage();  // 跳转到下一页
-        }, 0.5)
-        // pg.event.once('layer_ending_touch_replay', () => {
-        //     this.replay();
-        // })
-        // pg.event.emit('layer_ending_show', { coin: this.wordDataList.length * 3 })
+            if (middleLayer) {
+                const middleLayerComponent = middleLayer.getComponent('middleLayer');
+                middleLayerComponent.goNextPage();
+                return;
+            } else {
+                console.log("[onFinish] middleLayer not found")
+            }
+        })
     }
 
     private wordBgList: Array<cc.Node>;
-- 
2.21.0