import { PrecalculatedBot , BotTags , BotSpace , Bot , BotSignatures , botsFromShortIds , TAG_MASK_SPACE_PRIORITIES , RuntimeBot , hasValue , } from '../../bots' ; import { createRuntimeBot , RuntimeBotInterface , RuntimeBotFactory , RealtimeEditMode , } from '../RuntimeBot' ; import { createCompiledBot , CompiledBot } from '../CompiledBot' ; import { pickBy } from 'lodash' ; import { applyTagEdit , isTagEdit } from '../../aux-format-2' ; export class TestScriptBotFactory implements RuntimeBotFactory { createRuntimeBot ( bot ) { return createDummyRuntimeBot ( bot . id , bot . tags , bot . space ) ; } destroyScriptBot ( ) { return RealtimeEditMode . Immediate ; } } param id param tags param space export function createDummyRuntimeBot ( id , tags = { } , space ? , signatures ? ) { let functions = pickBy ( tags , ( t ) => typeof t === 'function' ) ; const precalc = createCompiledBot ( id , tags , undefined , space , functions , signatures ) ; return createRuntimeBot ( precalc , testScriptBotInterface ) ; } export const testScriptBotInterface = { updateTag ( bot , tag , newValue ) { if ( isTagEdit ( newValue ) ) { bot . values [ tag ] = bot . tags [ tag ] = applyTagEdit ( bot . tags [ tag ] , newValue ) ; } else { if ( hasValue ( newValue ) ) { bot . tags [ tag ] = newValue ; bot . values [ tag ] = newValue ; } else { delete bot . tags [ tag ] ; delete bot . values [ tag ] ; } } return RealtimeEditMode . Immediate ; } , getValue ( bot , tag ) { return bot . values [ tag ] ; } , getRawValue ( bot , tag ) { return bot . tags [ tag ] ; } , getListener ( bot , tag ) { return bot . listeners [ tag ] ; } , getSignature ( bot , signature ) { if ( bot . signatures ) { return bot . signatures [ signature ] ; } else { return undefined ; } } , notifyChange ( ) { } , getTagMask ( bot , tag ) { if ( ! bot . masks ) { return undefined ; } for ( let space of TAG_MASK_SPACE_PRIORITIES ) { if ( ! bot . masks [ space ] ) { continue ; } if ( tag in bot . masks [ space ] ) { return bot . masks [ space ] [ tag ] ; } } return undefined ; } , updateTagMask ( bot , tag , spaces , value ) { if ( ! bot . masks ) { bot . masks = { } ; } for ( let space of spaces ) { if ( ! bot . masks [ space ] ) { bot . masks [ space ] = { } ; } if ( isTagEdit ( value ) ) { bot . masks [ space ] [ tag ] = applyTagEdit ( bot . masks [ space ] [ tag ] , value ) ; } else { bot . masks [ space ] [ tag ] = value ; } } return RealtimeEditMode . Immediate ; } , getTagLink ( bot , tag ) { return null ; } , currentVersion : { localSites : { } , vector : { } , } , } ;