"use strict";
cc._RF.push(module, '669f4SuSl9ORqawBcbwCNpG', 'NumberToImage');
// Script/NumberToImage.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var NumberToImage = /** @class */ (function (_super) {
    __extends(NumberToImage, _super);
    function NumberToImage() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.fontUI = null;
        return _this;
        // static calculateAndConvert(num1: number, num2: number, operator: '+' | '-' | '*' | '/', spriteFrames: SpriteFrame[]): Node[] {
        //     let result: number;
        //     switch (operator) {
        //         case '+':
        //             result = num1 + num2;
        //             break;
        //         case '-':
        //             result = num1 - num2;
        //             break;
        //         case '*':
        //             result = num1 * num2;
        //             break;
        //         case '/':
        //             result = num1 / num2;
        //             break;
        //         default:
        //             throw new Error('不支持的运算符');
        //     }
        //     // 处理结果为小数的情况，这里简单取整
        //     result = Math.floor(result);
        //     return this.numberToImageNodes(result, spriteFrames);
        // }
        // update (dt) {}
    }
    NumberToImage_1 = NumberToImage;
    // LIFE-CYCLE CALLBACKS:
    NumberToImage.prototype.onLoad = function () {
        if (this.fontUI != null) {
            NumberToImage_1.font = this.fontUI;
        }
    };
    //第一个参数  数字， 第二个参数  数字间距  第三个参数 占位宽度  第四个参数 目标节点
    NumberToImage.numberToImageNodes = function (number, width, posX, name, targetNode, middle) {
        if (middle === void 0) { middle = false; }
        var numStr = number.toString();
        var cha = 0;
        if (number > 99)
            cha = -posX;
        else if (number < 10)
            cha = posX;
        if (targetNode.children.length > 0)
            targetNode.removeAllChildren();
        for (var i = 0; i < numStr.length; i++) {
            var digit = parseInt(numStr[i], 10);
            var node = new cc.Node();
            var sprite = node.addComponent(cc.Sprite);
            // debugger;
            sprite.spriteFrame = this.font._spriteFrames[name + digit + ""];
            // 将节点添加到目标节点下
            node.x = i * width + cha;
            node.parent = targetNode;
        }
        if (middle) {
            targetNode.x = targetNode.x - targetNode.children.length * (width - 15) / 2;
        }
    };
    NumberToImage.getTimeMargin = function (number, width, name, targetNode) {
        var timeArr = [];
        var total = 0;
        total = number;
        var hour = 0;
        hour = parseInt((total / 3600) + ""); //计算整数小时数
        var afterHour = total - hour * 60 * 60; //取得算出小时数后剩余的秒数
        var min = parseInt((afterHour / 60) + ""); //计算整数分
        var m = "" + min;
        if (min < 10)
            m = "0" + min;
        var afterMin = total - hour * 60 * 60 - min * 60; //取得算出分后剩余的秒数
        var miao = afterMin + "";
        if (afterMin < 10)
            miao = "0" + afterMin;
        var result = m + miao;
        for (var i = 0; i < result.length; i++) {
            var digit = parseInt(result[i], 10);
            timeArr.push(digit);
        }
        if (targetNode.children.length > 0) {
            for (var i = 0; i < targetNode.children.length; i++) {
                targetNode.children[i].getComponent(cc.Sprite).spriteFrame = this.font._spriteFrames[name + timeArr[i] + ""];
            }
        }
        else {
            for (var i = 0; i < 4; i++) {
                var node = new cc.Node();
                var sprite = node.addComponent(cc.Sprite);
                var digit = timeArr[i];
                // debugger;
                sprite.spriteFrame = this.font._spriteFrames[name + digit + ""];
                // 将节点添加到目标节点下
                node.x = i * width;
                if (i > 1)
                    node.x += 35;
                node.parent = targetNode;
            }
        }
    };
    var NumberToImage_1;
    NumberToImage.font = null;
    __decorate([
        property(cc.SpriteAtlas)
    ], NumberToImage.prototype, "fontUI", void 0);
    NumberToImage = NumberToImage_1 = __decorate([
        ccclass
    ], NumberToImage);
    return NumberToImage;
}(cc.Component));
exports.default = NumberToImage;

cc._RF.pop();