
                (function() {
                    var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
                    var __module = nodeEnv ? module : {exports:{}};
                    var __filename = 'preview-scripts/assets/Script/lq_base/util/lq_game_util.js';
                    var __require = nodeEnv ? function (request) {
                        return cc.require(request);
                    } : function (request) {
                        return __quick_compile_project__.require(request, __filename);
                    };
                    function __define (exports, require, module) {
                        if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}"use strict";
cc._RF.push(module, '63c53CB9dhL/phFOPtTeuF7', 'lq_game_util');
// Script/lq_base/util/lq_game_util.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LQGameUtil = void 0;
var director = cc.director;
var tween = cc.tween;
var visibleRect = cc.visibleRect;
var find = cc.find;
var LQGameUtil = /** @class */ (function () {
    function LQGameUtil() {
    }
    LQGameUtil.get_image = function (url, callback, cache) {
        if (cache === void 0) { cache = true; }
        if (!url || url === '') {
            callback(false, undefined);
            return;
        }
        if (this.image_cache[url]) {
            callback(true, this.image_cache[url]);
            return;
        }
        // cc.loader.load(
        //     {url: url, type: 'png'},
        //     (err: string, texture: Texture2D | undefined) => {
        //         if (err) {
        //             // console.error('err:' + err);
        //             callback(false, undefined);
        //             return;
        //         }
        //         const frame = new SpriteFrame(texture);
        //         callback(true, frame);
        //         if (cache) {
        //             this.image_cache[url] = frame;
        //         }
        //     });
    };
    LQGameUtil.canvas_policy = function (c, width, height) {
        // @ts-ignore
        var ratio = visibleRect.height / visibleRect.width;
        if (ratio > height / width) {
            c.fitHeight = false;
            c.fitWidth = true;
        }
        else {
            c.fitHeight = true;
            c.fitWidth = false;
        }
        return c.fitHeight;
    };
    LQGameUtil.recursion_node_property = function (node, p) {
        if (node.parent) {
            // @ts-ignore
            p.value *= node.parent[p.key];
            this.recursion_node_property(node.parent, p);
        }
    };
    /**
     *
     * @param path
     * eg.'Canvas>node_main>btn_start'
     */
    LQGameUtil.find_node = function (path) {
        if (!path || path.length <= 0) {
            console.warn('路径不正确');
            return undefined;
        }
        var arr = path.split('/');
        var root = find(arr[0]);
        if (!root) {
            console.warn('没找到节点:' + arr[0]);
            return undefined;
        }
        var node = root;
        for (var i = 1; i < arr.length; i++) {
            var temp = node.getChildByName(arr[i]);
            if (!temp) {
                console.warn('没找到节点:' + arr[i]);
                return undefined;
            }
            node = temp;
        }
        return node;
    };
    LQGameUtil.wait = function (time) {
        return new Promise(function (resolve) {
            tween(director.getScene()).delay(time).call(function () {
                resolve();
            }).start();
        });
    };
    LQGameUtil.set_clip = function (clip, off, flip_x, flip_y) {
        var s = function (arr) {
            for (var i = 0; i < arr.length; i++) {
                if (i % 2 === 0) {
                    if (flip_x) {
                        arr[i] = -arr[i];
                    }
                    arr[i] += off.x;
                }
                else {
                    if (flip_y) {
                        arr[i] = -arr[i];
                    }
                    arr[i] += off.y;
                }
            }
        };
        var pos_arr = clip.curveData.props.position;
        for (var i = 0; i < pos_arr.length; i++) {
            var motionPath = pos_arr[i].motionPath;
            var value = pos_arr[i].value;
            if (motionPath) {
                for (var i_1 = 0; i_1 < motionPath.length; i_1++) {
                    s(motionPath[i_1]);
                }
            }
            s(value);
        }
    };
    LQGameUtil.scroll_layout = function (layout, speed) {
        if (speed === void 0) { speed = 50; }
        layout.updateLayout();
        var len = layout.type === cc.Layout.Type.HORIZONTAL ? layout.node.width : layout.node.height;
        var time = len / speed;
        if (layout.type === cc.Layout.Type.HORIZONTAL) {
            var offset_1 = layout.node.anchorX === 1 ? layout.node.width * 0.5 : -layout.node.width * 0.5;
            layout.node.runAction(cc.repeatForever(cc.sequence(cc.moveBy(time, cc.v2(offset_1, 0)), cc.callFunc(function () {
                layout.node.x -= offset_1;
            }))));
        }
        else if (layout.type === cc.Layout.Type.VERTICAL || layout.type === cc.Layout.Type.GRID) {
            var offset_2 = layout.node.anchorY === 1 ? layout.node.height * 0.5 : -layout.node.height * 0.5;
            layout.node.runAction(cc.repeatForever(cc.sequence(cc.moveBy(time, cc.v2(0, offset_2)), cc.callFunc(function () {
                layout.node.y -= offset_2;
            }))));
        }
    };
    LQGameUtil.image_cache = {};
    return LQGameUtil;
}());
exports.LQGameUtil = LQGameUtil;

cc._RF.pop();
                    }
                    if (nodeEnv) {
                        __define(__module.exports, __require, __module);
                    }
                    else {
                        __quick_compile_project__.registerModuleFunc(__filename, function () {
                            __define(__module.exports, __require, __module);
                        });
                    }
                })();
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 13648 characters]