try game hints
This commit is contained in:
parent
4bfc649dec
commit
b31c8b3529
3 changed files with 75 additions and 33 deletions
|
@ -214,9 +214,32 @@ class Game
|
||||||
$target = $lowest_scoring_hit->getTarget();
|
$target = $lowest_scoring_hit->getTarget();
|
||||||
$emotion = $target->getEmotion();
|
$emotion = $target->getEmotion();
|
||||||
|
|
||||||
|
$exaggerate = ($target->getScore() - $hit->getEmotions()->getEmotionScore($emotion)) > 20 ? "only " : "";
|
||||||
|
$exaggerate = ($target->getScore() - $hit->getEmotions()->getEmotionScore($emotion)) < -20 ? "a whopping " : $only;
|
||||||
|
|
||||||
$text = "When you had to feel "
|
$text = "When you had to feel "
|
||||||
. $target->getScore() ."% " . $emotion->getName()
|
. $target->getScore() ."% " . $emotion->getName()
|
||||||
." you showed " . $hit->getEmotions()->getEmotionScore($emotion) ."%. To show you empathy, ...";
|
." you showed " . $exaggerate . round($hit->getEmotions()->getEmotionScore($emotion),3) ."%.";
|
||||||
|
$betterHit = Application::getInstance()->getEm()->getRepository(Hit::class)->getBetterHit($lowest_scoring_hit);
|
||||||
|
if(!empty($betterHit)) {
|
||||||
|
$diffs = $betterHit->getExpressions()->getDifferences($hit->getExpressions());
|
||||||
|
$max = max($diffs);
|
||||||
|
$min = min($diffs);
|
||||||
|
$diff = abs($max) > $abs($min) ? $max : $min;
|
||||||
|
$diffExpression = array_search($diff, $diffs);
|
||||||
|
if($diff < 1) {
|
||||||
|
$diff = $diff * -1;
|
||||||
|
$diffText = "less";
|
||||||
|
} else {
|
||||||
|
$diffText = "more";
|
||||||
|
}
|
||||||
|
|
||||||
|
if($diffExpression) {
|
||||||
|
$diffExpressionText = $betterHit->getExpressions()::$EXPRESSIONS_2ND_PERSON[$diffExpression];
|
||||||
|
$text .= " To show your empathy, you have to " . $diffExpressionText . $diff . "% " . $diffText;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,6 +429,26 @@ class Expressions {
|
||||||
*/
|
*/
|
||||||
public static $EXPRESSIONS = ['roll','pitch','yaw','inter_ocular_distance','mouth_open','lip_press','brow_raise','nose_wrinkler','lip_depressor','brow_furrow','attention','smile','inner_brow_raiser','chin_raiser','smirk','lip_suck','upper_lip_raiser','lip_pucker','eye_closure','engagement','valence'];
|
public static $EXPRESSIONS = ['roll','pitch','yaw','inter_ocular_distance','mouth_open','lip_press','brow_raise','nose_wrinkler','lip_depressor','brow_furrow','attention','smile','inner_brow_raiser','chin_raiser','smirk','lip_suck','upper_lip_raiser','lip_pucker','eye_closure','engagement','valence'];
|
||||||
|
|
||||||
|
public static $EXPRESSIONS_2ND_PERSON = [
|
||||||
|
'mouth_open' => 'open your mouth',
|
||||||
|
'lip_press' => 'press your lips',
|
||||||
|
'brow_raise' => 'raise your brow',
|
||||||
|
'nose_wrinkler' => 'wrinkle your nose',
|
||||||
|
'lip_depressor' => 'depress your lips',
|
||||||
|
'brow_furrow' => 'furrow your brows',
|
||||||
|
'attention' => 'focus at the camera',
|
||||||
|
'smile' => 'smile',
|
||||||
|
'inner_brow_raiser' => 'raise the inner side of your brows',
|
||||||
|
'chin_raiser' => 'raise your chin',
|
||||||
|
'smirk' => 'smirk',
|
||||||
|
'lip_suck' => 'suck your lips',
|
||||||
|
'upper_lip_raiser' => 'raise your upper lip',
|
||||||
|
'lip_pucker' => 'pucker your lip',
|
||||||
|
'eye_closure' => 'close your eyes',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var float Head roll angle
|
* @var float Head roll angle
|
||||||
* @ORM\Column(type="float")
|
* @ORM\Column(type="float")
|
||||||
|
@ -754,6 +774,29 @@ class Expressions {
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getExpressionScore(string $expression){
|
||||||
|
$expressions = static::$EXPRESSIONS;
|
||||||
|
if(in_array($expression, $expressions)) {
|
||||||
|
return $this->$expression;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get difference between two expressions objects
|
||||||
|
* Get only for those that can be used in 2nd person
|
||||||
|
*
|
||||||
|
* @param Expressions $expressions To compare wiht
|
||||||
|
* @return array Key: expression, value, diff
|
||||||
|
*/
|
||||||
|
public function getDifferences(Expressions $expressions) {
|
||||||
|
$diffs = [];
|
||||||
|
foreach(array_keys(static::$EXPRESSIONS_2ND_PERSON) as $exp) {
|
||||||
|
$diffs[$exp] = $this->getExpressionScore($exp) - $expressions->getExpressionScore($exp);
|
||||||
|
}
|
||||||
|
return $diffs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @ORM\Embeddable */
|
/** @ORM\Embeddable */
|
||||||
|
|
|
@ -6,42 +6,18 @@ use EmotionHero\Tools\Position;
|
||||||
|
|
||||||
class HitRepository extends EntityRepository
|
class HitRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
public function getPositionForGame(Game $game) {
|
public function getBetterHit(Hit $hit) {
|
||||||
|
// we want only the slightly better hit...
|
||||||
$query = $this->_em->createQuery(
|
$query = $this->_em->createQuery(
|
||||||
"SELECT COUNT(g.id) FROM ". Game::class ." g WHERE g.score < :score AND g.level = :level"
|
"SELECT * FROM ".Hit::class." WHERE target = :target AND score > :score ORDER BY score ASC"
|
||||||
)
|
)
|
||||||
|
->setMaxResults(1)
|
||||||
->setParameters([
|
->setParameters([
|
||||||
'score' => $game->getScore(),
|
'score' => $hit->getScore(),
|
||||||
'level' => $game->getLevel(),
|
'target' => $hit->getTarget(),
|
||||||
]);
|
]);
|
||||||
$position = $query->getSingleScalarResult();
|
$betterHit = $query->getOneOrNullResult();
|
||||||
$total = $this->getCountForLevel($game->getLevel());
|
|
||||||
$highscore = $this->getHighscoreForLevel($game->getLevel());
|
|
||||||
|
|
||||||
return new Position($position, $total, $game->getScore(), $highscore);
|
return $betterHit;
|
||||||
}
|
|
||||||
|
|
||||||
public function getCountForLevel(Level $level) {
|
|
||||||
|
|
||||||
$query = $this->_em->createQuery(
|
|
||||||
"SELECT COUNT(g.id) FROM ".Game::class." g WHERE g.level = :level"
|
|
||||||
)
|
|
||||||
->setParameters([
|
|
||||||
'level' => $level,
|
|
||||||
]);
|
|
||||||
return $query->getSingleScalarResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getHighscoreForLevel(Level $level) {
|
|
||||||
$query = $this->_em->createQuery(
|
|
||||||
"SELECT MAX(g.score) FROM ".Game::class." g WHERE g.level = :level"
|
|
||||||
)
|
|
||||||
->setParameters([
|
|
||||||
'level' => $level,
|
|
||||||
]);
|
|
||||||
return $query->getSingleScalarResult();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue