@casual-simulation/aux-common
Advanced tools
Comparing version 0.7.0 to 0.7.5
@@ -153,3 +153,4 @@ import { Object, File, Workspace, UserMode, SelectionMode, FileShape, FileTags, FileLabelAnchor, FileDragMode } from './File'; | ||
*/ | ||
export declare function fileTags(files: File[], currentTags: string[], extraTags: string[], includeHidden?: boolean): string[]; | ||
export declare function fileTags(files: File[], currentTags: string[], extraTags: string[], includeHidden?: boolean, tagBlacklist?: string[], blacklistIndex?: boolean[]): string[]; | ||
export declare function getAllFileTags(files: File[]): string[]; | ||
/** | ||
@@ -738,2 +739,3 @@ * Find files that match the short ids. | ||
export declare function getDiffUpdate(file: File): PartialFile; | ||
export declare function simulationIdToString(id: SimulationIdParseSuccess): string; | ||
export declare function parseSimulationId(id: string): SimulationIdParseSuccess; | ||
@@ -740,0 +742,0 @@ /** |
import { DEFAULT_WORKSPACE_SCALE, DEFAULT_WORKSPACE_HEIGHT, DEFAULT_WORKSPACE_GRID_SCALE, DEFAULT_USER_MODE, DEFAULT_SELECTION_MODE, DEFAULT_FILE_SHAPE, DEFAULT_WORKSPACE_SIZE, DEFAULT_LABEL_ANCHOR, } from './File'; | ||
import uuid from 'uuid/v4'; | ||
import { flatMap, union, keys, intersection, some, assign, find, values, isEqual, sortBy, cloneDeep, } from 'lodash'; | ||
import { flatMap, union, keys, intersection, some, assign, find, values, isEqual, sortBy, cloneDeep, sortedIndexBy, } from 'lodash'; | ||
import { Sandbox } from '../Formulas/Sandbox'; | ||
@@ -111,3 +111,3 @@ import { isProxy, createFileProxy, proxyObject, } from './FileProxy'; | ||
*/ | ||
export function fileTags(files, currentTags, extraTags, includeHidden = false) { | ||
export function fileTags(files, currentTags, extraTags, includeHidden = false, tagBlacklist = [], blacklistIndex = []) { | ||
const fileTags = flatMap(files, f => keys(f.tags)); | ||
@@ -119,4 +119,68 @@ // Only keep tags that don't start with an underscore (_) | ||
const onlyTagsToKeep = intersection(allTags, tagsToKeep); | ||
return onlyTagsToKeep; | ||
// if there is a blacklist index and the first index [all] is not selected | ||
if (blacklistIndex != undefined && | ||
blacklistIndex.length > 0 && | ||
tagBlacklist != undefined && | ||
tagBlacklist.length > 0) { | ||
let filteredTags = []; | ||
for (let i = onlyTagsToKeep.length - 1; i >= 0; i--) { | ||
for (let j = tagBlacklist.length - 1; j >= 0; j--) { | ||
if (onlyTagsToKeep[i] != undefined) { | ||
if (!onlyTagsToKeep[i].includes('.')) { | ||
// no section indecator, but matches the blacklist tag, remove it | ||
if (j === 0 && !blacklistIndex[0]) { | ||
// if | ||
let isNotInBlacklist = true; | ||
for (let k = tagBlacklist.length - 1; k >= 0; k--) { | ||
if (onlyTagsToKeep[i] === tagBlacklist[k]) { | ||
isNotInBlacklist = false; | ||
} | ||
} | ||
if (isNotInBlacklist) { | ||
onlyTagsToKeep.splice(i, 1); | ||
} | ||
} | ||
else { | ||
if (onlyTagsToKeep[i] === tagBlacklist[j] && | ||
!blacklistIndex[j]) { | ||
onlyTagsToKeep.splice(i, 1); | ||
//filteredTags.push(onlyTagsToKeep[i]); | ||
} | ||
} | ||
} | ||
else { | ||
if (j === 0 && !blacklistIndex[0]) { | ||
let isNotInBlacklist = true; | ||
for (let k = tagBlacklist.length - 1; k >= 0; k--) { | ||
if (onlyTagsToKeep[i].split('.')[0] === | ||
tagBlacklist[k]) { | ||
isNotInBlacklist = false; | ||
} | ||
} | ||
if (isNotInBlacklist) { | ||
onlyTagsToKeep.splice(i, 1); | ||
} | ||
} | ||
else { | ||
// if section indecator and it is a block listed tag, remove it | ||
if (onlyTagsToKeep[i].split('.')[0] === | ||
tagBlacklist[j] && | ||
!blacklistIndex[j]) { | ||
onlyTagsToKeep.splice(i, 1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return onlyTagsToKeep; | ||
} | ||
else { | ||
return onlyTagsToKeep; | ||
} | ||
} | ||
export function getAllFileTags(files) { | ||
const fileTags = flatMap(files, f => keys(f.tags)); | ||
return fileTags; | ||
} | ||
/** | ||
@@ -734,2 +798,5 @@ * Find files that match the short ids. | ||
export function filtersMatchingArguments(context, file, eventName, args) { | ||
if (file === undefined) { | ||
return; | ||
} | ||
const tags = keys(file.tags); | ||
@@ -1243,2 +1310,12 @@ return tags | ||
} | ||
export function simulationIdToString(id) { | ||
let str = ''; | ||
if (id.host) { | ||
str += `${id.host}/`; | ||
} | ||
if (id.channel) { | ||
str += id.channel; | ||
} | ||
return str; | ||
} | ||
export function parseSimulationId(id) { | ||
@@ -1253,3 +1330,3 @@ try { | ||
host: uri.host, | ||
channel: split[0], | ||
context: split[0], | ||
}; | ||
@@ -1268,4 +1345,4 @@ } | ||
host: uri.host, | ||
channel: split[0], | ||
context: split.slice(1).join('/'), | ||
context: split[0], | ||
channel: split.slice(1).join('/'), | ||
}; | ||
@@ -1680,3 +1757,3 @@ } | ||
constructor(context, userId, setValueHandlerFactory) { | ||
this.objects = context.objects; | ||
this.objects = sortBy(context.objects, 'id'); | ||
this.context = context; | ||
@@ -1696,3 +1773,4 @@ this._userId = userId; | ||
else { | ||
this.objects.push(file); | ||
const index = sortedIndexBy(this.objects, file, f => f.id); | ||
this.objects.splice(index, 0, file); | ||
return this._convertToFormulaObject(file); | ||
@@ -1706,3 +1784,3 @@ } | ||
const filtered = this._filterValues(tags, filter); | ||
return _singleOrArray(filtered); | ||
return filtered; | ||
} | ||
@@ -1714,3 +1792,3 @@ listObjectsWithTag(tag, filter, extras) { | ||
const filtered = this._filterObjects(objs, filter, tag); | ||
return _singleOrArray(filtered); | ||
return filtered; | ||
} | ||
@@ -1717,0 +1795,0 @@ list(obj, context) { |
@@ -100,3 +100,3 @@ import { File, PartialFile } from './File'; | ||
*/ | ||
export declare type LocalEvents = ShowToastEvent | TweenToEvent | OpenQRCodeScannerEvent | ShowQRCodeEvent | LoadSimulationEvent | UnloadSimulationEvent | SuperShoutEvent; | ||
export declare type LocalEvents = ShowToastEvent | TweenToEvent | OpenQRCodeScannerEvent | ShowQRCodeEvent | LoadSimulationEvent | UnloadSimulationEvent | SuperShoutEvent | GoToContextEvent; | ||
/** | ||
@@ -179,2 +179,12 @@ * An event that is used to show a toast message to the user. | ||
/** | ||
* Defines an event that is used to send the player to a context. | ||
*/ | ||
export interface GoToContextEvent extends LocalEvent { | ||
name: 'go_to_context'; | ||
/** | ||
* The context that should be loaded. | ||
*/ | ||
context: string; | ||
} | ||
/** | ||
* Defines an event for actions. | ||
@@ -275,1 +285,7 @@ * Actions are basically user-defined events. | ||
export declare function superShout(eventName: string, arg?: any): SuperShoutEvent; | ||
/** | ||
* Creates a new GoToContextEvent. | ||
* @param simulationOrContext The simulation ID or context to go to. If a simulation ID is being provided, then the context parameter must also be provided. | ||
* @param context | ||
*/ | ||
export declare function goToContext(context: string): GoToContextEvent; |
@@ -30,3 +30,3 @@ import { sortBy, flatMap, mapValues } from 'lodash'; | ||
let changes = {}; | ||
objects.forEach(o => { | ||
context.sandbox.interface.objects.forEach(o => { | ||
changes[o.id] = { | ||
@@ -39,3 +39,3 @@ changedTags: [], | ||
let events = fileEvents; | ||
const updates = objects.map(o => calculateFileUpdateFromChanges(o.id, changes[o.id])); | ||
const updates = context.sandbox.interface.objects.map(o => calculateFileUpdateFromChanges(o.id, changes[o.id])); | ||
updates.forEach(u => { | ||
@@ -116,2 +116,5 @@ if (u) { | ||
function eventActions(state, objects, context, file, eventName, setValueHandlerFactory, argument) { | ||
if (file === undefined) { | ||
return; | ||
} | ||
const otherObjects = objects.filter(o => o !== file); | ||
@@ -340,3 +343,15 @@ const sortedObjects = sortBy(objects, o => o !== file); | ||
} | ||
/** | ||
* Creates a new GoToContextEvent. | ||
* @param simulationOrContext The simulation ID or context to go to. If a simulation ID is being provided, then the context parameter must also be provided. | ||
* @param context | ||
*/ | ||
export function goToContext(context) { | ||
return { | ||
type: 'local', | ||
name: 'go_to_context', | ||
context: context, | ||
}; | ||
} | ||
// export | ||
//# sourceMappingURL=FilesChannel.js.map |
@@ -5,2 +5,4 @@ import { File, FileTags } from '../Files/File'; | ||
import { FileCalculationContext } from '../Files/FileCalculations'; | ||
import '../polyfill/Array.first.polyfill'; | ||
import '../polyfill/Array.last.polyfill'; | ||
export declare function setActions(value: FileEvent[]): void; | ||
@@ -131,7 +133,6 @@ export declare function getActions(): FileEvent[]; | ||
/** | ||
* Redirects the user to a context in the given simulation and context. | ||
* @param simulationId The ID of the simulation to go to. | ||
* @param context The context to go to. If not provided then the simulation ID will be used as the context. | ||
* Redirects the user to the given context. | ||
* @param context The context to go to. | ||
*/ | ||
export declare function goToContext(simulationId: string, context?: string): void; | ||
export declare function goToContext(context: string): void; | ||
/** | ||
@@ -143,2 +144,6 @@ * Derermines whether the player is in the given context. | ||
/** | ||
* Gets the context that the player is currently in. | ||
*/ | ||
export declare function currentContext(): string; | ||
/** | ||
* Determines whether the player has the given file in their inventory. | ||
@@ -165,2 +170,3 @@ * @param files The file or files to check. | ||
export declare function getFilesInContext(context: string): FileProxy[]; | ||
export declare function createDiff(file: any, ...tags: (string | RegExp)[]): FileDiff; | ||
/** | ||
@@ -277,2 +283,3 @@ * Applies the given diff to the given file. | ||
setPosition: typeof setPositionDiff; | ||
create: typeof createDiff; | ||
}; | ||
@@ -298,2 +305,3 @@ /** | ||
isConnected: typeof isConnected; | ||
currentContext: typeof currentContext; | ||
}; | ||
@@ -330,2 +338,3 @@ /** | ||
setPosition: typeof setPositionDiff; | ||
create: typeof createDiff; | ||
}; | ||
@@ -357,2 +366,3 @@ math: { | ||
isConnected: typeof isConnected; | ||
currentContext: typeof currentContext; | ||
}; | ||
@@ -359,0 +369,0 @@ applyDiff: typeof applyDiff; |
@@ -1,6 +0,8 @@ | ||
import { action, calculateActionEvents, fileRemoved, fileAdded, toast as toastMessage, tweenTo as calcTweenTo, openQRCodeScanner as calcOpenQRCodeScanner, loadSimulation as calcLoadSimulation, unloadSimulation as calcUnloadSimulation, superShout as calcSuperShout, showQRCode as calcShowQRCode, } from '../Files/FilesChannel'; | ||
import { action, calculateActionEvents, fileRemoved, fileAdded, toast as toastMessage, tweenTo as calcTweenTo, openQRCodeScanner as calcOpenQRCodeScanner, loadSimulation as calcLoadSimulation, unloadSimulation as calcUnloadSimulation, superShout as calcSuperShout, showQRCode as calcShowQRCode, goToContext as calcGoToContext, } from '../Files/FilesChannel'; | ||
import uuid from 'uuid/v4'; | ||
import { every } from 'lodash'; | ||
import { isProxy, proxyObject } from '../Files/FileProxy'; | ||
import { calculateFormulaValue, COMBINE_ACTION_NAME, addToContextDiff as calcAddToContextDiff, removeFromContextDiff as calcRemoveFromContextDiff, setPositionDiff as calcSetPositionDiff, isFormulaObject, unwrapProxy, CREATE_ACTION_NAME, DESTROY_ACTION_NAME, isFileInContext, } from '../Files/FileCalculations'; | ||
import { calculateFormulaValue, COMBINE_ACTION_NAME, addToContextDiff as calcAddToContextDiff, removeFromContextDiff as calcRemoveFromContextDiff, setPositionDiff as calcSetPositionDiff, isFormulaObject, unwrapProxy, CREATE_ACTION_NAME, DESTROY_ACTION_NAME, isFileInContext, tagsOnFile, } from '../Files/FileCalculations'; | ||
import '../polyfill/Array.first.polyfill'; | ||
import '../polyfill/Array.last.polyfill'; | ||
let actions = []; | ||
@@ -337,17 +339,7 @@ let state = null; | ||
/** | ||
* Redirects the user to a context in the given simulation and context. | ||
* @param simulationId The ID of the simulation to go to. | ||
* @param context The context to go to. If not provided then the simulation ID will be used as the context. | ||
* Redirects the user to the given context. | ||
* @param context The context to go to. | ||
*/ | ||
export function goToContext(simulationId, context) { | ||
if (!context) { | ||
// Go to context in same simulation | ||
context = simulationId; | ||
// Grab the simulation ID from the current URL. | ||
// pathname always starts with a '/' so the first part is actually the second | ||
// element. | ||
simulationId = window.location.pathname.split('/')[1]; | ||
} | ||
// Go to context and simulation | ||
window.location.pathname = `${simulationId}/${context}`; | ||
export function goToContext(context) { | ||
actions.push(calcGoToContext(context)); | ||
} | ||
@@ -359,6 +351,16 @@ /** | ||
export function isInContext(givenContext) { | ||
let currentContext = window.location.pathname.split('/')[2]; | ||
return currentContext === givenContext; | ||
return currentContext() === givenContext; | ||
} | ||
/** | ||
* Gets the context that the player is currently in. | ||
*/ | ||
export function currentContext() { | ||
const user = getUser(); | ||
if (user) { | ||
const context = user['aux._userContext']; | ||
return context.valueOf() || undefined; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Determines whether the player has the given file in their inventory. | ||
@@ -428,2 +430,27 @@ * @param files The file or files to check. | ||
} | ||
export function createDiff(file, ...tags) { | ||
let diff = {}; | ||
let fileTags = tagsOnFile(file); | ||
for (let fileTag of fileTags) { | ||
let add = false; | ||
for (let tag of tags) { | ||
if (tag instanceof RegExp) { | ||
if (tag.test(fileTag)) { | ||
add = true; | ||
break; | ||
} | ||
} | ||
else { | ||
if (tag === fileTag) { | ||
add = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (add) { | ||
diff[fileTag] = file[fileTag]; | ||
} | ||
} | ||
return diff; | ||
} | ||
/** | ||
@@ -600,2 +627,3 @@ * Applies the given diff to the given file. | ||
setPosition: setPositionDiff, | ||
create: createDiff, | ||
}; | ||
@@ -621,2 +649,3 @@ /** | ||
isConnected, | ||
currentContext, | ||
}; | ||
@@ -623,0 +652,0 @@ /** |
@@ -10,2 +10,6 @@ import { File } from '../Files/File'; | ||
/** | ||
* The list of objects contained by the interface. | ||
*/ | ||
objects: File[]; | ||
/** | ||
* Calculates the list of tag values for the given tag. | ||
@@ -12,0 +16,0 @@ * @param tag The tag. |
{ | ||
"name": "@casual-simulation/aux-common", | ||
"version": "0.7.0", | ||
"version": "0.7.5", | ||
"description": "Common library for AUX projects", | ||
@@ -56,3 +56,3 @@ "main": "index.js", | ||
], | ||
"gitHead": "625296c14d329479cedefab0519ddc8af02a2207" | ||
"gitHead": "b212d65e45a8dd9c98c16086d735fec19e57d272" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
374656
93
7368