change. contains errors

This commit is contained in:
bedlam343 2024-05-15 20:47:04 -07:00
parent f92e18bbdb
commit 75530d202a
4 changed files with 118 additions and 109 deletions

View File

@ -3,7 +3,7 @@ import type { Message, SimToCmMessage, Range } from 'src/types/schema-types';
const useWorldSim = () => {
const [messages, setMessages] = useState<Message[]>([]);
const [stressLevel, setStressLevel] = useState<Range<0,1>>(0);
const [stressLevel, setStressLevel] = useState<Range<0, 1>>(0);
const socket = useRef<WebSocket | null>();
useEffect(() => {
@ -15,8 +15,12 @@ const useWorldSim = () => {
socket.current.addEventListener('message', (event) => {
// console.log('\x1b[34mmessage received:\x1b[0m', event.data);
const { message, stressLevel }: IncomingMessage = JSON.parse(event.data);
if (message) setMessages((prevMessages) => [...prevMessages, {...message, fulfilled: false}]);
const { message, stressLevel }: SimToCmMessage = JSON.parse(event.data);
if (message)
setMessages((prevMessages) => [
...prevMessages,
{ ...message, fulfilled: false },
]);
if (stressLevel) setStressLevel(stressLevel);
});

View File

@ -71,13 +71,18 @@ const Prototype = () => {
dispatch(addMessage(currentMessage));
reactToMessage({dispatch, currentMessage});
reactToMessage({ dispatch, currentMessage, stressLevel });
}, [messages]);
useEffect(() => {
let allWidgetsInNewStressLPDIds: string[] = Object.keys(widgets); //this should be the actual new ones
stressChangeHandler({dispatch:dispatch, allWidgetIds:Object.keys(widgets), allMessages: messages, allWidgetsInNewStressLPDIds: allWidgetsInNewStressLPDIds})
}, [stressLevel])
stressChangeHandler({
dispatch: dispatch,
allWidgetIds: Object.keys(widgets),
allMessages: messages,
allWidgetsInNewStressLPDIds: allWidgetsInNewStressLPDIds,
});
}, [stressLevel]);
return <Home />;
};

View File

