diff --git a/src/Api/ScoreControllerProvider.php b/src/Api/ScoreControllerProvider.php index 9f3750e..646510c 100644 --- a/src/Api/ScoreControllerProvider.php +++ b/src/Api/ScoreControllerProvider.php @@ -205,6 +205,90 @@ class ScoreControllerProvider implements ControllerProviderInterface return new JsonResponse(['success' => true, 'message' => "images saved."], 200); }); + $controllers->get('/hits/{hitId}', function(Request $request, Application $app) { + + $hit = $request->attributes->get('hit'); + + if(empty($hit)) { + return new JsonResponse(['message' => 'Hit not found'], 404); + } + + return new CustomJsonResponse($hit, $app['serializer.json'], 200); + }) + ->bind('hit') + ->convert('hit', function($hit, Request $request) use ($app){ return $app['entity.manager']->getRepository(Models\Hit::class)->find($request->attributes->get('hitId'));}); + + /** + * Convert the hit to a mhpose file for use with MakeHuman + */ + $controllers->get('/hits/{hitId}.mhpose', function(Request $request, Application $app) { + + $hit = $request->attributes->get('hit'); + + if(empty($hit)) { + return new JsonResponse(['message' => 'Hit not found'], 404); + } + + $conversions = [ + 'roll' => [], + 'pitch' => [], + 'yaw' => [], + 'inter_ocular_distance' => [], + 'mouth_open' => ["JawDropStretched"], + 'lip_press' => ["Lowerlipup"], + 'brow_raise' => ["RightOuterBrowUp","LeftOuterBrowUp"], + 'nose_wrinkler' => ["NasolabialDeepener"], + 'lip_depressor' => ["Mouthrightpulldown","Mouthleftpulldown"], + 'brow_furrow' => ["Nosewrinkler"], + 'attention' => [], + 'smile' => ["Mouthrightpullup","Mouthrightpulldown","Upperlipup","Lowerlipdown"], + 'smile' => ["Upperlipstretched"], + 'inner_brow_raiser' => ["RightInnerBrowUp","LeftInnerBrowUp"], + 'chin_raiser' => ["ChinForward"], + 'smirk' => ["MouthLeftPullUp"], + 'lip_suck' => ["Upperlipbackward","Lowerlipbackward"], + 'upper_lip_raiser' => ["Upperlipup"], + 'lip_pucker' => ["Lipskiss"], + 'lip_pucker' => ["Upperlipforward","Lowerlipforward"], + 'eye_closure' => ["RightUpperLidClosed","LefttUpperLidClosed"], + 'engagement' => [], + 'valence' => [], + 'dimpler' => ["Mouthrightpullside","Mouthleftpullside"], + 'cheek_raise' => ["LeftCheekUp","RightCheekUp"], + 'eye_widen' => ["RightUpperLidOpen","LeftUpperLidOpen"], + 'jaw_drop' => ["JawDrop"], + 'lid_tighten' => ["LeftLowerLidUp","RightLowerLidUp"], + 'lip_stretch' => ["Mouthrightpullside","Mouthleftpullside"], + // + ]; + + $data = [ + "license" => "AGPL3", + "name" => "hit_{$hit->getId()}", + "copyright" => "None", + "tags" => [ + "no tag", + "expression" + ], + "author" => "Ruben van de Ven & player {$hit->getGame()->getUser()->getId()}", + "unit_poses" => [], + "homepage" => "http://emotionhero.com", + "description" => "Hit {$hit->getId()} in the Emotion Hero game by player {$hit->getGame()->getUser()->getId()}. Points awarded for hit: {$hit->getScore()}." + ]; + + foreach($conversions as $from => $to) { + $value = $hit->getExpressions()->getExpressionScore($from) / 100; + foreach($to as $t) { + $data['unit_poses'][$t] = isSet($data['unit_poses'][$t]) ? max(1,$data['unit_poses'][$t]+$value) : $value; + } + } + + return new CustomJsonResponse($data, $app['serializer.json'], 200); + }) + ->bind('hit') + ->convert('hit', function($hit, Request $request) use ($app){ return $app['entity.manager']->getRepository(Models\Hit::class)->find($request->attributes->get('hitId'));}); + + return $controllers; } }