'use strict'
!(function(require, directRequire) {
  function a(a, b, c, d) {
    c = 0 < c ? c : 1
    let f = e(a, b, c)
    return `${d}\n${f}`
  }
  function b(a, b) {
    let e = [],
      g = 'subPackages'
    if (
      (b.subpackages &&
        ((g = 'subpackages'),
        (b.subPackages = b.subpackages),
        delete b.subpackages),
      b.subPackages)
    ) {
      if ('array' != f.getType(b.subPackages))
        return e.push(h.config.JSON_CONTENT_SHOULD_BE.format([g, 'Array'])), e
      let i = {},
        j = {}
      b.subPackages.forEach((b, k) => {
        if (
          ('undefined' != typeof b.name &&
            ('string' != f.getType(b.name) &&
              e.push(
                h.config.JSON_CONTENT_SHOULD_BE.format([
                  `${g}[${k}].name`,
                  'String'
                ])
              ),
            i[b.name] &&
              e.push(h.config.JSON_CONTENT_EXISTED.format(`${g}[${k}].name`)),
            (i[b.name] = !0)),
          'string' != f.getType(b.root))
        )
          return void e.push(
            h.config.JSON_CONTENT_SHOULD_BE.format([
              `${g}[${k}].root`,
              'String'
            ])
          )
        if (
          (j[b.root] &&
            e.push(h.config.JSON_CONTENT_EXISTED.format(`${g}[${k}].root`)),
          (j[b.root] = !0),
          0 == b.root.indexOf('.'))
        )
          return void e.push(
            h.config.JSON_SHOULD_NOT_START_WITH.format([`${g}[${k}].root`, '.'])
          )
        ;(b.root = c.posix.normalize(b.root)),
          0 != b.root.indexOf('/') && (b.root = '/' + b.root)
        let l = c.join(a, b.root)
        if (!d.existsSync(l))
          e.push(h.config.JSON_CONTENT_NOT_FOUND.format(`${g}[${k}].root`))
        else {
          let a = d.statSync(l)
          a.isDirectory() &&
            (!/\/$/.test(b.root) && (b.root += '/'),
            !d.existsSync(c.join(l, './game.js')) &&
              e.push(h.config.JSON_CONTENT_NOT_FOUND.format(`${l}/game.js`)))
        }
      })
    }
    return e
  }
  const c = require('path'),
    d = require('fs'),
    e = require('babel-code-frame'),
    f = require('./tools.js'),
    g = require('./libs/jsonlint.js').parser,
    h = require('./common/locales/index.js'),
    i = require('./162bf2ee28b76d3b3d95b685cede4146.js'),
    j = require('./2bc7cd511c5a7e0e403126d943b041b1.js'),
    k = require('./9fdd4ac31a05c27355910f0d74accd4c.js')
  ;(g.parseError = g.lexer.parseError = function(a, b) {
    throw b
  }),
    (module.exports = async function(e) {
      let l = await i(e),
        m = l.srcPath,
        n = require('./6242f55dbdfe53c2f07b7a51568311f2.js'),
        o = 'game.json',
        p = ''
      try {
        p = l.getFile(o)
      } catch (a) {
        p = ''
        let b = new Error(a.message)
        throw ((b.code = j.GAME_JSON_READ_ERR), b)
      }
      let q = {}
      try {
        ;(q = g.parse(p)), (q.configFrom = o)
      } catch (b) {
        let c = `编译 game.json 文件出错: Expecting ${b.expected}, got ${
            b.token
          }`,
          d = a(p, b.line, b.loc.first_column, c),
          e = new Error(d)
        throw ((e.code = j.GAME_JSON_PARSE_ERR), e)
      }
      let r = q.deviceOrientation
      if (r)
        if ('string' != f.getType(r)) {
          let a = new Error(
            h.config.JSON_CONTENT_SHOULD_BE.format([
              'deviceOrientation',
              'String \u7C7B\u578B'
            ])
          )
          throw ((a.code = j.GAME_JSON_CONTENT_ERR), a)
        } else if ('portrait' != r && 'landscape' != r) {
          let a = new Error(
            h.config.JSON_CONTENT_SHOULD_BE.format([
              'deviceOrientation',
              '"portrait" \u6216 "landscape"'
            ])
          )
          throw ((a.code = j.GAME_JSON_CONTENT_ERR), a)
        }
      if (q.networkTimeout && 'object' != f.getType(q.networkTimeout)) {
        let a = new Error(
          h.config.JSON_CONTENT_SHOULD_BE.format(['networkTimeout', 'Object'])
        )
        throw ((a.code = j.GAME_JSON_CONTENT_ERR), a)
      }
      let s = q.openDataContext
      if (q.openDataContext || q.subContext) {
        let a
        if (
          ((a = (q.openDataContext || q.subContext).replace('./', '')),
          /\/$/.test(a) || (a = `${a}/`),
          '/' === a || './' === a || 0 === a.indexOf('.'))
        ) {
          let a = new Error(
            'subContext \u8BBE\u7F6E\u4E0D\u5408\u6CD5\uFF0C\u5FC5\u987B\u4E3A\u9879\u76EE\u76EE\u5F55\u4E2D\u7684\u4E00\u4E2A\u5B50\u76EE\u5F55\u3002'
          )
          throw ((a.code = j.GAME_SUBCONTEXT_ERR), a)
        }
        let b = c.join(a, s ? 'index.js' : 'sub.js')
        try {
          l.getFile(b)
        } catch (a) {
          let b = new Error(a.message)
          throw ((b.code = j.GAME_SUBJS_NOT_FOUND), b)
        }
        s ? ((q.openDataContext = a), (q.subContext = a)) : (q.subContext = a)
      }
      let t = e.compileType
      if (t == k.conversation || t == k.search) {
        let a,
          b = q.widgets,
          g = ''
        if (!b) a = new Error(h.config.JSON_WIDGETS_EMPTY.format('game.json'))
        else if ('array' != f.getType(b))
          a = new Error(h.config.JSON_WIDGETS_NOT_ARRAY.format('game.json'))
        else {
          let i = []
          b.forEach((a, b) => {
            if ('object' != f.getType(a))
              i.push(
                h.config.JSON_WIDGETS_ITEM_NOT_OBJECT.format(['game.json', b])
              )
            else if ('conversation' != a.type && 'search' != a.type)
              i.push(
                h.config.JSON_WIDGETS_TYPE_INVALID.format([
                  'game.json',
                  b,
                  'conversation\u3001search'
                ])
              )
            else if (!a.path || 'string' != f.getType(a.path))
              i.push(
                h.config.JSON_WIDGETS_PATH_NOT_FOUND.format(['game.json', b])
              )
            else if (!d.existsSync(c.join(m, a.path)))
              i.push(
                h.config.JSON_WIDGETS_PATH_NOT_FOUND.format(['game.json', b])
              )
            else {
              let e = d.statSync(c.join(m, a.path))
              e.isDirectory()
                ? !d.existsSync(c.join(m, a.path, 'widget.js')) &&
                  i.push(
                    h.config.JSON_WIDGETS_JS_NOT_FOUND.format([
                      'game.json',
                      b,
                      'widget.js'
                    ])
                  )
                : i.push(
                    h.config.JSON_WIDGETS_PATH_SHOULD_BE_DIR.format([
                      'game.json',
                      b
                    ])
                  )
            }
            g || a.type != e.compileType || (g = a.path)
          }),
            g ||
              i.push(
                h.config.JSON_WIDGETS_TYPE_NOT_FOUND.format([
                  'game.json',
                  e.compileType
                ])
              ),
            0 < i.length && (a = new Error(i.join('\n')))
        }
        if (a) throw ((a.code = j.GAME_JSON_CONTENT_ERR), a)
      }
      let u = b(m, q)
      if (0 < u.length) {
        let a = new Error(u.join('\n'))
        throw ((a.code = j.GAME_JSON_CONTENT_ERR), a)
      }
      return q
    })
})(require('lazyload'), require)