@ -1,14 +1,19 @@
import type { Message } from "src/types/schema-types";
import selector from "./selector";
import assimilator from "./assimilator";
import store from "src/redux/store";
import type { AppDispatch } from "src/redux/store";
import { addElementToWidget, addWidget, addWidgetToSection } from "src/redux/slices/minimapSlice";
import type { Message } from 'src/types/schema-types';
import selector from './selector';
import assimilator from './assimilator';
import store from 'src/redux/store';
import type { AppDispatch } from 'src/redux/store';
import {
addElementToWidget,
addWidget,
addWidgetToSection,
} from 'src/redux/slices/minimapSlice';
type ReactToMessageProps = {
// define expected input here and it's type (number, string, etc.)
dispatch: AppDispatch;
currentMessage: Message;
// define expected input here and it's type (number, string, etc.)
dispatch: AppDispatch;
currentMessage: Message;
stressLevel: number;
};
/**
@ -16,71 +21,70 @@ type ReactToMessageProps = {
* @param ???
* @returns ???
*/
const reactToMessage = ({
dispatch,
currentMessage,
const reactToMessage = ({
dispatch,
currentMessage,
stressLevel,
}: ReactToMessageProps) => {
const sections = store.getState().minimap.sections;
const widgets = store.getState().minimap.widgets;
const sections = store.getState().minimap.sections;
const widgets = store.getState().minimap.widgets;
const { message, possibleWidgets } = selector({
message: currentMessage,
stressLevel,
});
// possibleWidgets[0].id = uuid();
const { message, possibleWidgets } = selector({
message: currentMessage,
});
// possibleWidgets[0].id = uuid();
//console.log('running through assimilator...');
const { widgetToDeploy, sectionID, action } = assimilator({
// find if there is room for us to put the widget down (returns null if there is not room)
possibleWidgets: possibleWidgets,
sections,
widgets,
message,
});
//console.log('widgetToDeploy ' + widgetToDeploy);
if (action !== 'newWidget') {
//we should do something other than
switch (action) {
case 'updateWidget':
console.log('widget already exists, updating');
// only have one widget in possibleWidgets right now, this is why this works
// furthermore, only have one element in the widget
// so we can just do possibleWidgets[0]...
// eventually, maybe assimilator returns the widget that needs to be updated
// assimilator should also say if to add a new element or remove one, etc. -- JAGJIT
dispatch(
addElementToWidget(
possibleWidgets[0].id,
possibleWidgets[0].elements[0],
),
);
break;
case 'none':
console.log('proposed widgets could not be placed');
break;
}
} else if (widgetToDeploy) {
//console.log('widget deployed:', widgetToDeploy);
//console.log('widgets that are now deployed: ', widgets);
//if we can actually place the widget
//ADD RESTRAINER HERE TO CHECK IF WE CAN PLACE THE WIDGET
/* if (
//console.log('running through assimilator...');
const { widgetToDeploy, sectionID, action } = assimilator({
// find if there is room for us to put the widget down (returns null if there is not room)
possibleWidgets: possibleWidgets,
sections,
widgets,
message,
});
//console.log('widgetToDeploy ' + widgetToDeploy);
if (action !== 'newWidget') {
//we should do something other than
switch (action) {
case 'updateWidget':
console.log('widget already exists, updating');
// only have one widget in possibleWidgets right now, this is why this works
// furthermore, only have one element in the widget
// so we can just do possibleWidgets[0]...
// eventually, maybe assimilator returns the widget that needs to be updated
// assimilator should also say if to add a new element or remove one, etc. -- JAGJIT
dispatch(
addElementToWidget(
possibleWidgets[0].id,
possibleWidgets[0].elements[0],
),
);
break;
case 'none':
console.log('proposed widgets could not be placed');
break;
}
} else if (widgetToDeploy) {
//console.log('widget deployed:', widgetToDeploy);
//console.log('widgets that are now deployed: ', widgets);
//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(addWidget(widgetToDeploy));
dispatch(addWidgetToSection(sectionID));
}
}
// dispatch action to add new widget
dispatch(addWidget(widgetToDeploy));
dispatch(addWidgetToSection(sectionID));
}
};
export default reactToMessage;
export default reactToMessage;

View File

@ -1,49 +1,45 @@
import { ElementInGaze } from "src/redux/slices/gazeSlice";
import { removeWidget } from "src/redux/slices/minimapSlice";
import { AppDispatch } from "src/redux/store";
import { BaseElement } from "src/types/element";
import { Message } from "src/types/schema-types";
import { Widget } from "src/types/widget";
import reactToMessage from "./reactToMessage";
import { ElementInGaze } from 'src/redux/slices/gazeSlice';
import { removeWidget } from 'src/redux/slices/minimapSlice';
import { type AppDispatch } from 'src/redux/store';
import { BaseElement } from 'src/types/element';
import { type Message } from 'src/types/schema-types';
import { Widget } from 'src/types/widget';
import reactToMessage from './reactToMessage';
type StressChangeHandlerProps = {
// define expected input here and it's type (number, string, etc.)
dispatch: AppDispatch;
allWidgetIds: string[];
allMessages: Message[];
allWidgetsInNewStressLPDIds: string[];
};
// define expected input here and it's type (number, string, etc.)
dispatch: AppDispatch;
allWidgetIds: string[];
allMessages: Message[];
allWidgetsInNewStressLPDIds: string[];
};
/**
* @description ???
* @param ???
* @returns ???
*/
const stressChangeHandler = ({
dispatch,
allWidgetIds,
allMessages,
allWidgetsInNewStressLPDIds,
}: StressChangeHandlerProps) => {
allWidgetIds.forEach(function(widgetId, widgetIdIndex){
if(!allWidgetsInNewStressLPDIds.includes(widgetId)){
dispatch(removeWidget(widgetId))
}
});
const stressChangeHandler = ({
dispatch,
allWidgetIds,
allMessages,
allWidgetsInNewStressLPDIds,
}: StressChangeHandlerProps) => {
allWidgetIds.forEach(function (widgetId, widgetIdIndex) {
if (!allWidgetsInNewStressLPDIds.includes(widgetId)) {
dispatch(removeWidget(widgetId));
}
});
allMessages.forEach(function(message, messageIndex){
if(!message.fulfilled){
reactToMessage({dispatch:dispatch, currentMessage:message});
}
});
allMessages.forEach(function (message, messageIndex) {
if (!message.fulfilled) {
reactToMessage({ dispatch: dispatch, currentMessage: message });
}
});
//messages need to have completed
//messages need to have completed
return {
return {};
};
};
}
export default stressChangeHandler;
export default stressChangeHandler;