@casual-simulation/aux-common 3.0.10 → 3.0.13-alpha.2430479070

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.
Files changed (47) hide show
  1. package/aux-format-2/AuxCausalTree2.js +40 -5
  2. package/aux-format-2/AuxCausalTree2.js.map +1 -1
  3. package/bots/Bot.d.ts +8 -0
  4. package/bots/Bot.js +10 -0
  5. package/bots/Bot.js.map +1 -1
  6. package/bots/BotCalculations.d.ts +47 -7
  7. package/bots/BotCalculations.js +172 -15
  8. package/bots/BotCalculations.js.map +1 -1
  9. package/bots/test/BotCalculationContextTests.js +58 -6
  10. package/bots/test/BotCalculationContextTests.js.map +1 -1
  11. package/bots/test/BotTestHelpers.d.ts +4 -0
  12. package/bots/test/BotTestHelpers.js +67 -0
  13. package/bots/test/BotTestHelpers.js.map +1 -1
  14. package/math/Quaternion.d.ts +94 -0
  15. package/math/Quaternion.js +128 -0
  16. package/math/Quaternion.js.map +1 -0
  17. package/math/Rotation.d.ts +274 -0
  18. package/math/Rotation.js +378 -0
  19. package/math/Rotation.js.map +1 -0
  20. package/math/Vector2.d.ts +251 -0
  21. package/math/Vector2.js +287 -0
  22. package/math/Vector2.js.map +1 -0
  23. package/math/Vector3.d.ts +318 -0
  24. package/math/Vector3.js +370 -0
  25. package/math/Vector3.js.map +1 -0
  26. package/math/index.d.ts +5 -0
  27. package/math/index.js +5 -0
  28. package/math/index.js.map +1 -0
  29. package/package.json +4 -4
  30. package/partitions/MemoryPartition.js +23 -4
  31. package/partitions/MemoryPartition.js.map +1 -1
  32. package/partitions/RemoteYjsPartition.d.ts +2 -0
  33. package/partitions/RemoteYjsPartition.js +11 -4
  34. package/partitions/RemoteYjsPartition.js.map +1 -1
  35. package/partitions/YjsPartition.js +8 -0
  36. package/partitions/YjsPartition.js.map +1 -1
  37. package/runtime/AuxLibrary.d.ts +17 -40
  38. package/runtime/AuxLibrary.js +183 -68
  39. package/runtime/AuxLibrary.js.map +1 -1
  40. package/runtime/AuxLibraryDefinitions.def +587 -10
  41. package/runtime/AuxRuntime.js +26 -1
  42. package/runtime/AuxRuntime.js.map +1 -1
  43. package/runtime/Utils.js +12 -4
  44. package/runtime/Utils.js.map +1 -1
  45. package/partitions/test/PartitionTests.d.ts +0 -8
  46. package/partitions/test/PartitionTests.js +0 -1548
  47. package/partitions/test/PartitionTests.js.map +0 -1
@@ -11,7 +11,7 @@ import { DEBUG_STRING, debugStringifyFunction, } from './AuxGlobalContext';
11
11
  import { hasValue, trimTag, isBot, BOT_SPACE_TAG, toast as toastMessage, tip as tipMessage, hideTips as hideTipMessages, showJoinCode as calcShowJoinCode, requestFullscreen, exitFullscreen, html as htmlMessage, hideHtml as hideHtmlMessage, setClipboard as calcSetClipboard, tweenTo as calcTweenTo, showChat as calcShowChat, hideChat as calcHideChat, runScript, getMediaPermission as calcGetMediaPermission, getAverageFrameRate as calcGetAverageFrameRate, enableAR as calcEnableAR, disableAR as calcDisableAR, enableVR as calcEnableVR, disableVR as calcDisableVR, arSupported as calcARSupported, vrSupported as calcVRSupported, showUploadAuxFile as calcShowUploadAuxFile, openQRCodeScanner as calcOpenQRCodeScanner, showQRCode as calcShowQRCode, openBarcodeScanner as calcOpenBarcodeScanner, showBarcode as calcShowBarcode, importAUX as calcImportAUX, showInputForTag as calcShowInputForTag, showInput as calcShowInput, replaceDragBot as calcReplaceDragBot, goToDimension as calcGoToDimension, goToURL as calcGoToURL, openURL as calcOpenURL, checkout as calcCheckout, playSound as calcPlaySound, bufferSound as calcBufferSound, cancelSound as calcCancelSound, setupServer as calcSetupServer, shell as calcShell, backupToGithub as calcBackupToGithub, backupAsDownload as calcBackupAsDownload, finishCheckout as calcFinishCheckout, markHistory as calcMarkHistory, browseHistory as calcBrowseHistory, restoreHistoryMark as calcRestoreHistoryMark, loadFile as calcLoadFile, saveFile as calcSaveFile, reject as calcReject, localFormAnimation as calcLocalFormAnimation, webhook as calcWebhook, superShout as calcSuperShout, share as calcShare, registerPrefix as calcRegisterPrefix, createCertificate as calcCreateCertificate, signTag as calcSignTag, revokeCertificate as calcRevokeCertificate, localPositionTween as calcLocalPositionTween, localRotationTween as calcLocalRotationTween, showUploadFiles as calcShowUploadFiles, download, loadSimulation, unloadSimulation, getUploadState, addState, getPortalTag, KNOWN_PORTALS, openConsole, tagsOnBot, getOriginalObject, getBotSpace, trimEvent, CREATE_ACTION_NAME, CREATE_ANY_ACTION_NAME, DESTROY_ACTION_NAME, ORIGINAL_OBJECT, unlockSpace, getRemoteCount, getServers, getRemotes, action, getServerStatuses, setSpacePassword, rpioInitPin, rpioExitPin, rpioOpenPin, rpioModePin, rpioReadPin, rpioReadSequencePin, rpioWritePin, rpioWriteSequencePin, rpioReadpadPin, rpioWritepadPin, rpioPudPin, rpioPollPin, rpioClosePin, rpioI2CBeginPin, rpioI2CSetSlaveAddressPin, rpioI2CSetBaudRatePin, rpioI2CSetClockDividerPin, rpioI2CReadPin, rpioI2CWritePin,
12
12
  // rpioI2CReadRegisterRestartPin,
13
13
  // rpioI2CWriteReadRestartPin,
14
- rpioI2CEndPin, rpioPWMSetClockDividerPin, rpioPWMSetRangePin, rpioPWMSetDataPin, rpioSPIBeginPin, rpioSPIChipSelectPin, rpioSPISetCSPolarityPin, rpioSPISetClockDividerPin, rpioSPISetDataModePin, rpioSPITransferPin, rpioSPIWritePin, rpioSPIEndPin, serialConnectPin, serialOpenPin, serialStreamPin, serialUpdatePin, serialWritePin, serialReadPin, serialClosePin, serialFlushPin, serialDrainPin, serialPausePin, serialResumePin, calculateAnchorPoint, calculateAnchorPointOffset, getBotPosition as calcGetBotPosition, isRuntimeBot, SET_TAG_MASK_SYMBOL, CLEAR_TAG_MASKS_SYMBOL, getBotScale, EDIT_TAG_SYMBOL, EDIT_TAG_MASK_SYMBOL, circleWipe, addDropSnap as calcAddDropSnap, addDropGrid as calcAddDropGrid, animateToPosition, beginAudioRecording as calcBeginAudioRecording, endAudioRecording as calcEndAudioRecording, beginRecording as calcBeginRecording, endRecording as calcEndRecording, speakText as calcSpeakText, getVoices as calcGetVoices, getGeolocation as calcGetGeolocation, cancelAnimation, disablePOV, enablePOV, enableCustomDragging as calcEnableCustomDragging, MINI_PORTAL, registerCustomApp, setAppOutput, unregisterCustomApp, requestAuthData as calcRequestAuthData, createBot, defineGlobalBot as calcDefineGlobalBot, TEMPORARY_BOT_PARTITION_ID, convertToString, GET_TAG_MASKS_SYMBOL, isBotLink, parseBotLink, createBotLink, convertGeolocationToWhat3Words as calcConvertGeolocationToWhat3Words, getPublicRecordKey as calcGetPublicRecordKey, recordData as calcRecordData, getRecordData, eraseRecordData, recordFile as calcRecordFile, eraseFile as calcEraseFile, meetCommand as calcMeetCommand, meetFunction as calcMeetFunction, listDataRecord, recordEvent as calcRecordEvent, getEventCount as calcGetEventCount, openImageClassifier as calcOpenImageClassifier, isBotDate, DATE_TAG_PREFIX, parseBotDate, } from '../bots';
14
+ rpioI2CEndPin, rpioPWMSetClockDividerPin, rpioPWMSetRangePin, rpioPWMSetDataPin, rpioSPIBeginPin, rpioSPIChipSelectPin, rpioSPISetCSPolarityPin, rpioSPISetClockDividerPin, rpioSPISetDataModePin, rpioSPITransferPin, rpioSPIWritePin, rpioSPIEndPin, serialConnectPin, serialOpenPin, serialStreamPin, serialUpdatePin, serialWritePin, serialReadPin, serialClosePin, serialFlushPin, serialDrainPin, serialPausePin, serialResumePin, calculateAnchorPoint, calculateAnchorPointOffset, getBotPosition as calcGetBotPosition, getBotRotation as calcGetBotRotation, isRuntimeBot, SET_TAG_MASK_SYMBOL, CLEAR_TAG_MASKS_SYMBOL, getBotScale, EDIT_TAG_SYMBOL, EDIT_TAG_MASK_SYMBOL, circleWipe, addDropSnap as calcAddDropSnap, addDropGrid as calcAddDropGrid, animateToPosition, beginAudioRecording as calcBeginAudioRecording, endAudioRecording as calcEndAudioRecording, beginRecording as calcBeginRecording, endRecording as calcEndRecording, speakText as calcSpeakText, getVoices as calcGetVoices, getGeolocation as calcGetGeolocation, cancelAnimation, disablePOV, enablePOV, enableCustomDragging as calcEnableCustomDragging, MINI_PORTAL, registerCustomApp, setAppOutput, unregisterCustomApp, requestAuthData as calcRequestAuthData, createBot, defineGlobalBot as calcDefineGlobalBot, TEMPORARY_BOT_PARTITION_ID, convertToString, GET_TAG_MASKS_SYMBOL, isBotLink, parseBotLink, createBotLink, convertGeolocationToWhat3Words as calcConvertGeolocationToWhat3Words, getPublicRecordKey as calcGetPublicRecordKey, recordData as calcRecordData, getRecordData, eraseRecordData, recordFile as calcRecordFile, eraseFile as calcEraseFile, meetCommand as calcMeetCommand, meetFunction as calcMeetFunction, listDataRecord, recordEvent as calcRecordEvent, getEventCount as calcGetEventCount, openImageClassifier as calcOpenImageClassifier, isBotDate, DATE_TAG_PREFIX, parseBotDate, realNumberOrDefault, } from '../bots';
15
15
  import { sortBy, every, cloneDeep, union, isEqual, flatMap } from 'lodash';
16
16
  import { remote as calcRemote, } from '@casual-simulation/causal-trees';
17
17
  import { RanOutOfEnergyError } from './AuxResults';
@@ -23,11 +23,12 @@ import stableStringify from '@casual-simulation/fast-json-stable-stringify';
23
23
  import { encrypt as realEncrypt, decrypt as realDecrypt, keypair as realKeypair, sign as realSign, verify as realVerify, asymmetricKeypair as realAsymmetricKeypair, asymmetricEncrypt as realAsymmetricEncrypt, asymmetricDecrypt as realAsymmetricDecrypt, isAsymmetricKeypair, isAsymmetricEncrypted, isEncrypted, } from '@casual-simulation/crypto';
24
24
  import { tagValueHash } from '../aux-format-2/AuxOpTypes';
25
25
  import { apply, del, insert, isTagEdit, preserve } from '../aux-format-2';
26
- import { Euler, Vector3, Plane, Ray, } from '@casual-simulation/three';
26
+ import { Vector3 as ThreeVector3, Plane, Ray, } from '@casual-simulation/three';
27
27
  import mime from 'mime';
28
28
  import TWEEN from '@tweenjs/tween.js';
29
29
  import './PerformanceNowPolyfill';
30
30
  import './BlobPolyfill';
31
+ import { Vector3, Vector2, Quaternion, Rotation } from '../math';
31
32
  import { Fragment, h } from 'preact';
32
33
  import htm from 'htm';
33
34
  import { fromByteArray, toByteArray } from 'base64-js';
@@ -123,6 +124,8 @@ function getBotSnapshot(bot) {
123
124
  return b;
124
125
  }
125
126
  const DEAD_RECKONING_OFFSET = 50;
127
+ const DEG_TO_RAD = Math.PI / 180;
128
+ const RAD_TO_DEG = 180 / Math.PI;
126
129
  /**
127
130
  * Creates a library that includes the default functions and APIs.
128
131
  * @param context The global context that should be used.
@@ -149,6 +152,7 @@ export function createDefaultLibrary(context) {
149
152
  getBotTagValues,
150
153
  getMod,
151
154
  getBotPosition,
155
+ getBotRotation,
152
156
  getID,
153
157
  getJSON,
154
158
  getFormattedJSON,
@@ -174,6 +178,10 @@ export function createDefaultLibrary(context) {
174
178
  updateBotLinks,
175
179
  getDateTime,
176
180
  DateTime,
181
+ Vector2,
182
+ Vector3,
183
+ Quaternion,
184
+ Rotation,
177
185
  superShout,
178
186
  priorityShout,
179
187
  shout: shoutProxy,
@@ -476,6 +484,8 @@ export function createDefaultLibrary(context) {
476
484
  setRandomSeed,
477
485
  randomInt,
478
486
  random,
487
+ degreesToRadians,
488
+ radiansToDegrees,
479
489
  getForwardDirection,
480
490
  intersectPlane,
481
491
  getAnchorPointOffset,
@@ -796,7 +806,23 @@ export function createDefaultLibrary(context) {
796
806
  if (!finalBot) {
797
807
  throw new Error(`Could not find the bot with the given ID (${bot}).`);
798
808
  }
799
- return calcGetBotPosition(null, finalBot, dimension);
809
+ const position = calcGetBotPosition(null, finalBot, dimension);
810
+ return new Vector3(position.x, position.y, position.z);
811
+ }
812
+ /**
813
+ * Gets the rotation that the given bot is at in the given dimension.
814
+ * @param bot The bot or bot ID.
815
+ * @param dimension The dimension that the bot's rotation should be retrieved for.
816
+ */
817
+ function getBotRotation(bot, dimension) {
818
+ if (!bot) {
819
+ throw new Error('The given bot must not be null.');
820
+ }
821
+ const finalBot = typeof bot === 'string' ? context.state[bot] : bot;
822
+ if (!finalBot) {
823
+ throw new Error(`Could not find the bot with the given ID (${bot}).`);
824
+ }
825
+ return calcGetBotRotation(null, finalBot, dimension);
800
826
  }
801
827
  /**
802
828
  * Creates a filter function that checks whether bots have the given tag and value.
@@ -3366,28 +3392,70 @@ export function createDefaultLibrary(context) {
3366
3392
  throw new Error('You must provide a duration.');
3367
3393
  }
3368
3394
  return new Promise((resolve, reject) => {
3369
- let valueHolder = {
3370
- [tag]: hasValue(options.fromValue)
3371
- ? options.fromValue
3372
- : bot.tags[tag],
3373
- };
3395
+ let initialValue = hasValue(options.fromValue)
3396
+ ? options.fromValue
3397
+ : bot.tags[tag];
3374
3398
  const easing = getEasing(options.easing);
3375
3399
  const startTime = hasValue(options.startTime)
3376
3400
  ? options.startTime - context.startTime
3377
3401
  : context.localTime;
3402
+ let targetValue = options.toValue;
3403
+ let getValue = (elapsed) => {
3404
+ return valueHolder[tag];
3405
+ };
3406
+ if (targetValue instanceof Vector3) {
3407
+ const startValue = new Vector3(realNumberOrDefault(initialValue.x, 0), realNumberOrDefault(initialValue.y, 0), realNumberOrDefault(initialValue.z, 0));
3408
+ initialValue = {
3409
+ x: startValue.x,
3410
+ y: startValue.y,
3411
+ z: startValue.z,
3412
+ };
3413
+ getValue = (elapsed) => {
3414
+ return Vector3.interpolatePosition(startValue, targetValue, easing(elapsed));
3415
+ };
3416
+ }
3417
+ else if (targetValue instanceof Vector2) {
3418
+ const startValue = new Vector2(realNumberOrDefault(initialValue.x, 0), realNumberOrDefault(initialValue.y, 0));
3419
+ initialValue = {
3420
+ x: startValue.x,
3421
+ y: startValue.y,
3422
+ };
3423
+ getValue = (elapsed) => {
3424
+ return Vector2.interpolatePosition(startValue, targetValue, easing(elapsed));
3425
+ };
3426
+ }
3427
+ else if (targetValue instanceof Rotation) {
3428
+ const startValue = initialValue instanceof Rotation
3429
+ ? initialValue
3430
+ : initialValue instanceof Quaternion
3431
+ ? new Rotation(initialValue)
3432
+ : new Rotation();
3433
+ initialValue = {
3434
+ x: startValue.quaternion.x,
3435
+ y: startValue.quaternion.y,
3436
+ z: startValue.quaternion.z,
3437
+ w: startValue.quaternion.w,
3438
+ };
3439
+ getValue = (elapsed) => {
3440
+ return Rotation.interpolate(startValue, targetValue, easing(elapsed));
3441
+ };
3442
+ }
3443
+ let valueHolder = {
3444
+ [tag]: initialValue,
3445
+ };
3378
3446
  const tween = new TWEEN.Tween(valueHolder)
3379
3447
  .to({
3380
- [tag]: options.toValue,
3448
+ [tag]: targetValue,
3381
3449
  })
3382
3450
  .duration(options.duration * 1000)
3383
3451
  .easing(easing)
3384
- .onUpdate(() => {
3452
+ .onUpdate((obj, elapsed) => {
3385
3453
  if (options.tagMaskSpace === false ||
3386
3454
  options.tagMaskSpace === getBotSpace(bot)) {
3387
- setTag(bot, tag, valueHolder[tag]);
3455
+ setTag(bot, tag, getValue(elapsed));
3388
3456
  }
3389
3457
  else {
3390
- setTagMask(bot, tag, valueHolder[tag], options.tagMaskSpace || 'tempLocal');
3458
+ setTagMask(bot, tag, getValue(elapsed), options.tagMaskSpace || 'tempLocal');
3391
3459
  }
3392
3460
  })
3393
3461
  .onComplete(() => {
@@ -3828,19 +3896,40 @@ export function createDefaultLibrary(context) {
3828
3896
  }
3829
3897
  return Math.random();
3830
3898
  }
3899
+ /**
3900
+ * Converts the given number of degrees to radians and returns the result.
3901
+ * @param degrees The number of degrees.
3902
+ */
3903
+ function degreesToRadians(degrees) {
3904
+ return degrees * DEG_TO_RAD;
3905
+ }
3906
+ /**
3907
+ * Converts the given number of radians to degrees and returns the result.
3908
+ * @param radians The number of radians.
3909
+ */
3910
+ function radiansToDegrees(radians) {
3911
+ return radians * RAD_TO_DEG;
3912
+ }
3831
3913
  /**
3832
3914
  * Gets the forward direction for the given rotation.
3833
3915
  * @param pointerRotation The rotation that the pointer has represented in radians.
3834
3916
  */
3835
3917
  function getForwardDirection(pointerRotation) {
3836
- let euler = new Euler(pointerRotation.x, pointerRotation.z, pointerRotation.y, 'XYZ');
3837
- let direction = new Vector3(0, 0, -1);
3838
- direction.applyEuler(euler);
3839
- return {
3840
- x: direction.x,
3841
- y: -direction.z,
3842
- z: direction.y,
3843
- };
3918
+ const rotation = pointerRotation instanceof Rotation
3919
+ ? pointerRotation
3920
+ : 'w' in pointerRotation
3921
+ ? new Rotation({
3922
+ quaternion: new Quaternion(pointerRotation.x, pointerRotation.y, pointerRotation.z, pointerRotation.w),
3923
+ })
3924
+ : new Rotation({
3925
+ euler: {
3926
+ x: pointerRotation.x,
3927
+ y: pointerRotation.y,
3928
+ z: pointerRotation.z,
3929
+ },
3930
+ });
3931
+ const direction = new Vector3(0, 1, 0);
3932
+ return rotation.rotateVector3(direction);
3844
3933
  }
3845
3934
  /**
3846
3935
  * Finds the point at which the the given ray and ground plane intersect.
@@ -3848,16 +3937,12 @@ export function createDefaultLibrary(context) {
3848
3937
  * @param direction The direction that the ray is pointing.
3849
3938
  */
3850
3939
  function intersectPlane(origin, direction) {
3851
- let plane = new Plane(new Vector3(0, 0, 1));
3852
- let final = new Vector3();
3853
- let ray = new Ray(new Vector3(origin.x, origin.y, origin.z), new Vector3(direction.x, direction.y, direction.z));
3940
+ let plane = new Plane(new ThreeVector3(0, 0, 1));
3941
+ let final = new ThreeVector3();
3942
+ let ray = new Ray(new ThreeVector3(origin.x, origin.y, origin.z), new ThreeVector3(direction.x, direction.y, direction.z));
3854
3943
  let result = ray.intersectPlane(plane, final);
3855
3944
  if (result) {
3856
- return {
3857
- x: result.x,
3858
- y: result.y,
3859
- z: result.z,
3860
- };
3945
+ return new Vector3(result.x, result.y, result.z);
3861
3946
  }
3862
3947
  else {
3863
3948
  return null;
@@ -3870,11 +3955,7 @@ export function createDefaultLibrary(context) {
3870
3955
  function getAnchorPointOffset(anchorPoint) {
3871
3956
  const value = calculateAnchorPoint(anchorPoint);
3872
3957
  const offset = calculateAnchorPointOffset(value);
3873
- return {
3874
- x: offset.x,
3875
- y: -offset.y,
3876
- z: offset.z,
3877
- };
3958
+ return new Vector3(offset.x, -offset.y, offset.z);
3878
3959
  }
3879
3960
  /**
3880
3961
  * Adds the given vectors together and returns the result.
@@ -3884,6 +3965,10 @@ export function createDefaultLibrary(context) {
3884
3965
  if (vectors.length <= 0) {
3885
3966
  return {};
3886
3967
  }
3968
+ let hasX = false;
3969
+ let hasY = false;
3970
+ let hasZ = false;
3971
+ let hasOther = false;
3887
3972
  let result = {};
3888
3973
  for (let i = 0; i < vectors.length; i++) {
3889
3974
  const v = vectors[i];
@@ -3892,6 +3977,18 @@ export function createDefaultLibrary(context) {
3892
3977
  }
3893
3978
  const keys = Object.keys(v);
3894
3979
  for (let key of keys) {
3980
+ if (key === 'x') {
3981
+ hasX = true;
3982
+ }
3983
+ else if (key === 'y') {
3984
+ hasY = true;
3985
+ }
3986
+ else if (key === 'z') {
3987
+ hasZ = true;
3988
+ }
3989
+ else {
3990
+ hasOther = true;
3991
+ }
3895
3992
  if (key in result) {
3896
3993
  result[key] += v[key];
3897
3994
  }
@@ -3900,6 +3997,12 @@ export function createDefaultLibrary(context) {
3900
3997
  }
3901
3998
  }
3902
3999
  }
4000
+ if (hasX && hasY && !hasZ && !hasOther) {
4001
+ return new Vector2(result.x, result.y);
4002
+ }
4003
+ else if (hasX && hasY && hasZ && !hasOther) {
4004
+ return new Vector3(result.x, result.y, result.z);
4005
+ }
3903
4006
  return result;
3904
4007
  }
3905
4008
  /**
@@ -3910,6 +4013,10 @@ export function createDefaultLibrary(context) {
3910
4013
  if (vectors.length <= 0) {
3911
4014
  return {};
3912
4015
  }
4016
+ let hasX = false;
4017
+ let hasY = false;
4018
+ let hasZ = false;
4019
+ let hasOther = false;
3913
4020
  let result = {};
3914
4021
  for (let i = 0; i < vectors.length; i++) {
3915
4022
  const v = vectors[i];
@@ -3918,6 +4025,18 @@ export function createDefaultLibrary(context) {
3918
4025
  }
3919
4026
  const keys = Object.keys(v);
3920
4027
  for (let key of keys) {
4028
+ if (key === 'x') {
4029
+ hasX = true;
4030
+ }
4031
+ else if (key === 'y') {
4032
+ hasY = true;
4033
+ }
4034
+ else if (key === 'z') {
4035
+ hasZ = true;
4036
+ }
4037
+ else {
4038
+ hasOther = true;
4039
+ }
3921
4040
  if (key in result) {
3922
4041
  result[key] -= v[key];
3923
4042
  }
@@ -3926,6 +4045,12 @@ export function createDefaultLibrary(context) {
3926
4045
  }
3927
4046
  }
3928
4047
  }
4048
+ if (hasX && hasY && !hasZ && !hasOther) {
4049
+ return new Vector2(result.x, result.y);
4050
+ }
4051
+ else if (hasX && hasY && hasZ && !hasOther) {
4052
+ return new Vector3(result.x, result.y, result.z);
4053
+ }
3929
4054
  return result;
3930
4055
  }
3931
4056
  /**
@@ -3936,6 +4061,12 @@ export function createDefaultLibrary(context) {
3936
4061
  if (!hasValue(vector)) {
3937
4062
  return vector;
3938
4063
  }
4064
+ if (vector instanceof Vector2) {
4065
+ return vector.negate();
4066
+ }
4067
+ else if (vector instanceof Vector3) {
4068
+ return vector.negate();
4069
+ }
3939
4070
  let result = {};
3940
4071
  const keys = Object.keys(vector);
3941
4072
  for (let key of keys) {
@@ -3951,6 +4082,12 @@ export function createDefaultLibrary(context) {
3951
4082
  if (!hasValue(vector)) {
3952
4083
  return vector;
3953
4084
  }
4085
+ if (vector instanceof Vector2) {
4086
+ return vector.normalize();
4087
+ }
4088
+ else if (vector instanceof Vector3) {
4089
+ return vector.normalize();
4090
+ }
3954
4091
  let result = {};
3955
4092
  const length = vectorLength(vector);
3956
4093
  if (length === 0) {
@@ -3988,6 +4125,12 @@ export function createDefaultLibrary(context) {
3988
4125
  if (!hasValue(vector)) {
3989
4126
  return vector;
3990
4127
  }
4128
+ if (vector instanceof Vector2) {
4129
+ return vector.multiplyScalar(scale);
4130
+ }
4131
+ else if (vector instanceof Vector3) {
4132
+ return vector.multiplyScalar(scale);
4133
+ }
3991
4134
  let result = {};
3992
4135
  const keys = Object.keys(vector);
3993
4136
  for (let key of keys) {
@@ -5113,17 +5256,9 @@ export function createDefaultLibrary(context) {
5113
5256
  function getCameraPosition(portal = 'grid') {
5114
5257
  const bot = context.global[`${portal}PortalBot`];
5115
5258
  if (!bot) {
5116
- return {
5117
- x: NaN,
5118
- y: NaN,
5119
- z: NaN,
5120
- };
5259
+ return new Vector3(NaN, NaN, NaN);
5121
5260
  }
5122
- return {
5123
- x: bot.tags[`cameraPositionX`],
5124
- y: bot.tags[`cameraPositionY`],
5125
- z: bot.tags[`cameraPositionZ`],
5126
- };
5261
+ return new Vector3(bot.tags[`cameraPositionX`], bot.tags[`cameraPositionY`], bot.tags[`cameraPositionZ`]);
5127
5262
  }
5128
5263
  /**
5129
5264
  * Gets the 3D rotation of the player's camera.
@@ -5151,17 +5286,9 @@ export function createDefaultLibrary(context) {
5151
5286
  function getFocusPoint(portal = 'grid') {
5152
5287
  const bot = context.global[`${portal}PortalBot`];
5153
5288
  if (!bot) {
5154
- return {
5155
- x: NaN,
5156
- y: NaN,
5157
- z: NaN,
5158
- };
5289
+ return new Vector3(NaN, NaN, NaN);
5159
5290
  }
5160
- return {
5161
- x: bot.tags[`cameraFocusX`],
5162
- y: bot.tags[`cameraFocusY`],
5163
- z: bot.tags[`cameraFocusZ`],
5164
- };
5291
+ return new Vector3(bot.tags[`cameraFocusX`], bot.tags[`cameraFocusY`], bot.tags[`cameraFocusZ`]);
5165
5292
  }
5166
5293
  /**
5167
5294
  * Gets the 3D position of the player's pointer.
@@ -5170,17 +5297,9 @@ export function createDefaultLibrary(context) {
5170
5297
  function getPointerPosition(pointer = 'mouse') {
5171
5298
  const user = context.playerBot;
5172
5299
  if (!user) {
5173
- return {
5174
- x: NaN,
5175
- y: NaN,
5176
- z: NaN,
5177
- };
5300
+ return new Vector3(NaN, NaN, NaN);
5178
5301
  }
5179
- return {
5180
- x: user.tags[`${pointer}PointerPositionX`],
5181
- y: user.tags[`${pointer}PointerPositionY`],
5182
- z: user.tags[`${pointer}PointerPositionZ`],
5183
- };
5302
+ return new Vector3(user.tags[`${pointer}PointerPositionX`], user.tags[`${pointer}PointerPositionY`], user.tags[`${pointer}PointerPositionZ`]);
5184
5303
  }
5185
5304
  /**
5186
5305
  * Gets the 3D rotation of the player's pointer.
@@ -5208,11 +5327,7 @@ export function createDefaultLibrary(context) {
5208
5327
  function getPointerDirection(pointer = 'mouse') {
5209
5328
  const rotation = getPointerRotation(pointer);
5210
5329
  if (isNaN(rotation.x) || isNaN(rotation.y) || isNaN(rotation.z)) {
5211
- return {
5212
- x: NaN,
5213
- y: NaN,
5214
- z: NaN,
5215
- };
5330
+ return new Vector3(NaN, NaN, NaN);
5216
5331
  }
5217
5332
  return getForwardDirection(rotation);
5218
5333
  }