restrain boundaries

This commit is contained in:
Azlothe 2024-04-04 16:15:48 -07:00
parent 6c652501ee
commit 2bdc3fd432
4 changed files with 59 additions and 8 deletions

View File

@ -16,6 +16,9 @@ import assimilator from 'src/prototype/assimilator';
import generateMessage from 'src/utils/generateMessage';
import type { Message } from 'src/types/schema-types';
import type { Widget } from 'src/types/modalities';
import useRestrainer from 'src/prototype/useRestrainer';
import { generateModalityMeasure } from 'src/utils/restrainerConst';
import restrainer from 'src/prototype/useRestrainer';
const Prototype = () => {
const dispatch = useAppDispatch();
@ -57,6 +60,7 @@ const Prototype = () => {
//if we can actually place the widget
//ADD RESTRAINER HERE TO CHECK IF WE CAN PLACE THE WIDGET
if(!restrainer({ visualComplexity:generateModalityMeasure(), audioComplexity:generateModalityMeasure() })) return;
// dispatch action to add new widget
dispatch(addWidgetToGrid(widgetToDeploy));

View File

@ -1,10 +1,11 @@
import type { Widget } from 'src/types/modalities';
import type { Modality } from 'src/types/modalities';
import { modalityMeasures } from 'src/utils/restrainerConst';
type RestrainerProps = {
// define expected input here and it's type (number, string, etc.)
visualComplexity: number;
audioComplexity: number;
widgets: { [key: string]: Widget };
// widgets: { [key: string]: Widget };
// add more as needed
};
@ -18,14 +19,14 @@ type ModalityMeasureBoundary = {
max: number;
};
type ModalityMeasure = {
export type ModalityMeasure = {
// for now it only takes into account how many visual and audio modalities are used
/**
* or use array instead of number and use objects with attributes such as volume, frequency
* amount of audios playing at the same time for example can be seen by the amout of objects in the list
*/
Visual: number;
Audio: number;
type: Modality;
measure: number;
range: ModalityMeasureRange;
boundary: ModalityMeasureBoundary;
};
@ -35,6 +36,16 @@ type ModalityMeasure = {
* @param ???
* @returns ???
*/
const useRestrainer = ({ visualComplexity }: RestrainerProps) => {};
const restrainer = ({ visualComplexity }: RestrainerProps) => {
// currently visual only
if (modalityMeasures.visual.boundary.max - modalityMeasures.visual.measure <= visualComplexity) {
console.warn("widget could not be added; will surpass boundary");
return false;
}
export default useRestrainer;
modalityMeasures.visual.measure += visualComplexity;
console.log(modalityMeasures);
return true;
};
export default restrainer;

View File

@ -1 +1 @@
export const ONE_SECOND_IN_MS = 1000;
export const ONE_SECOND_IN_MS = 1000;

View File

@ -0,0 +1,36 @@
import type { ModalityMeasure } from "src/prototype/useRestrainer";
const visualMeasure : ModalityMeasure = {
type: "visual",
measure: 0,
boundary: {
min: 0,
max: 200
},
range: {
min: 0,
max: 255
}
};
const auralMeasure : ModalityMeasure = {
type: "auditory",
measure: 0,
boundary: {
min: 0,
max: 150
},
range: {
min: 0,
max: 255
}
};
export const modalityMeasures = {
visual: visualMeasure,
audio: auralMeasure
};
export function generateModalityMeasure() {
return ((Math.random() * 25) + 5);
}