import CSSettingsV3Example from "./CSSettingsV3Example";
import { StringExampleTable } from "./Tables/StringTableExample";


const { ccclass, property } = cc._decorator;

@ccclass
export default class TableUseExample extends cc.Component {

    start() {

        //#region StringExample表
        cc.log("----------------#stringExample");
        cc.log(CSSettingsV3Example.StringExample instanceof StringExampleTable); // true
        cc.log(Array.isArray(CSSettingsV3Example.StringExample)); // true, 所以Array相關的方法都可以拿來操作

        cc.log(CSSettingsV3Example.StringExample.length);
        cc.log(CSSettingsV3Example.StringExample.Count); // 跟length一樣

        cc.log(CSSettingsV3Example.StringExample.ContainsRow(11)); // 是否包含id=11的Row
        cc.log(11 in CSSettingsV3Example.StringExample); // 同上

        cc.log(CSSettingsV3Example.StringExample[1].MsgZnCh);
        cc.log(CSSettingsV3Example.StringExample[1]["MsgZnCh"]); // 同上
        cc.log(CSSettingsV3Example["StringExample"][1]["MsgZnCh"]); // 同上

        cc.log("----------------");
        for (let row of CSSettingsV3Example.StringExample) {
            if (row) { // 如果Row沒有連號, 那有可能取到undefined值, 要先判斷, 不想判斷就用 CSSettings.StringExample.Rows
                cc.log(row.Id, row.MsgZnCh);
            }
        }

        cc.log("----------------");
        for (let id of CSSettingsV3Example.StringExample.Keys) {
            cc.log(id); // 只會列出有值的id, undefined會跳過
        }

        cc.log("----------------");
        for (let row of CSSettingsV3Example.StringExample.Rows) {
            cc.log(row.Id, row.MsgZnCh); // 只會列出有值的Row, undefined會跳過
        }
        //#endregion

        //#region StringExample表 #StringFilter表
        cc.log("----------------#stringExample#string_filter");
        //cc.log(CSSettings.StringExample.StringFilter instanceof StringFilterTable); // true
        cc.log(Array.isArray(CSSettingsV3Example.StringExample.StringFilter)); // true, 所以Array相關的方法都可以拿來操作

        cc.log(CSSettingsV3Example.StringExample.StringFilter.length);
        cc.log(CSSettingsV3Example.StringExample.StringFilter.Count); // 跟length一樣

        cc.log(CSSettingsV3Example.StringExample.StringFilter.ContainsRow(11)); // 是否包含id=11的Row
        cc.log(11 in CSSettingsV3Example.StringExample.StringFilter); // 同上

        cc.log(CSSettingsV3Example.StringExample.StringFilter[1].FilterWord);
        cc.log(CSSettingsV3Example.StringExample.StringFilter[1]["FilterWord"]); // 同上
        cc.log(CSSettingsV3Example["StringExample"]["StringFilter"][1]["FilterWord"]); // 同上

        cc.log("----------------");
        for (let row of CSSettingsV3Example.StringExample.StringFilter) {
            if (row) { // 如果Row沒有連號, 那有可能取到undefined值, 要先判斷, 不想判斷就用 CSSettings.StringExample.StringFilter.Rows
                cc.log(row.Id, row.FilterWord);
            }
        }

        cc.log("----------------");
        for (let id of CSSettingsV3Example.StringExample.StringFilter.Keys) {
            cc.log(id); // 只會列出有值的id, undefined會跳過
        }

        cc.log("----------------");
        for (let row of CSSettingsV3Example.StringExample.StringFilter.Rows) {
            cc.log(row.Id, row.FilterWord); // 只會列出有值的Row, undefined會跳過
        }
        //#endregion

        cc.log("----------------");
        //CSSettingsV3.ResetTables(); // 重置表

    }
}
