
let wasm;

const heap = new Array(32).fill(undefined);

heap.push(undefined, null, true, false);

function getObject(idx) { return heap[idx]; }

let heap_next = heap.length;

function dropObject(idx) {
    if (idx < 36) return;
    heap[idx] = heap_next;
    heap_next = idx;
}

function takeObject(idx) {
    const ret = getObject(idx);
    dropObject(idx);
    return ret;
}

let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachegetUint8Memory0 = null;
function getUint8Memory0() {
    if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
        cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
    }
    return cachegetUint8Memory0;
}

function getStringFromWasm0(ptr, len) {
    return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}

function addHeapObject(obj) {
    if (heap_next === heap.length) heap.push(heap.length + 1);
    const idx = heap_next;
    heap_next = heap[idx];

    heap[idx] = obj;
    return idx;
}

function isLikeNone(x) {
    return x === undefined || x === null;
}

let cachegetFloat64Memory0 = null;
function getFloat64Memory0() {
    if (cachegetFloat64Memory0 === null || cachegetFloat64Memory0.buffer !== wasm.memory.buffer) {
        cachegetFloat64Memory0 = new Float64Array(wasm.memory.buffer);
    }
    return cachegetFloat64Memory0;
}

let cachegetInt32Memory0 = null;
function getInt32Memory0() {
    if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
        cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
    }
    return cachegetInt32Memory0;
}

function debugString(val) {
    // primitive types
    const type = typeof val;
    if (type == 'number' || type == 'boolean' || val == null) {
        return `${val}`;
    }
    if (type == 'string') {
        return `"${val}"`;
    }
    if (type == 'symbol') {
        const description = val.description;
        if (description == null) {
            return 'Symbol';
        } else {
            return `Symbol(${description})`;
        }
    }
    if (type == 'function') {
        const name = val.name;
        if (typeof name == 'string' && name.length > 0) {
            return `Function(${name})`;
        } else {
            return 'Function';
        }
    }
    // objects
    if (Array.isArray(val)) {
        const length = val.length;
        let debug = '[';
        if (length > 0) {
            debug += debugString(val[0]);
        }
        for (let i = 1; i < length; i++) {
            debug += ', ' + debugString(val[i]);
        }
        debug += ']';
        return debug;
    }
    // Test for built-in
    const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
    let className;
    if (builtInMatches.length > 1) {
        className = builtInMatches[1];
    } else {
        // Failed to match the standard '[object ClassName]'
        return toString.call(val);
    }
    if (className == 'Object') {
        // we're a user defined class or Object
        // JSON.stringify avoids problems with cycles, and is generally much
        // easier than looping through ownProperties of `val`.
        try {
            return 'Object(' + JSON.stringify(val) + ')';
        } catch (_) {
            return 'Object';
        }
    }
    // errors
    if (val instanceof Error) {
        return `${val.name}: ${val.message}\n${val.stack}`;
    }
    // TODO we could test for more things here, like `Set`s and `Map`s.
    return className;
}

let WASM_VECTOR_LEN = 0;

let cachedTextEncoder = new TextEncoder('utf-8');

const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
    ? function (arg, view) {
        return cachedTextEncoder.encodeInto(arg, view);
    }
    : function (arg, view) {
        const buf = cachedTextEncoder.encode(arg);
        view.set(buf);
        return {
            read: arg.length,
            written: buf.length
        };
    });

function passStringToWasm0(arg, malloc, realloc) {

    if (realloc === undefined) {
        const buf = cachedTextEncoder.encode(arg);
        const ptr = malloc(buf.length);
        getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
        WASM_VECTOR_LEN = buf.length;
        return ptr;
    }

    let len = arg.length;
    let ptr = malloc(len);

    const mem = getUint8Memory0();

    let offset = 0;

    for (; offset < len; offset++) {
        const code = arg.charCodeAt(offset);
        if (code > 0x7F) break;
        mem[ptr + offset] = code;
    }

    if (offset !== len) {
        if (offset !== 0) {
            arg = arg.slice(offset);
        }
        ptr = realloc(ptr, len, len = offset + arg.length * 3);
        const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
        const ret = encodeString(arg, view);

        offset += ret.written;
    }

    WASM_VECTOR_LEN = offset;
    return ptr;
}

let cachegetUint32Memory0 = null;
function getUint32Memory0() {
    if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
        cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
    }
    return cachegetUint32Memory0;
}

function getArrayU32FromWasm0(ptr, len) {
    return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
}

function passArray32ToWasm0(arg, malloc) {
    const ptr = malloc(arg.length * 4);
    getUint32Memory0().set(arg, ptr / 4);
    WASM_VECTOR_LEN = arg.length;
    return ptr;
}

function handleError(f, args) {
    try {
        return f.apply(this, args);
    } catch (e) {
        wasm.__wbindgen_exn_store(addHeapObject(e));
    }
}
/**
*/
export const BottleState = Object.freeze({ Empty: 0, "0": "Empty", Some: 1, "1": "Some", Full: 2, "2": "Full", Close: 3, "3": "Close", });
/**
*/
export const GameState = Object.freeze({ GameInit: 0, "0": "GameInit", GamePlay: 1, "1": "GamePlay", GameWin: 2, "2": "GameWin", GameLost: 3, "3": "GameLost", GameOver: 4, "4": "GameOver", GamePause: 5, "5": "GamePause", });
/**
*/
export const DaoShuiGameEvent = Object.freeze({ GameWin: 0, "0": "GameWin", GameLost: 1, "1": "GameLost", GameOver: 2, "2": "GameOver", Move: 3, "3": "Move", });
/**
*/
export class Bottle {

    static __wrap(ptr) {
        const obj = Object.create(Bottle.prototype);
        obj.ptr = ptr;

        return obj;
    }

    __destroy_into_raw() {
        const ptr = this.ptr;
        this.ptr = 0;

        return ptr;
    }

    free() {
        const ptr = this.__destroy_into_raw();
        wasm.__wbg_bottle_free(ptr);
    }
    /**
    * @param {number} index
    */
    constructor(index) {
        var ret = wasm.bottle_new(index);
        return Bottle.__wrap(ret);
    }
    /**
    * @returns {Uint32Array}
    */
    get_bodys() {
        try {
            const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
            wasm.bottle_get_bodys(retptr, this.ptr);
            var r0 = getInt32Memory0()[retptr / 4 + 0];
            var r1 = getInt32Memory0()[retptr / 4 + 1];
            var v0 = getArrayU32FromWasm0(r0, r1).slice();
            wasm.__wbindgen_free(r0, r1 * 4);
            return v0;
        } finally {
            wasm.__wbindgen_add_to_stack_pointer(16);
        }
    }
    /**
    * @param {Uint32Array} bodys
    */
    set_bodys(bodys) {
        var ptr0 = passArray32ToWasm0(bodys, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        wasm.bottle_set_bodys(this.ptr, ptr0, len0);
    }
    /**
    * @returns {number}
    */
    get_index() {
        var ret = wasm.bottle_get_index(this.ptr);
        return ret >>> 0;
    }
    /**
    * @param {number} state
    */
    set_state(state) {
        wasm.bottle_set_state(this.ptr, state);
    }
    /**
    * @returns {number}
    */
    get_state() {
        var ret = wasm.bottle_get_state(this.ptr);
        return ret >>> 0;
    }
}
/**
*/
export class DaoShuiGameBox {

    static __wrap(ptr) {
        const obj = Object.create(DaoShuiGameBox.prototype);
        obj.ptr = ptr;

        return obj;
    }

    __destroy_into_raw() {
        const ptr = this.ptr;
        this.ptr = 0;

        return ptr;
    }

    free() {
        const ptr = this.__destroy_into_raw();
        wasm.__wbg_daoshuigamebox_free(ptr);
    }
    /**
    */
    constructor() {
        var ret = wasm.daoshuigamebox_new();
        return DaoShuiGameBox.__wrap(ret);
    }
    /**
    * @param {any} data
    */
    set_config_data(data) {
        wasm.daoshuigamebox_set_config_data(this.ptr, addHeapObject(data));
    }
    /**
    * @returns {any}
    */
    get_bottles() {
        var ret = wasm.daoshuigamebox_get_bottles(this.ptr);
        return takeObject(ret);
    }
    /**
    * @param {number} index
    * @returns {any}
    */
    get_bottle_info(index) {
        var ret = wasm.daoshuigamebox_get_bottle_info(this.ptr, index);
        return takeObject(ret);
    }
    /**
    * @returns {number}
    */
    get_game_time() {
        var ret = wasm.daoshuigamebox_get_game_time(this.ptr);
        return ret;
    }
    /**
    */
    play() {
        wasm.daoshuigamebox_backplay(this.ptr);
    }
    /**
    */
    backplay() {
        wasm.daoshuigamebox_backplay(this.ptr);
    }
    /**
    */
    stop() {
        wasm.daoshuigamebox_stop(this.ptr);
    }
    /**
    * @returns {number}
    */
    get_game_state() {
        var ret = wasm.daoshuigamebox_get_game_state(this.ptr);
        return ret >>> 0;
    }
    /**
    * @param {number} dt
    */
    update(dt) {
        wasm.daoshuigamebox_update(this.ptr, dt);
    }
    /**
    * @param {number} index
    * @returns {number}
    */
    touch_bottle(index) {
        var ret = wasm.daoshuigamebox_touch_bottle(this.ptr, index);
        return ret;
    }
    /**
    * @returns {Bottle | undefined}
    */
    get_cur_bottle() {
        var ret = wasm.daoshuigamebox_get_cur_bottle(this.ptr);
        return ret === 0 ? undefined : Bottle.__wrap(ret);
    }
    /**
    * @returns {Bottle | undefined}
    */
    get_target_bottle() {
        var ret = wasm.daoshuigamebox_get_target_bottle(this.ptr);
        return ret === 0 ? undefined : Bottle.__wrap(ret);
    }
    /**
    * @returns {Uint32Array}
    */
    move_body() {
        try {
            const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
            wasm.daoshuigamebox_move_body(retptr, this.ptr);
            var r0 = getInt32Memory0()[retptr / 4 + 0];
            var r1 = getInt32Memory0()[retptr / 4 + 1];
            var v0 = getArrayU32FromWasm0(r0, r1).slice();
            wasm.__wbindgen_free(r0, r1 * 4);
            return v0;
        } finally {
            wasm.__wbindgen_add_to_stack_pointer(16);
        }
    }
    /**
    */
    check_game_win_or_lost() {
        wasm.daoshuigamebox_check_game_win_or_lost(this.ptr);
    }
    /**
    */
    game_revive() {
        wasm.daoshuigamebox_game_revive(this.ptr);
    }
    /**
    * @returns {Uint32Array}
    */
    get_tests() {
        try {
            const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
            wasm.daoshuigamebox_get_tests(retptr, this.ptr);
            var r0 = getInt32Memory0()[retptr / 4 + 0];
            var r1 = getInt32Memory0()[retptr / 4 + 1];
            var v0 = getArrayU32FromWasm0(r0, r1).slice();
            wasm.__wbindgen_free(r0, r1 * 4);
            return v0;
        } finally {
            wasm.__wbindgen_add_to_stack_pointer(16);
        }
    }
    /**
    * @param {Uint32Array} tests
    */
    set_tests(tests) {
        var ptr0 = passArray32ToWasm0(tests, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        wasm.daoshuigamebox_set_tests(this.ptr, ptr0, len0);
    }
}
/**
*/
export class GameEventItem {

    static __wrap(ptr) {
        const obj = Object.create(GameEventItem.prototype);
        obj.ptr = ptr;

        return obj;
    }

    __destroy_into_raw() {
        const ptr = this.ptr;
        this.ptr = 0;

        return ptr;
    }

    free() {
        const ptr = this.__destroy_into_raw();
        wasm.__wbg_gameeventitem_free(ptr);
    }
    /**
    * @param {number} game_time
    * @param {Uint32Array} from_indexs
    * @param {Uint32Array} to_indexs
    * @param {number} game_event
    * @param {Uint32Array} event_values
    * @param {number} duration
    */
    constructor(game_time, from_indexs, to_indexs, game_event, event_values, duration) {
        var ptr0 = passArray32ToWasm0(from_indexs, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        var ptr1 = passArray32ToWasm0(to_indexs, wasm.__wbindgen_malloc);
        var len1 = WASM_VECTOR_LEN;
        var ptr2 = passArray32ToWasm0(event_values, wasm.__wbindgen_malloc);
        var len2 = WASM_VECTOR_LEN;
        var ret = wasm.gameeventitem_new(game_time, ptr0, len0, ptr1, len1, game_event, ptr2, len2, duration);
        return GameEventItem.__wrap(ret);
    }
}

async function load(module, imports) {
    if (typeof Response === 'function' && module instanceof Response) {
        if (typeof WebAssembly.instantiateStreaming === 'function') {
            try {
                return await WebAssembly.instantiateStreaming(module, imports);

            } catch (e) {
                if (module.headers.get('Content-Type') != 'application/wasm') {
                    console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);

                } else {
                    throw e;
                }
            }
        }

        const bytes = await module.arrayBuffer();
        return await WebAssembly.instantiate(bytes, imports);

    } else {
        const instance = await WebAssembly.instantiate(module, imports);

        if (instance instanceof WebAssembly.Instance) {
            return { instance, module };

        } else {
            return instance;
        }
    }
}

async function init(input) {
    if (typeof input === 'undefined') {
        input = new URL('demo_bg.wasm', import.meta.url);
    }
    const imports = {};
    imports.wbg = {};
    imports.wbg.__wbindgen_object_drop_ref = function (arg0) {
        takeObject(arg0);
    };
    imports.wbg.__wbindgen_string_new = function (arg0, arg1) {
        var ret = getStringFromWasm0(arg0, arg1);
        return addHeapObject(ret);
    };
    imports.wbg.__wbindgen_is_undefined = function (arg0) {
        var ret = getObject(arg0) === undefined;
        return ret;
    };
    imports.wbg.__wbindgen_is_null = function (arg0) {
        var ret = getObject(arg0) === null;
        return ret;
    };
    imports.wbg.__wbg_bottle_new = function (arg0) {
        var ret = Bottle.__wrap(arg0);
        return addHeapObject(ret);
    };
    imports.wbg.__wbindgen_number_new = function (arg0) {
        var ret = arg0;
        return addHeapObject(ret);
    };
    imports.wbg.__wbg_get_73c087db0a496c21 = function (arg0, arg1) {
        var ret = getObject(arg0)[arg1 >>> 0];
        return addHeapObject(ret);
    };
    imports.wbg.__wbg_length_c5fa152b8c3f311f = function (arg0) {
        var ret = getObject(arg0).length;
        return ret;
    };
    imports.wbg.__wbg_new_ec75d0d5815be736 = function () {
        var ret = new Array();
        return addHeapObject(ret);
    };
    imports.wbg.__wbg_get_6d26c712aa73c8b2 = function () {
        return handleError(function (arg0, arg1) {
            var ret = Reflect.get(getObject(arg0), getObject(arg1));
            return addHeapObject(ret);
        }, arguments)
    };
    imports.wbg.__wbg_new_4b48f9f8159fea77 = function () {
        var ret = new Object();
        return addHeapObject(ret);
    };
    imports.wbg.__wbg_from_28631399e1e647cb = function (arg0) {
        var ret = Array.from(getObject(arg0));
        return addHeapObject(ret);
    };
    imports.wbg.__wbg_push_0daae9343162dbe7 = function (arg0, arg1) {
        var ret = getObject(arg0).push(getObject(arg1));
        return ret;
    };
    imports.wbg.__wbg_set_d29a397c9cc5d746 = function () {
        return handleError(function (arg0, arg1, arg2) {
            var ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
            return ret;
        }, arguments)
    };
    imports.wbg.__wbindgen_number_get = function (arg0, arg1) {
        const obj = getObject(arg1);
        var ret = typeof (obj) === 'number' ? obj : undefined;
        getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
        getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
    };
    imports.wbg.__wbindgen_debug_string = function (arg0, arg1) {
        var ret = debugString(getObject(arg1));
        var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
        var len0 = WASM_VECTOR_LEN;
        getInt32Memory0()[arg0 / 4 + 1] = len0;
        getInt32Memory0()[arg0 / 4 + 0] = ptr0;
    };
    imports.wbg.__wbindgen_throw = function (arg0, arg1) {
        throw new Error(getStringFromWasm0(arg0, arg1));
    };

    if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
        if (typeof wx != 'undefined' && wx.request) {
            // 微信直接用input
        } else {
            input = fetch(input);
        }
    }



    const { instance, module } = await load(await input, imports);

    wasm = instance.exports;
    init.__wbindgen_wasm_module = module;

    return wasm;
}

export default init;

