@casual-simulation/aux-common 3.0.0 → 3.0.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/bots/Bot.d.ts +13 -1
- package/bots/Bot.js +17 -0
- package/bots/Bot.js.map +1 -1
- package/bots/BotCalculations.d.ts +17 -0
- package/bots/BotCalculations.js +53 -5
- package/bots/BotCalculations.js.map +1 -1
- package/bots/test/BotCalculationContextTests.js +1 -0
- package/bots/test/BotCalculationContextTests.js.map +1 -1
- package/package.json +4 -2
- package/runtime/AuxGlobalContext.d.ts +6 -0
- package/runtime/AuxGlobalContext.js +1 -0
- package/runtime/AuxGlobalContext.js.map +1 -1
- package/runtime/AuxLibrary.d.ts +31 -0
- package/runtime/AuxLibrary.js +87 -11
- package/runtime/AuxLibrary.js.map +1 -1
- package/runtime/AuxLibraryDefinitions.def +5173 -2227
- package/runtime/AuxRuntime.d.ts +3 -3
- package/runtime/AuxRuntime.js +22 -3
- package/runtime/AuxRuntime.js.map +1 -1
- package/runtime/RuntimeBot.d.ts +16 -3
- package/runtime/RuntimeBot.js +11 -39
- package/runtime/RuntimeBot.js.map +1 -1
- package/runtime/Utils.js +5 -1
- package/runtime/Utils.js.map +1 -1
- package/runtime/test/TestScriptBotFactory.js +8 -2
- package/runtime/test/TestScriptBotFactory.js.map +1 -1
package/runtime/AuxLibrary.js
CHANGED
|
@@ -11,7 +11,7 @@ import { DEBUG_STRING, debugStringifyFunction, } from './AuxGlobalContext';
|
|
|
11
11
|
import { hasValue, trimTag, isBot, BOT_SPACE_TAG, toast as toastMessage, 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, 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, exportGpioPin, unexportGpioPin, setGpioPin, getGpioPin, 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, 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, listDataRecord, recordEvent as calcRecordEvent, getEventCount as calcGetEventCount, openImageClassifier as calcOpenImageClassifier, } 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, isRuntimeBot, SET_TAG_MASK_SYMBOL, CLEAR_TAG_MASKS_SYMBOL, getBotScale, EDIT_TAG_SYMBOL, EDIT_TAG_MASK_SYMBOL, circleWipe, addDropSnap as calcAddDropSnap, 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, listDataRecord, recordEvent as calcRecordEvent, getEventCount as calcGetEventCount, openImageClassifier as calcOpenImageClassifier, isBotDate, DATE_TAG_PREFIX, parseBotDate, } 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';
|
|
@@ -33,6 +33,8 @@ import htm from 'htm';
|
|
|
33
33
|
import { fromByteArray, toByteArray } from 'base64-js';
|
|
34
34
|
import expect, { iterableEquality } from '@casual-simulation/expect';
|
|
35
35
|
import { parseRecordKey, isRecordKey as calcIsRecordKey, } from '@casual-simulation/aux-records';
|
|
36
|
+
import SeedRandom from 'seedrandom';
|
|
37
|
+
import { DateTime } from 'luxon';
|
|
36
38
|
const _html = htm.bind(h);
|
|
37
39
|
const html = ((...args) => {
|
|
38
40
|
return _html(...args);
|
|
@@ -169,6 +171,8 @@ export function createDefaultLibrary(context) {
|
|
|
169
171
|
getLink: createBotLinkApi,
|
|
170
172
|
getBotLinks,
|
|
171
173
|
updateBotLinks,
|
|
174
|
+
getDateTime,
|
|
175
|
+
DateTime,
|
|
172
176
|
superShout,
|
|
173
177
|
priorityShout,
|
|
174
178
|
shout: shoutProxy,
|
|
@@ -424,6 +428,8 @@ export function createDefaultLibrary(context) {
|
|
|
424
428
|
sqrt,
|
|
425
429
|
abs,
|
|
426
430
|
stdDev,
|
|
431
|
+
getSeededRandomNumberGenerator,
|
|
432
|
+
setRandomSeed,
|
|
427
433
|
randomInt,
|
|
428
434
|
random,
|
|
429
435
|
getForwardDirection,
|
|
@@ -3567,21 +3573,49 @@ export function createDefaultLibrary(context) {
|
|
|
3567
3573
|
let standardMean = avg(numbersMinusMean);
|
|
3568
3574
|
return sqrt(standardMean);
|
|
3569
3575
|
}
|
|
3576
|
+
/**
|
|
3577
|
+
* Creates a new random number generator and returns it.
|
|
3578
|
+
* @param seed The value that should be used to seed the random number generator.
|
|
3579
|
+
*/
|
|
3580
|
+
function getSeededRandomNumberGenerator(seed) {
|
|
3581
|
+
if (hasValue(seed)) {
|
|
3582
|
+
let s = typeof seed !== 'string' ? seed.toString() : seed;
|
|
3583
|
+
return _wrapPrng(seed, SeedRandom(s));
|
|
3584
|
+
}
|
|
3585
|
+
return _wrapPrng(null, SeedRandom());
|
|
3586
|
+
}
|
|
3587
|
+
function _wrapPrng(seed, prng) {
|
|
3588
|
+
return {
|
|
3589
|
+
seed: seed,
|
|
3590
|
+
random(min, max) {
|
|
3591
|
+
return randomBase(min, max, prng);
|
|
3592
|
+
},
|
|
3593
|
+
randomInt(min, max) {
|
|
3594
|
+
return randomIntBase(min, max, prng);
|
|
3595
|
+
},
|
|
3596
|
+
};
|
|
3597
|
+
}
|
|
3598
|
+
/**
|
|
3599
|
+
* Sets the seed that should be used for random numbers.
|
|
3600
|
+
* @param seed The seed that should be used. If given null, then the numbers will be unseeded.
|
|
3601
|
+
*/
|
|
3602
|
+
function setRandomSeed(seed) {
|
|
3603
|
+
if (!hasValue(seed)) {
|
|
3604
|
+
context.pseudoRandomNumberGenerator = null;
|
|
3605
|
+
return;
|
|
3606
|
+
}
|
|
3607
|
+
if (typeof seed !== 'string') {
|
|
3608
|
+
seed = seed.toString();
|
|
3609
|
+
}
|
|
3610
|
+
context.pseudoRandomNumberGenerator = SeedRandom(seed);
|
|
3611
|
+
}
|
|
3570
3612
|
/**
|
|
3571
3613
|
* Generates a random integer number between min and max.
|
|
3572
3614
|
* @param min The smallest allowed value.
|
|
3573
3615
|
* @param max The largest allowed value.
|
|
3574
3616
|
*/
|
|
3575
3617
|
function randomInt(min = 0, max) {
|
|
3576
|
-
min
|
|
3577
|
-
max = Math.floor(max);
|
|
3578
|
-
const rand = Math.random();
|
|
3579
|
-
if (max) {
|
|
3580
|
-
return Math.floor(rand * (max - min)) + min;
|
|
3581
|
-
}
|
|
3582
|
-
else {
|
|
3583
|
-
return Math.floor(rand) + min;
|
|
3584
|
-
}
|
|
3618
|
+
return randomIntBase(min, max, context.pseudoRandomNumberGenerator);
|
|
3585
3619
|
}
|
|
3586
3620
|
/**
|
|
3587
3621
|
* Generates a random number between min and max.
|
|
@@ -3589,7 +3623,10 @@ export function createDefaultLibrary(context) {
|
|
|
3589
3623
|
* @param max The largest allowed value.
|
|
3590
3624
|
*/
|
|
3591
3625
|
function random(min = 0, max) {
|
|
3592
|
-
|
|
3626
|
+
return randomBase(min, max, context.pseudoRandomNumberGenerator);
|
|
3627
|
+
}
|
|
3628
|
+
function randomBase(min = 0, max, prng) {
|
|
3629
|
+
const rand = _random(prng);
|
|
3593
3630
|
if (max) {
|
|
3594
3631
|
return rand * (max - min) + min;
|
|
3595
3632
|
}
|
|
@@ -3597,6 +3634,23 @@ export function createDefaultLibrary(context) {
|
|
|
3597
3634
|
return rand + min;
|
|
3598
3635
|
}
|
|
3599
3636
|
}
|
|
3637
|
+
function randomIntBase(min, max, prng) {
|
|
3638
|
+
min = Math.ceil(min);
|
|
3639
|
+
max = Math.floor(max);
|
|
3640
|
+
const rand = _random(prng);
|
|
3641
|
+
if (max) {
|
|
3642
|
+
return Math.floor(rand * (max - min)) + min;
|
|
3643
|
+
}
|
|
3644
|
+
else {
|
|
3645
|
+
return Math.floor(rand) + min;
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
function _random(prng) {
|
|
3649
|
+
if (prng) {
|
|
3650
|
+
return prng();
|
|
3651
|
+
}
|
|
3652
|
+
return Math.random();
|
|
3653
|
+
}
|
|
3600
3654
|
/**
|
|
3601
3655
|
* Gets the forward direction for the given rotation.
|
|
3602
3656
|
* @param pointerRotation The rotation that the pointer has represented in radians.
|
|
@@ -4697,6 +4751,28 @@ export function createDefaultLibrary(context) {
|
|
|
4697
4751
|
}
|
|
4698
4752
|
}
|
|
4699
4753
|
}
|
|
4754
|
+
/**
|
|
4755
|
+
* Parses the given value into a date time object.
|
|
4756
|
+
* Returns null if the value could not be parsed into a date time.
|
|
4757
|
+
* @param value The value to parse.
|
|
4758
|
+
*/
|
|
4759
|
+
function getDateTime(value) {
|
|
4760
|
+
if (typeof value === 'string') {
|
|
4761
|
+
if (!isBotDate(value)) {
|
|
4762
|
+
value = DATE_TAG_PREFIX + value;
|
|
4763
|
+
}
|
|
4764
|
+
return parseBotDate(value);
|
|
4765
|
+
}
|
|
4766
|
+
else if (value instanceof DateTime) {
|
|
4767
|
+
return value;
|
|
4768
|
+
}
|
|
4769
|
+
else if (value instanceof Date) {
|
|
4770
|
+
return DateTime.fromJSDate(value);
|
|
4771
|
+
}
|
|
4772
|
+
else {
|
|
4773
|
+
return null;
|
|
4774
|
+
}
|
|
4775
|
+
}
|
|
4700
4776
|
/**
|
|
4701
4777
|
* Shouts the given event to every bot in every loaded simulation.
|
|
4702
4778
|
* @param eventName The name of the event to shout.
|