backend fixes, better case handling, some frontend changes

This commit is contained in:
2026-08-11 17:57:38 +02:00
parent ddcb410eee
commit 0f1de1fffc
7 changed files with 39 additions and 25 deletions
+23 -7
View File
@@ -49,6 +49,8 @@ class TlaController extends Controller
'hint' => $tla->hint,
'guesses' => $request->session()->get('guesses-'.$language, []),
'date' => $request->session()->get('date'),
'tla' => $request->session()->get('tla') == $tla->acronym ? $tla->acronym : NULL,
'context' => $request->session()->get('tla') == $tla->acronym ? $tla->context : NULL,
]);
}
@@ -58,10 +60,16 @@ class TlaController extends Controller
'guess' => 'required|array|size:3',
]);
$this->session_flush($request, $language);
$tla_object = Tla::GetCurrentTla($language);
$session = $request->session();
$tla = explode(' ', Tla::GetCurrentTla($language)->abbreviation);
$tla = explode(' ', strtolower($tla_object->acronym));
$guess_array = $request->all()['guess'];
for ($i = 0; $i<3; $i++) {
$guess_array[$i] = strtolower($guess_array[$i]);
}
$proposal = [];
@@ -85,16 +93,24 @@ class TlaController extends Controller
array_push($guess_array, max($proposal[0][$i], $proposal[1][$i], $proposal[2][$i]));
}
$score = 0;
if ( $request->session()->get('guesses-'.$language, NULL) == NULL ) $request->session()->put('guesses-'.$language, [$guess_array]);
else $request->session()->push('guesses-'.$language, $guess_array);
for ($i = 0; $i<3; $i++) {
$guess_array[$i] = ucfirst($guess_array[$i]);
$score += $guess_array[$i + 3];
}
$guesses = $request->session()->get('guesses-'.$language, NULL);
if ($score == 12) $session->put('tla', $tla_object->acronym);
$session->push('guesses-'.$language, $guess_array);
$guesses = $session->get('guesses-'.$language, NULL);
return response()->json([
'guesses' => $request->session()->get('guesses-'.$language, []),
'date' => $request->session()->get('date'),
'real' => $tla
'guesses' => $session->get('guesses-'.$language, []),
'date' => $session->get('date'),
'tla' => $session->get('tla') == $tla_object->acronym ? $tla_object->acronym : NULL,
'context' => $session->get('tla') == $tla_object->acronym ? $tla_object->context : NULL,
'score' => $score,
]);
}
+1 -1
View File
@@ -11,7 +11,7 @@ class Tla extends Model
use HasFactory;
protected $fillable = ['abbreviation', 'hint', 'used'];
protected $fillable = ['acronym', 'hint', 'used', 'context'];
public static function GetCurrentTla( string $language ) : Tla {
$tla = Tla::where('used', date("Y-m-d"))
+2 -1
View File
@@ -18,9 +18,10 @@ class TlaFactory extends Factory
public function definition(): array
{
return [
'abbreviation' => fake()->word() . ' ' . fake()->word() . ' ' . fake()->word(),
'acronym' => fake()->word() . ' ' . fake()->word() . ' ' . fake()->word(),
'hint' => fake()->sentence(),
'language' => fake()->randomElement(['hu', 'en']),
'context' => fake()->paragraph(),
];
}
}
@@ -13,10 +13,11 @@ return new class extends Migration
{
Schema::create('tla', function (Blueprint $table) {
$table->id();
$table->string('abbreviation');
$table->string('acronym');
$table->string('hint')->nullable();
$table->enum('language', ['hu', 'en']);
$table->date('used')->nullable();
$table->longText('context')->nullable();
$table->timestamps();
});
}
-2
View File
@@ -27,8 +27,6 @@
<template #right>
<UColorModeButton />
</template>
</UHeader>
<UMain class="main">
-2
View File
@@ -8,8 +8,6 @@
<script lang="ts">
import { Transition } from 'vue';
export default {
props: {
correctness: {
+11 -11
View File
@@ -1,8 +1,7 @@
<script setup lang="ts">
import axios from 'axios';
import GuessWord from '../components/GuessWord.vue';
import { ref } from 'vue'
import Modal from '../components/Modal.vue';
import Modal from '../components/Modal.vue';
</script>
<script lang="ts">
@@ -13,6 +12,8 @@ import Modal from '../components/Modal.vue';
guesses: [' '],
words: [' '],
guess: '',
tla: '',
context: '',
victory: false,
loss: false,
maxGuesses: 10,
@@ -25,6 +26,8 @@ import Modal from '../components/Modal.vue';
.then(response => {
this.hint = response.data.hint;
this.guesses = response.data.guesses;
this.tla = response.data.tla;
this.context = response.data.context;
});
},
@@ -45,6 +48,8 @@ import Modal from '../components/Modal.vue';
let current_guess = response.data.guesses[response.data.guesses.length-1]
if (Number(current_guess[3]) + Number(current_guess[4]) + Number(current_guess[5]) == 12) {
this.victory = !this.victory;
this.tla = response.data.tla;
this.context = response.data.context;
}
else if (this.guesses.length == this.maxGuesses) {
this.loss = !this.loss;
@@ -72,7 +77,7 @@ import Modal from '../components/Modal.vue';
<UButton label="How to play" color="neutral" variant="subtle" />
<template #body>
You have to try and guess the TLA (Three Letter Abbreviation). You get a Motto to start on, and on each try you get more information about the kinds of words
You have to try and guess the TLA (Three Letter Acronym). You get a Motto to start on, and on each try you get more information about the kinds of words
and letters the abbreviation has.
<br>
@@ -86,12 +91,7 @@ import Modal from '../components/Modal.vue';
<GuessWord :correctness="1">Correct starting letter, wrong place</GuessWord>
</div>
If you have any feedback, <a style="text-decoration: underline;" href="mailto:peter@sc0tt.org">
let me know in an email
</a>, or create a <a style="text-decoration: underline;" href='https://gitea.sc0tt.org/Belupeti/TLA/pulls'>pull request</a>
<br><br>
<h2 style="font-weight: bold;">IMPORTANT</h2>
<p>Only use lowercase letters, I have not yet implemented automatic casing yet and I should really get some sleep</p>
let me know in an email</a>, or create a <a style="text-decoration: underline;" href='https://gitea.sc0tt.org/Belupeti/TLA/pulls'>pull request</a>
</template>
</UModal>
@@ -120,7 +120,7 @@ import Modal from '../components/Modal.vue';
</div>
<template v-if="guesses.length < maxGuesses">
<form ref="main-form" @submit="onSubmit" onsubmit="return false">
<input style="background-color: grey;" type="text" @keyup="onkeyup()" v-model="guess">
<UInput v-model="guess" @keyup="onkeyup()"/>
</form>
</template>
<h3>{{ guesses.length }} / {{ maxGuesses }}</h3>
@@ -130,7 +130,7 @@ import Modal from '../components/Modal.vue';
<Modal v-model:open="victory">
<h1>Congratulations!</h1>
Todays TLA was: whatever you wrote
Todays TLA was: {{ tla }}
</Modal>
<Modal v-model:open="loss">
<h1>What a shame!</h1>