'use strict'
!(function(require, directRequire) {
  function a() {
    M = ''
  }
  function b(b, c) {
    let e = d.extname(c)
    '.js' === e
      ? ('add' == b || 'unlink' == b) && a()
      : ('app-config.json' == c || 'game.json' == c) && a()
  }
  async function c(c) {
    let d = await g(c)
    ;(L && L.srcPath == d.srcPath) ||
      (a(), L && L.unWatch(b), (L = d), L.watch(b))
  }
  const d = require('path'),
    e = require('./d28a711224425b00101635efe1034c99.js'),
    f = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    g = require('./162bf2ee28b76d3b3d95b685cede4146.js'),
    h = require('./1bd2563d13db26950ae47494b2c34454.js'),
    i = require('./dbf59194122bf3d143456959d86d6213.js'),
    j = require('./be8599cf60139a20dca47b3e43647454.js'),
    k = require('./bc78839ccca8df9e5ceeb7fae11b7be2.js'),
    {
      asDebug: l,
      subAsDebug: m,
      vendorList: n,
      devVendorList: o,
      devSubContextList: p,
      devWorkerList: q,
      appservicejslistPlaceholder: r,
      subvendorList: s,
      workerVendorList: t,
      htmlTpl: u,
      asdebugPlaceholder: v,
      devtoolsConfigPlaceholder: w,
      wxConfigPlaceholder: x,
      vendorPlaceholder: y,
      subVendorPlaceholder: z,
      subAppservicejslistPlaceholder: A,
      canvasPlaceholder: B,
      subAsdebugPlaceholder: C,
      workerjslistPlaceholder: D,
      workerVendorPlaceholder: E,
      workerAsdebugPlaceholder: F,
      workerAsDebug: G
    } = require('./d9ce5316cc172b6017fdd2399a91117a.js'),
    H = global.appConfig.isDev,
    I = H && !nw.App.manifest.forceVendor ? o : n,
    J = H && !nw.App.manifest.forceVendor ? p : s,
    K = H && !nw.App.manifest.forceVendor ? q : t
  var L,
    M = '',
    N = ''
  e.on('VENDOR_CONFIG_CHANGE', a),
    e.on('VENDOR_VERSION_CHANGE', a),
    a(),
    (module.exports = async function(a, b = {}) {
      await c(a)
      let e = !1,
        g = j(),
        i = JSON.stringify({
          setting: a.setting,
          condiction: a.condiction,
          devtoolsConfig: g
        })
      if ((i !== N && ((e = !0), (N = i)), e || !M || b.force)) {
        let b = u
        ;(b = b.replace(w, () => {
          return `<script>var __devtoolsConfig=${JSON.stringify(g)}</script>`
        })),
          (b = b.replace(v, () => {
            return H
              ? '<script src="__asdebug__/asdebug.js"></script>'
              : `<script>${l}</script>`
          })),
          (b = b.replace(y, () => {
            let a = []
            for (let b = 0, c = I.length; b < c; b++) {
              let c = I[b],
                e = d.extname(c)
              '.js' === e
                ? a.push(`<script src="__dev__/${c}"></script>`)
                : '.css' === e &&
                  a.push(
                    `<link rel="stylesheet" type="text/css" href="__dev__/${c}" />`
                  )
            }
            return a.join('\n')
          }))
        let c = await h(a),
          e = c.openDataContext || c.subContext
        e &&
          (b = b.replace(C, () => {
            return H
              ? '<script src="__subasdebug__/subasdebug.js"></script>'
              : `<script>${m}</script>`
          }))
        let i = c.workers
        i &&
          ((b = b.replace(F, () => {
            return H
              ? '<script src="__workerasdebug__/workerasdebug.js"></script>'
              : `<script>${G}</script>`
          })),
          (b = b.replace(E, () => {
            const a = []
            for (let b = 0, c = K.length; b < c; b++) {
              let c = K[b],
                e = d.extname(c)
              '.js' === e &&
                a.push(`<script src="__workerdev__/${c}"></script>`)
            }
            const b = `<script>var __workerVendors__ = ${JSON.stringify(
              K
            )}</script>`
            return b + '\n' + a.join('\n')
          }))),
          (b = b.replace(B, () => {
            let a = k.getState(),
              b = a.toolbar.deviceInfo,
              { screenHeight: c, screenWidth: d } = b
            return `<canvas id="myCanvas" width="${d}" height="${c}" ></canvas>`
          }))
        let j = L.getAllJSFiles(),
          n = 'game',
          o = [],
          p = [],
          q = [],
          s = !1
        j.forEach(a => {
          if (e && 0 === a.indexOf(e)) p.push(a)
          else if (i && 0 === a.indexOf(i)) q.push(a)
          else {
            if (c.subPackages) {
              let b = f.checkInGameSubPackage(c, a)
              if (b) return
            }
            let b = d.normalize(a.replace(/\.js$/, ''))
            n === b
              ? (s = !0)
              : o.push(`<script src="${encodeURI(a)}"></script>`)
          }
        }),
          (n = s
            ? `<script src="${n}.js"></script>`
            : `<script>
        console.group("${new Date()} game 编译错误")
        console.error(\` ${n}.js 未找到\`)
        console.groupEnd()
        </script>`),
          o.push(n),
          (b = b.replace(r, () => {
            return o.join('\n')
          })),
          i &&
            q.length &&
            (b = b.replace(D, () => {
              let a = []
              for (let b = 0; b < q.length; b++)
                a.push(`<script src="${encodeURI(q[b])}"></script>`)
              return a.join('\n')
            })),
          (M = b)
      }
      return M
    })
})(require('lazyload'), require)
