screeps-timeseries 0.0.7 → 0.0.9

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.
@@ -83,4 +83,5 @@
83
83
  "test/setup-mocha.js"
84
84
  ],
85
85
  "search.useIgnoreFiles": false,
86
+ "js/ts.tsdk.path": "./node_modules/typescript/lib",
86
87
  }
package/dist/index.js CHANGED
@@ -3568,12 +3568,15 @@ class TimeSeriesDataEngine {
3568
3568
  const nodeList = getDataNodeList(dataInThisTick);
3569
3569
  const mutationSize = this.opts.mutationSize;
3570
3570
  Object.entries(nodeList).forEach(([key, value]) => {
3571
- var _a, _b, _c;
3571
+ var _a, _b, _c, _d;
3572
3572
  const nullValue = POWERS_OF_2[value.depth] - 1;
3573
- // 更新exp数据
3573
+ // 更新exp数据和signed数据
3574
3574
  if (seriesDataNodeList[key] && (value === null || value === void 0 ? void 0 : value.exp) !== ((_a = seriesDataNodeList[key]) === null || _a === void 0 ? void 0 : _a.exp)) {
3575
3575
  seriesDataNodeList[key].exp = value === null || value === void 0 ? void 0 : value.exp;
3576
3576
  }
3577
+ if (seriesDataNodeList[key] && (value === null || value === void 0 ? void 0 : value.signed) !== ((_b = seriesDataNodeList[key]) === null || _b === void 0 ? void 0 : _b.signed)) {
3578
+ seriesDataNodeList[key].signed = value === null || value === void 0 ? void 0 : value.signed;
3579
+ }
3577
3580
  if (seriesDataNodeList[key] && value.depth !== seriesDataNodeList[key].depth) {
3578
3581
  // 深度改变了。需要对本segment内的该条数据做处理保证兼容。
3579
3582
  const newDepth = value.depth;
@@ -3598,17 +3601,32 @@ class TimeSeriesDataEngine {
3598
3601
  if (isNull(value.data) || isNaN(value.data) || isUndefined(value.data)) {
3599
3602
  valueToStore = nullValue;
3600
3603
  }
3601
- if (value.data >= nullValue) {
3602
- valueToStore = nullValue - 1;
3604
+ else if (value.signed) {
3605
+ const signedOffset = POWERS_OF_2[value.depth - 1];
3606
+ const signedMax = signedOffset - 2;
3607
+ if (value.data > signedMax) {
3608
+ valueToStore = nullValue - 1;
3609
+ }
3610
+ else if (value.data < -signedOffset) {
3611
+ valueToStore = 0;
3612
+ }
3613
+ else {
3614
+ valueToStore = value.data + signedOffset;
3615
+ }
3603
3616
  }
3604
- if (value.data < 0) {
3605
- valueToStore = 0;
3617
+ else {
3618
+ if (value.data >= nullValue) {
3619
+ valueToStore = nullValue - 1;
3620
+ }
3621
+ if (value.data < 0) {
3622
+ valueToStore = 0;
3623
+ }
3606
3624
  }
3607
3625
  if (seriesDataNodeList[key]) {
3608
3626
  const { depth, data } = seriesDataNodeList[key];
3609
3627
  const codec = new UTF15({ depth, array: true, meta: true });
3610
3628
  const numberList = codec.decode(data);
3611
- if (((_c = (_b = seriesDataNodeList[key].mutations) === null || _b === void 0 ? void 0 : _b[seriesDataNodeList[key].mutations.length - 1]) === null || _c === void 0 ? void 0 : _c[0]) ===
3629
+ if (((_d = (_c = seriesDataNodeList[key].mutations) === null || _c === void 0 ? void 0 : _c[seriesDataNodeList[key].mutations.length - 1]) === null || _d === void 0 ? void 0 : _d[0]) ===
3612
3630
  numberList.length - 1 &&
3613
3631
  numberList[numberList.length - 1] === valueToStore) {
3614
3632
  seriesDataNodeList[key].mutations[seriesDataNodeList[key].mutations.length - 1][1]++;
@@ -3640,8 +3658,8 @@ class TimeSeriesDataEngine {
3640
3658
  seriesDataNodeList[key].data = codec.encode(numberList);
3641
3659
  }
3642
3660
  else {
3643
- const { depth, type, exp } = value;
3644
- seriesDataNodeList[key] = { depth, data: "", type, exp };
3661
+ const { depth, type, exp, signed } = value;
3662
+ seriesDataNodeList[key] = { depth, data: "", type, exp, signed };
3645
3663
  const newSeriesDataNode = seriesDataNodeList[key];
3646
3664
  const codec = new UTF15({ depth, array: true, meta: true });
3647
3665
  if (storeNum !== 0) {
@@ -3758,8 +3776,16 @@ class TimeSeriesDataEngine {
3758
3776
  // console.log(key);
3759
3777
  const { depth } = value;
3760
3778
  const codec = new UTF15({ depth, array: true, meta: true });
3761
- let data = codec.decode(value.data);
3762
- data = data.map(i => (i === POWERS_OF_2[depth] - 1 ? null : i));
3779
+ const decoded = codec.decode(value.data);
3780
+ const nullValue = POWERS_OF_2[depth] - 1;
3781
+ let data;
3782
+ if (value.signed) {
3783
+ const signedOffset = POWERS_OF_2[depth - 1];
3784
+ data = decoded.map(i => (i === nullValue ? null : i - signedOffset));
3785
+ }
3786
+ else {
3787
+ data = decoded.map(i => (i === nullValue ? null : i));
3788
+ }
3763
3789
  // read mutations and insert extra data
3764
3790
  const mutations = value.mutations;
3765
3791
  if (mutations) {
@@ -3789,7 +3815,7 @@ class TimeSeriesDataEngine {
3789
3815
  }
3790
3816
  // push data
3791
3817
  if (!this.seriesDataNodeListReadCache[key]) {
3792
- this.seriesDataNodeListReadCache[key] = Object.assign(Object.assign({}, value), { data: [] });
3818
+ this.seriesDataNodeListReadCache[key] = Object.assign(Object.assign({}, value), { data: new Array(this.storeNumReadCache).fill(null) });
3793
3819
  }
3794
3820
  if (this.seriesDataNodeListReadCache[key].mutations) {
3795
3821
  delete this.seriesDataNodeListReadCache[key].mutations;
@@ -3803,7 +3829,7 @@ class TimeSeriesDataEngine {
3803
3829
  });
3804
3830
  this.storeNumReadCache += seriesDataHere.storeNum;
3805
3831
  Object.entries(this.seriesDataNodeListReadCache).forEach(([key, value]) => {
3806
- // 将不存在的数据补全为null
3832
+ // 将该份cache不存在的数据补全为null
3807
3833
  const { data } = value;
3808
3834
  // console.log(`${dataId}, ${key}:${data.length}, ${data}`);
3809
3835
  if (data.length < this.storeNumReadCache) {