sapdon 3.2.0 → 3.2.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "sapdon",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "scripts": {
5
5
  "build": "node scripts/build.cjs",
6
6
  "pub": "npm run build && npm publish"
package/prod/cli/start.js CHANGED
@@ -7,11 +7,8 @@ import fs, { readFileSync } from 'fs';
7
7
  import { randomUUID } from 'crypto';
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import cp from 'child_process';
10
- import { cacheSync } from '@sapdon/utils/cache.js';
11
10
  import fs$1 from 'fs/promises';
12
- import { serialize } from '@sapdon/utils/index.js';
13
11
  import http from 'http';
14
- import { handleRemoteLogger } from '@sapdon/cli/remoteLogger/server.js';
15
12
  import { rollup } from 'rollup';
16
13
  import commonjs from '@rollup/plugin-commonjs';
17
14
  import { nodeResolve } from '@rollup/plugin-node-resolve';
@@ -112,6 +109,17 @@ function parseJsonWithComments(jsonStr) {
112
109
  return JSON.parse(String(jsonStr).replace(/\/\/.*|\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, "$1"));
113
110
  }
114
111
 
112
+ const caches = new Map();
113
+ function cacheSync(uri, setter) {
114
+ let value = caches.get(uri);
115
+ if (value) {
116
+ return value;
117
+ }
118
+ value = setter(uri);
119
+ caches.set(uri, value);
120
+ return value;
121
+ }
122
+
115
123
  function getBuildConfig() {
116
124
  const pwd = getProjectPath();
117
125
  const configFile = path.join(pwd, 'build.config');
@@ -378,6 +386,9 @@ if (!Symbol.metadata) {
378
386
  //@ts-ignore
379
387
  Symbol.metadata = Symbol('[[metadata]]');
380
388
  }
389
+ function getMetadata(target) {
390
+ return target?.[Symbol.metadata];
391
+ }
381
392
 
382
393
  // 因为无法判断其他代码实现的接口是否真的是RawType,所以用Symbol来标记
383
394
  // 只要不export,其他代码就无法访问这个Symbol, 确保了唯一性
@@ -418,6 +429,21 @@ function jsonEncoderReplacer(_, v) {
418
429
  }
419
430
  throw new Error('Unexpected value');
420
431
  }
432
+ const defaultSerializer = instance => {
433
+ return structuredClone(instance);
434
+ };
435
+ const serializerSymbol = Symbol('serializer');
436
+ const serializerMapping = new WeakMap();
437
+ function serialize(inst) {
438
+ const ctor = Reflect.getPrototypeOf(inst)?.constructor;
439
+ if (!ctor) {
440
+ throw new Error('Cannot serialize an instance of an anonymous class');
441
+ }
442
+ const serializer = getMetadata(ctor)?.[serializerSymbol]
443
+ ?? serializerMapping.get(ctor)
444
+ ?? defaultSerializer;
445
+ return serializer.call(inst, inst);
446
+ }
421
447
  const jsonEncodeDecoder = {
422
448
  encode(value) {
423
449
  return JSON.stringify(value, jsonEncoderReplacer);
@@ -553,6 +579,10 @@ class UISystemRegistryServer {
553
579
  }
554
580
  }
555
581
 
582
+ async function handleRemoteLogger({ level, message, timeStamp, stack }) {
583
+ console[level](message, stack, `\nat ${new Date(timeStamp).toLocaleString()}`);
584
+ }
585
+
556
586
  const clientRegistryData = [];
557
587
  /**
558
588
  * Client
@@ -754,7 +784,7 @@ function getGamePath() {
754
784
  }
755
785
 
756
786
  var name = "sapdon";
757
- var version = "3.2.0";
787
+ var version = "3.2.1";
758
788
  var scripts = {
759
789
  build: "node scripts/build.cjs",
760
790
  pub: "npm run build && npm publish"
@@ -1406,13 +1406,13 @@ declare class ContainerUISystem {
1406
1406
  declare const ServerFormSystem: UISystem;
1407
1407
  declare const form_button_panel: Panel;
1408
1408
  declare class ServerUISystem {
1409
- static "__#1053@#binding_map": Map<any, any>;
1410
- static "__#1053@#binding_title_list": any[];
1409
+ static "__#659@#binding_map": Map<any, any>;
1410
+ static "__#659@#binding_title_list": any[];
1411
1411
  static addBindingTitle(title_name: any): void;
1412
1412
  static getBindingTitleList(): any[];
1413
1413
  static getBindingContentList(): any[];
1414
1414
  static bindingTitlewithContent(title_name: any, content: any): void;
1415
- static "__#1053@#updateServerFormSystem"(): void;
1415
+ static "__#659@#updateServerFormSystem"(): void;
1416
1416
  }
1417
1417
 
1418
1418
  declare class Guidebook {
@@ -1621,15 +1621,15 @@ declare class DataBindingObject {
1621
1621
  }
1622
1622
 
1623
1623
  declare class UISystemRegistry {
1624
- static "__#1050@#ui_system_map": {};
1625
- static "__#1050@#ui_def_list": any[];
1624
+ static "__#656@#ui_system_map": {};
1625
+ static "__#656@#ui_def_list": any[];
1626
1626
  static registerUISystem(ui_system: any): void;
1627
1627
  static addOuterUIdefs(ui_defs: any): void;
1628
1628
  static submit(): void;
1629
1629
  }
1630
1630
  declare class UISystemRegistryServer {
1631
- static "__#1051@#ui_system_map": {};
1632
- static "__#1051@#ui_def_list": any[];
1631
+ static "__#657@#ui_system_map": {};
1632
+ static "__#657@#ui_def_list": any[];
1633
1633
  static getUISystemList(): any[];
1634
1634
  static getUIdefList(): any[];
1635
1635
  static startServer(): void;
@@ -2741,4 +2741,5 @@ declare namespace FlipbookTextures {
2741
2741
  function registerFlipbookTexture(atlas_tile: any, texture: any, ticks_per_frame: any, options?: {}): void;
2742
2742
  }
2743
2743
 
2744
- export { BlockAPI, BlockComponent, Button, ButtonMapping$1 as ButtonMapping, ChestUISystem, CollectionPanel, type ConstructorOf, ContainerUISystem, Control, DataBinding, DataBindingObject, type EncodeDecoder, EntityAPI, Factory, FeatureAPI, FlipbookTextures, type FloatLiteral, Grid, GridProp, Guidebook, type ISerializer, Image, Input, ItemAPI, ItemCategory, ItemComponent, ItemTextureManager, Label, Layout, Matrix, Modifications, Panel, type RawType, RecipeAPI, ScrollView, ScrollingPanel, Serializable, Serializer, ServerFormSystem, ServerUISystem, Sound, Sprite, StackPanel, Text, UIElement, UISystem, UISystemRegistry, UISystemRegistryServer, Vec3, Vec4, type Vector3, type Vector4, decode, defaultSerializer, encode, f64, form_button_panel, getMetadata, getOrCreateMetadata, isRawJSON, jsonEncodeDecoder, jsonEncoderReplacer, registry, serialize, terrainTextureManager };
2744
+ export { BlockAPI, BlockComponent, Button, ButtonMapping$1 as ButtonMapping, ChestUISystem, CollectionPanel, ContainerUISystem, Control, DataBinding, DataBindingObject, EntityAPI, Factory, FeatureAPI, FlipbookTextures, Grid, GridProp, Guidebook, Image, Input, ItemAPI, ItemCategory, ItemComponent, ItemTextureManager, Label, Layout, Matrix, Modifications, Panel, RecipeAPI, ScrollView, ScrollingPanel, Serializable, Serializer, ServerFormSystem, ServerUISystem, Sound, Sprite, StackPanel, Text, UIElement, UISystem, UISystemRegistry, UISystemRegistryServer, Vec3, Vec4, decode, defaultSerializer, encode, f64, form_button_panel, getMetadata, getOrCreateMetadata, isRawJSON, jsonEncodeDecoder, jsonEncoderReplacer, registry, serialize, terrainTextureManager };
2745
+ export type { ConstructorOf, EncodeDecoder, FloatLiteral, ISerializer, RawType, Vector3, Vector4 };
@@ -1,6 +1,4 @@
1
- import { serialize as serialize$1 } from '@sapdon/utils/index.js';
2
1
  import http from 'http';
3
- import '@sapdon/cli/remoteLogger/server.js';
4
2
 
5
3
  class BlockComponent {
6
4
  static setTick(interval_range, looping) {
@@ -1498,7 +1496,7 @@ class GRegistry {
1498
1496
  static register(name, root, path, data) {
1499
1497
  data = data === 'string'
1500
1498
  ? JSON.parse(data)
1501
- : serialize$1(data);
1499
+ : serialize(data);
1502
1500
  clientRegistryData.push({ name, root, path, data });
1503
1501
  }
1504
1502
  static submit() {
@@ -139,4 +139,5 @@ declare class PlayerInputCompatibilityComponent extends BaseComponent {
139
139
  onTick(manager: ComponentManager, en: Optional<Entity>): void;
140
140
  }
141
141
 
142
- export { Actor, BaseComponent, type BasicComponent, type Component, type ComponentCtor, type ComponentDescriptor, ComponentManager, CustomComponent, InputChangeState, Optional, PlayerInputCompatibilityComponent, PlayerInputComponent, RequireComponents, type RequiredComponent, oc };
142
+ export { Actor, BaseComponent, ComponentManager, CustomComponent, InputChangeState, Optional, PlayerInputCompatibilityComponent, PlayerInputComponent, RequireComponents, oc };
143
+ export type { BasicComponent, Component, ComponentCtor, ComponentDescriptor, RequiredComponent };
@@ -38,4 +38,5 @@ declare const f64: (literal: FloatLiteral) => {
38
38
  };
39
39
  declare function isRawJSON(v: any): boolean;
40
40
 
41
- export { type ConstructorOf, type EncodeDecoder, type FloatLiteral, type ISerializer, type RawType, Serializable, Serializer, decode, defaultSerializer, encode, f64, getMetadata, getOrCreateMetadata, isRawJSON, jsonEncodeDecoder, jsonEncoderReplacer, serialize };
41
+ export { Serializable, Serializer, decode, defaultSerializer, encode, f64, getMetadata, getOrCreateMetadata, isRawJSON, jsonEncodeDecoder, jsonEncoderReplacer, serialize };
42
+ export type { ConstructorOf, EncodeDecoder, FloatLiteral, ISerializer, RawType };