Skip to content

Commit

Permalink
feat: play next action until no next action
Browse files Browse the repository at this point in the history
  • Loading branch information
FaaizHaikal committed Jun 7, 2024
1 parent 89907df commit 0be9acb
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions src/components/RunActionButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ActionContext from '../context/ActionContext';
import LoggerContext from '../context/LoggerContext';

function RunActionButton() {
const { currentAction, GRPC_WEB_API_URL } = useContext(ActionContext);
const { actionsData, currentAction, GRPC_WEB_API_URL } = useContext(ActionContext);
const { showLog } = useContext(LoggerContext);

const client = new akushon_interfaces.ConfigClient(GRPC_WEB_API_URL, null, null);
Expand All @@ -17,28 +17,52 @@ function RunActionButton() {
const [isLoading, setIsLoading] = useState(false);

const handlePublish = () => {
setIsLoading(true);
const fixedPoses = [];
const rawPoses = currentAction.poses;

if (Object.keys(currentAction).length === 0) {
showLog('No action selected.', 'warning');
return client;
}

setIsLoading(true);
const fixedPoses = [];
const rawPoses = [];

let currentActionTemp = currentAction;
while (currentActionTemp.next !== "") {
rawPoses.push(currentActionTemp.poses);
let i;
for (i = 0; i < actionsData.length; i += 1) {
if (actionsData[i].name === currentActionTemp.next) {
currentActionTemp = actionsData[i];
break;
}
}

if (i === actionsData.length) {
showLog(`Next action [${currentActionTemp.next}] not found!`, 'error');
setIsLoading(false);
return;
}
}

rawPoses.push(currentActionTemp.poses);

for (let i = 0; i < rawPoses.length; i += 1) {
const jointsData = {};
for (let j = 0; j < rawPoses[i].joints.length; j += 1) {
jointsData[rawPoses[i].joints[j].name] = rawPoses[i].joints[j].pose_pos;
const rawPose = rawPoses[i];
for (let j = 0; j < rawPose.length; j += 1) {
const jointsData = {};
for (let k = 0; k < rawPose[j].joints.length; k += 1) {
jointsData[rawPose[j].joints[k].name] = rawPose[j].joints[k].pose_pos;
}
fixedPoses.push({
name: rawPose[j].name,
pause: rawPose[j].pause,
speed: rawPose[j].speed,
time: rawPose[j].time,
joints: jointsData,
});
}
fixedPoses.push({
name: rawPoses[i].name,
pause: rawPoses[i].pause,
speed: rawPoses[i].speed,
time: rawPoses[i].time,
joints: jointsData,
});
}

const rawAction = {
name: currentAction.name,
next: currentAction.next,
Expand Down

0 comments on commit 0be9acb

Please sign in to comment.