@vyr/engine 0.0.25 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@vyr/engine",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@vyr/locale": "0.0.25",
9
+ "@vyr/locale": "0.0.27",
10
10
  "tinycolor2": "1.6.0"
11
11
  },
12
12
  "devDependencies": {
package/src/Engine.ts CHANGED
@@ -60,7 +60,7 @@ class Engine extends Listener<EngineListener> {
60
60
 
61
61
  if (typeof el === 'string') {
62
62
  const ele = document.getElementById(el)
63
- if (ele === null) throw language.get('engine.run.container.notFound')
63
+ if (ele === null) throw new Error(language.get('engine.run.container.notFound'))
64
64
  el = ele
65
65
  }
66
66
  el.appendChild(this.DOM)
@@ -107,7 +107,7 @@ class Engine extends Listener<EngineListener> {
107
107
  return this.compilation.get(scheduler)
108
108
  }
109
109
 
110
- ensureGraphicsExists(url: string, scheduler: ServiceSchedulerDescriptor) {
110
+ ensureGraphics(url: string, scheduler: ServiceSchedulerDescriptor) {
111
111
  return this.compilation.ensureExists(url, scheduler, this)
112
112
  }
113
113
  }
@@ -113,7 +113,7 @@ class Asset {
113
113
  if (status === null) continue
114
114
 
115
115
  let factory = privateState.assetFactoryCollection.get(status.category)
116
- if (factory === undefined) throw language.get('asset.load.fail', { category: status.category })
116
+ if (factory === undefined) throw new Error(language.get('asset.load.fail', { category: status.category }))
117
117
 
118
118
  const task = new AsyncTask(async () => {
119
119
  const asset = await factory(assetUrl, forced)
@@ -188,7 +188,7 @@ class Asset {
188
188
  static async compileDataset(url: string, engine: Engine) {
189
189
  const descriptor = this.get<ServiceSchedulerDescriptor>(url)
190
190
  if (descriptor === null) return
191
- const graphics = engine.ensureGraphicsExists(url, descriptor)
191
+ const graphics = engine.ensureGraphics(url, descriptor)
192
192
  const dependencide = Asset.graph.getDependencide(url)
193
193
 
194
194
  const queue: Promise<void>[] = []
@@ -103,7 +103,7 @@ class Descriptor extends ObjectPool {
103
103
  /**使用数据动态的创建描述器 */
104
104
  static create<T extends Descriptor = Descriptor>(descriptor: Partial<DeserializationObject<Descriptor>>) {
105
105
  const Class = this.getClass(descriptor.type ?? Descriptor.type)
106
- if (Class === null) throw language.get('descriptor.notRegister', { type: descriptor.type })
106
+ if (Class === null) throw new Error(language.get('descriptor.notRegister', { type: descriptor.type }))
107
107
  return new Class(descriptor) as T
108
108
  }
109
109
  /**将对象序列化成json字符 */
@@ -27,7 +27,7 @@ type OverrideUpdate = (descriptor: Descriptor, interpreter: Interpreter) => void
27
27
  class Graphics {
28
28
  static createInterpreter<T extends Interpreter = Interpreter>(descriptor: Descriptor, graphics: Graphics) {
29
29
  const Class = Interpreter.getClass(descriptor.type)
30
- if (Class === null) throw language.get('graphics.interpreter.notRegister', { type: descriptor.type })
30
+ if (Class === null) throw new Error(language.get('graphics.interpreter.notRegister', { type: descriptor.type }))
31
31
  privateState.factory = true
32
32
  let unit = graphics.unitCollection.get(descriptor.uuid) as Unit
33
33
  if (unit === undefined) unit = graphics._freeCollection.get(descriptor.uuid) as Unit
@@ -28,7 +28,7 @@ class Interpreter {
28
28
  readonly graphics
29
29
 
30
30
  constructor(unit: Unit, graphics: Graphics) {
31
- if (privateState.factory === false) throw language.get('interpreter.new.fail')
31
+ if (privateState.factory === false) throw new Error(language.get('interpreter.new.fail'))
32
32
  this.unit = unit
33
33
  this.graphics = graphics
34
34
  }
package/src/utils/http.ts CHANGED
@@ -2,6 +2,11 @@ import { ScriptableArgs } from "../interaction";
2
2
  import { Asset } from "../asset";
3
3
  import { HttpType } from "./constants";
4
4
 
5
+ const headers = {}
6
+ const setHttpHeaders = (options: { [k: string]: any }) => {
7
+ Object.assign(headers, options)
8
+ }
9
+
5
10
  const joinUrl = (url: string, requestData: any) => {
6
11
  const urlObj = new URL(Asset.joinUrl(url));
7
12
 
@@ -37,6 +42,7 @@ const http = async (url: string, type: string, data: string, result: ScriptableA
37
42
  method: type,
38
43
  headers: {
39
44
  'Content-Type': 'application/json',
45
+ ...headers,
40
46
  },
41
47
  }
42
48
  let res
@@ -52,5 +58,6 @@ const http = async (url: string, type: string, data: string, result: ScriptableA
52
58
  }
53
59
 
54
60
  export {
55
- http
61
+ setHttpHeaders,
62
+ http,
56
63
  }