@casual-simulation/aux-common
Advanced tools
Comparing version 0.8.3 to 0.8.4
@@ -11,5 +11,7 @@ export declare type PartialFile = Partial<File>; | ||
['aux.scene.color']?: string; | ||
['aux.scene.user.player.color']?: unknown; | ||
['aux.scene.user.builder.color']?: unknown; | ||
['aux.whitelist']?: unknown; | ||
['aux.blacklist']?: unknown; | ||
['aux.builders']?: unknown; | ||
['aux.designers']?: unknown; | ||
['aux.version']?: unknown; | ||
@@ -48,5 +50,5 @@ ['aux.color']?: unknown; | ||
['aux.channel']?: string; | ||
['aux._creator']?: string; | ||
['aux._diff']?: boolean; | ||
['aux._diffTags']?: string[]; | ||
['aux.diff']?: unknown; | ||
['aux.diffTags']?: unknown; | ||
['aux.creator']?: string; | ||
['aux._selection']?: string; | ||
@@ -67,5 +69,5 @@ ['aux._user']?: string; | ||
['aux.context.visualize']?: ContextVisualizeMode; | ||
['aux.context.surface.x']?: number; | ||
['aux.context.surface.y']?: number; | ||
['aux.context.surface.z']?: number; | ||
['aux.context.x']?: number; | ||
['aux.context.y']?: number; | ||
['aux.context.z']?: number; | ||
['aux.context.surface.scale']?: number; | ||
@@ -172,2 +174,14 @@ ['aux.context.surface.defaultHeight']?: number; | ||
/** | ||
* The default color for users in AUX Builder. | ||
*/ | ||
export declare const DEFAULT_BUILDER_USER_COLOR = "#00D000"; | ||
/** | ||
* The default color for users in AUX Player. | ||
*/ | ||
export declare const DEFAULT_PLAYER_USER_COLOR = "#DDDD00"; | ||
/** | ||
* The ID of the global configuration file. | ||
*/ | ||
export declare const GLOBALS_FILE_ID = "config"; | ||
/** | ||
* The current file format version for AUX Files. | ||
@@ -174,0 +188,0 @@ * This number increments whenever there are any changes between AUX versions. |
@@ -54,2 +54,14 @@ /** | ||
/** | ||
* The default color for users in AUX Builder. | ||
*/ | ||
export const DEFAULT_BUILDER_USER_COLOR = '#00D000'; | ||
/** | ||
* The default color for users in AUX Player. | ||
*/ | ||
export const DEFAULT_PLAYER_USER_COLOR = '#DDDD00'; | ||
/** | ||
* The ID of the global configuration file. | ||
*/ | ||
export const GLOBALS_FILE_ID = 'config'; | ||
/** | ||
* The current file format version for AUX Files. | ||
@@ -75,6 +87,8 @@ * This number increments whenever there are any changes between AUX versions. | ||
'aux._selectionMode', | ||
'aux._creator', | ||
'aux._lastEditedBy', | ||
'aux.scene.color', | ||
'aux.scene.user.player.color', | ||
'aux.scene.user.builder.color', | ||
'aux.color', | ||
'aux.creator', | ||
'aux.movable', | ||
@@ -124,10 +138,11 @@ 'aux.movable.diffTags', | ||
'aux.context.color', | ||
'aux.context.locked', | ||
'aux.context.grid.scale', | ||
'aux.context.surface.grid', | ||
'aux.context.surface.x', | ||
'aux.context.surface.y', | ||
'aux.context.surface.z', | ||
'aux.context.surface.rotation.x', | ||
'aux.context.surface.rotation.y', | ||
'aux.context.surface.rotation.z', | ||
'aux.context.x', | ||
'aux.context.y', | ||
'aux.context.z', | ||
'aux.context.rotation.x', | ||
'aux.context.rotation.y', | ||
'aux.context.rotation.z', | ||
'aux.context.surface.scale', | ||
@@ -141,4 +156,5 @@ 'aux.context.surface.defaultHeight', | ||
'onCombine()', | ||
'onSave()', | ||
'onClose()', | ||
'onDiff()', | ||
'onSaveInput()', | ||
'onCloseInput()', | ||
'onCreate()', | ||
@@ -165,3 +181,4 @@ 'onDestroy()', | ||
'onKeyUp()', | ||
'onGridClick()', | ||
]; | ||
//# sourceMappingURL=File.js.map |
@@ -1,2 +0,2 @@ | ||
import { Object, File, Workspace, UserMode, SelectionMode, FileShape, FileTags, FileLabelAnchor, FileDragMode, ContextVisualizeMode } from './File'; | ||
import { Object, File, Workspace, AuxDomain, UserMode, SelectionMode, FileShape, FileTags, FileLabelAnchor, FileDragMode, ContextVisualizeMode } from './File'; | ||
import { Sandbox, SandboxLibrary, SandboxResult } from '../Formulas/Sandbox'; | ||
@@ -14,2 +14,6 @@ import { SetValueHandler, FileProxy } from './FileProxy'; | ||
/** | ||
* The name of the event that represents a file being diffed into another file. | ||
*/ | ||
export declare const DIFF_ACTION_NAME: string; | ||
/** | ||
* The name of the event that represents a file being created. | ||
@@ -233,9 +237,7 @@ */ | ||
export declare function isFilterTag(tag: string): boolean; | ||
export declare const WELL_KNOWN_TAGS: RegExp[]; | ||
/** | ||
* Determines if the given tag is "well known". | ||
* @param tag The tag. | ||
* @param includeSelectionTags Whether to include selection tags. | ||
*/ | ||
export declare function isTagWellKnown(tag: string, includeSelectionTags?: boolean): boolean; | ||
export declare function isTagWellKnown(tag: string): boolean; | ||
/** | ||
@@ -257,3 +259,2 @@ * Determines if the files are equal disregarding well-known hidden tags | ||
export interface FileAppearanceEqualityOptions { | ||
ignoreSelectionTags?: boolean; | ||
ignoreId?: boolean; | ||
@@ -315,2 +316,10 @@ } | ||
/** | ||
* Gets the color that the given user file should appear as. | ||
* @param calc The file calculation context. | ||
* @param userFile The user file. | ||
* @param globalsFile The globals file. | ||
* @param domain The domain. | ||
*/ | ||
export declare function getUserFileColor(calc: FileCalculationContext, userFile: File, globalsFile: File, domain: AuxDomain): string; | ||
/** | ||
* Gets the menu ID that is used for the given user. | ||
@@ -515,3 +524,3 @@ * @param userFile The file for the user. | ||
/** | ||
* Gets the aux.builders tag from the given file. | ||
* Gets the aux.designers tag from the given file. | ||
* Always returns an array of strings. | ||
@@ -522,3 +531,3 @@ * If any files returned by the formula, then the aux._user tag will be used from the file. | ||
*/ | ||
export declare function getFileBuilderList(calc: FileCalculationContext, file: File): string[]; | ||
export declare function getFileDesignerList(calc: FileCalculationContext, file: File): string[]; | ||
/** | ||
@@ -730,6 +739,7 @@ * Gets the AUX_FILE_VERSION number that the given file was created with. | ||
* Third, it will not have any well known tags. (see isTagWellKnown()) | ||
* @param calc The file calculation context. | ||
* @param file The file to duplicate. | ||
* @param data The optional data that should override the existing file data. | ||
*/ | ||
export declare function duplicateFile(file: Object, data?: PartialFile): Object; | ||
export declare function duplicateFile(calc: FileCalculationContext, file: Object, data?: PartialFile): Object; | ||
/** | ||
@@ -739,3 +749,3 @@ * Determines if the given file represents a diff. | ||
*/ | ||
export declare function isDiff(file: File): boolean; | ||
export declare function isDiff(calc: FileCalculationContext, file: File): boolean; | ||
/** | ||
@@ -753,3 +763,3 @@ * Determines if the given file allows for merging. | ||
* Gets a partial file that can be used to apply the diff that the given file represents. | ||
* A diff file is any file that has `aux._diff` set to `true` and `aux._diffTags` set to a list of tag names. | ||
* A diff file is any file that has `aux.diff` set to `true` and `aux.diffTags` set to a list of tag names. | ||
* @param calc The file calculation context. | ||
@@ -759,2 +769,3 @@ * @param file The file that represents the diff. | ||
export declare function getDiffUpdate(calc: FileCalculationContext, file: File): PartialFile; | ||
export declare function getDiffTags(calc: FileCalculationContext, file: File): string[]; | ||
export declare function simulationIdToString(id: SimulationIdParseSuccess): string; | ||
@@ -761,0 +772,0 @@ export declare function parseSimulationId(id: string): SimulationIdParseSuccess; |
@@ -71,3 +71,3 @@ import { sortBy, flatMap, mapValues } from 'lodash'; | ||
function destroyChildren(calc, events, id) { | ||
const result = calculateFormulaValue(calc, `@aux._creator("${id}")`); | ||
const result = calculateFormulaValue(calc, `@aux.creator("${id}")`); | ||
if (result.success) { | ||
@@ -74,0 +74,0 @@ const children = result.result; |
@@ -187,4 +187,9 @@ import { File, FileTags } from '../Files/File'; | ||
declare function getNeighboringFiles(file: FileProxy, context: string, position: 'left' | 'right' | 'front' | 'back'): FileProxy[]; | ||
declare function createDiff(file: any, ...tags: (string | RegExp)[]): FileDiff; | ||
declare function loadDiff(file: any, ...tags: (string | RegExp)[]): FileDiff; | ||
/** | ||
* Saves the given diff to a string of JSON. | ||
* @param file The diff to save. | ||
*/ | ||
declare function saveDiff(file: any): string; | ||
/** | ||
* Applies the given diff to the given file. | ||
@@ -280,3 +285,4 @@ * @param file The file. | ||
setPosition: typeof setPositionDiff; | ||
create: typeof createDiff; | ||
load: typeof loadDiff; | ||
save: typeof saveDiff; | ||
}; | ||
@@ -337,3 +343,4 @@ /** | ||
setPosition: typeof setPositionDiff; | ||
create: typeof createDiff; | ||
load: typeof loadDiff; | ||
save: typeof saveDiff; | ||
}; | ||
@@ -340,0 +347,0 @@ math: { |
@@ -0,1 +1,2 @@ | ||
import { GLOBALS_FILE_ID } from '../Files/File'; | ||
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, importAUX as calcImportAUX, showInputForTag as calcShowInputForTag, } from '../Files/FilesChannel'; | ||
@@ -5,3 +6,3 @@ import uuid from 'uuid/v4'; | ||
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, tagsOnFile, isDestroyable, isInUsernameList, getFileUsernameList, } from '../Files/FileCalculations'; | ||
import { calculateFormulaValue, COMBINE_ACTION_NAME, addToContextDiff as calcAddToContextDiff, removeFromContextDiff as calcRemoveFromContextDiff, setPositionDiff as calcSetPositionDiff, isFile, isFormulaObject, unwrapProxy, CREATE_ACTION_NAME, DESTROY_ACTION_NAME, isFileInContext, tagsOnFile, isDestroyable, isInUsernameList, getFileUsernameList, DIFF_ACTION_NAME, } from '../Files/FileCalculations'; | ||
import '../polyfill/Array.first.polyfill'; | ||
@@ -269,3 +270,3 @@ import '../polyfill/Array.last.polyfill'; | ||
function destroyChildren(id) { | ||
const result = calculateFormulaValue(calc, `@aux._creator("${id}")`); | ||
const result = calculateFormulaValue(calc, `@aux.creator("${id}")`); | ||
if (result.success) { | ||
@@ -364,3 +365,3 @@ const children = result.result; | ||
? { | ||
'aux._creator': parentId, | ||
'aux.creator': parentId, | ||
} | ||
@@ -444,5 +445,5 @@ : {}; | ||
const globalsFile = globals[proxyObject]; | ||
const list = getFileUsernameList(calc, globalsFile, 'aux.builders'); | ||
const list = getFileUsernameList(calc, globalsFile, 'aux.designers'); | ||
if (list) { | ||
return isInUsernameList(calc, globalsFile, 'aux.builders', user[proxyObject].tags['aux._user']); | ||
return isInUsernameList(calc, globalsFile, 'aux.designers', user[proxyObject].tags['aux._user']); | ||
} | ||
@@ -502,3 +503,3 @@ } | ||
function getGlobals() { | ||
const globals = calc.sandbox.interface.listObjectsWithTag('id', 'globals'); | ||
const globals = calc.sandbox.interface.listObjectsWithTag('id', GLOBALS_FILE_ID); | ||
if (Array.isArray(globals)) { | ||
@@ -588,21 +589,29 @@ if (globals.length === 1) { | ||
} | ||
function createDiff(file, ...tags) { | ||
function loadDiff(file, ...tags) { | ||
if (typeof file === 'string') { | ||
file = JSON.parse(file); | ||
} | ||
let diff = {}; | ||
let fileTags = tagsOnFile(file); | ||
let fileTags = isFile(file) ? tagsOnFile(file) : Object.keys(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; | ||
if (tags.length > 0) { | ||
for (let tag of tags) { | ||
if (tag instanceof RegExp) { | ||
if (tag.test(fileTag)) { | ||
add = true; | ||
break; | ||
} | ||
} | ||
} | ||
else { | ||
if (tag === fileTag) { | ||
add = true; | ||
break; | ||
else { | ||
if (tag === fileTag) { | ||
add = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
add = true; | ||
} | ||
if (add) { | ||
@@ -615,2 +624,9 @@ diff[fileTag] = file[fileTag]; | ||
/** | ||
* Saves the given diff to a string of JSON. | ||
* @param file The diff to save. | ||
*/ | ||
function saveDiff(file) { | ||
return JSON.stringify(file); | ||
} | ||
/** | ||
* Applies the given diff to the given file. | ||
@@ -621,2 +637,3 @@ * @param file The file. | ||
function applyDiff(file, ...diffs) { | ||
let appliedDiffs = []; | ||
diffs.forEach(diff => { | ||
@@ -632,2 +649,3 @@ if (!diff) { | ||
} | ||
appliedDiffs.push(diff); | ||
for (let key in diff) { | ||
@@ -637,2 +655,7 @@ file[key] = unwrapProxy(diff[key]); | ||
}); | ||
if (isFile(file)) { | ||
event(DIFF_ACTION_NAME, [file], { | ||
diffs: appliedDiffs, | ||
}); | ||
} | ||
} | ||
@@ -657,21 +680,2 @@ /** | ||
/** | ||
* Adds the given file to the given context. | ||
* @param file The file. | ||
* @param context The context. | ||
* @param x The X position that the file should be added at. | ||
* @param y The Y position that the file should be added at. | ||
* @param index The index that the file should be added at. | ||
*/ | ||
function addToContext(file, context, x = 0, y = 0, index) { | ||
applyDiff(file, addToContextDiff(context, x, y, index)); | ||
} | ||
/** | ||
* Removes the given file from the given context. | ||
* @param file The file. | ||
* @param context The context. | ||
*/ | ||
function removeFromContext(file, context) { | ||
applyDiff(file, removeFromContextDiff(context)); | ||
} | ||
/** | ||
* Gets a diff that sets the position of a file in the given context when applied. | ||
@@ -694,9 +698,2 @@ * @param context The context. | ||
/** | ||
* Adds the given file to the current user's menu. | ||
* @param file The file to add to the menu. | ||
*/ | ||
function addToMenu(file) { | ||
applyDiff(file, addToMenuDiff()); | ||
} | ||
/** | ||
* Gets a diff that removes a file from the current user's menu. | ||
@@ -709,9 +706,2 @@ */ | ||
/** | ||
* Removes the given file from the current user's menu. | ||
* @param file The file to remove from the menu. | ||
*/ | ||
function removeFromMenu(file) { | ||
applyDiff(file, removeFromMenuDiff()); | ||
} | ||
/** | ||
* Shows a toast message to the user. | ||
@@ -799,3 +789,4 @@ * @param message The message to show. | ||
setPosition: setPositionDiff, | ||
create: createDiff, | ||
load: loadDiff, | ||
save: saveDiff, | ||
}; | ||
@@ -802,0 +793,0 @@ /** |
{ | ||
"name": "@casual-simulation/aux-common", | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"description": "Common library for AUX projects", | ||
@@ -56,3 +56,3 @@ "main": "index.js", | ||
], | ||
"gitHead": "471ba6dd769d0d0cd71500a33a4b17cf9c09052e" | ||
"gitHead": "a31a553d4fd43a23fc91efdc1df866ba256f7277" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
408277
8034