backend fixes, better case handling, some frontend changes
This commit is contained in:
@@ -49,6 +49,8 @@ class TlaController extends Controller
|
|||||||
'hint' => $tla->hint,
|
'hint' => $tla->hint,
|
||||||
'guesses' => $request->session()->get('guesses-'.$language, []),
|
'guesses' => $request->session()->get('guesses-'.$language, []),
|
||||||
'date' => $request->session()->get('date'),
|
'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',
|
'guess' => 'required|array|size:3',
|
||||||
]);
|
]);
|
||||||
$this->session_flush($request, $language);
|
$this->session_flush($request, $language);
|
||||||
|
$tla_object = Tla::GetCurrentTla($language);
|
||||||
|
|
||||||
$tla = explode(' ', Tla::GetCurrentTla($language)->abbreviation);
|
$session = $request->session();
|
||||||
|
|
||||||
|
$tla = explode(' ', strtolower($tla_object->acronym));
|
||||||
|
|
||||||
$guess_array = $request->all()['guess'];
|
$guess_array = $request->all()['guess'];
|
||||||
|
for ($i = 0; $i<3; $i++) {
|
||||||
|
$guess_array[$i] = strtolower($guess_array[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
$proposal = [];
|
$proposal = [];
|
||||||
|
|
||||||
@@ -85,16 +93,24 @@ class TlaController extends Controller
|
|||||||
array_push($guess_array, max($proposal[0][$i], $proposal[1][$i], $proposal[2][$i]));
|
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]);
|
for ($i = 0; $i<3; $i++) {
|
||||||
else $request->session()->push('guesses-'.$language, $guess_array);
|
$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([
|
return response()->json([
|
||||||
'guesses' => $request->session()->get('guesses-'.$language, []),
|
'guesses' => $session->get('guesses-'.$language, []),
|
||||||
'date' => $request->session()->get('date'),
|
'date' => $session->get('date'),
|
||||||
'real' => $tla
|
'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
@@ -11,7 +11,7 @@ class Tla extends Model
|
|||||||
|
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = ['abbreviation', 'hint', 'used'];
|
protected $fillable = ['acronym', 'hint', 'used', 'context'];
|
||||||
|
|
||||||
public static function GetCurrentTla( string $language ) : Tla {
|
public static function GetCurrentTla( string $language ) : Tla {
|
||||||
$tla = Tla::where('used', date("Y-m-d"))
|
$tla = Tla::where('used', date("Y-m-d"))
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ class TlaFactory extends Factory
|
|||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'abbreviation' => fake()->word() . ' ' . fake()->word() . ' ' . fake()->word(),
|
'acronym' => fake()->word() . ' ' . fake()->word() . ' ' . fake()->word(),
|
||||||
'hint' => fake()->sentence(),
|
'hint' => fake()->sentence(),
|
||||||
'language' => fake()->randomElement(['hu', 'en']),
|
'language' => fake()->randomElement(['hu', 'en']),
|
||||||
|
'context' => fake()->paragraph(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('tla', function (Blueprint $table) {
|
Schema::create('tla', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('abbreviation');
|
$table->string('acronym');
|
||||||
$table->string('hint')->nullable();
|
$table->string('hint')->nullable();
|
||||||
$table->enum('language', ['hu', 'en']);
|
$table->enum('language', ['hu', 'en']);
|
||||||
$table->date('used')->nullable();
|
$table->date('used')->nullable();
|
||||||
|
$table->longText('context')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,6 @@
|
|||||||
|
|
||||||
<template #right>
|
<template #right>
|
||||||
<UColorModeButton />
|
<UColorModeButton />
|
||||||
|
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
</UHeader>
|
</UHeader>
|
||||||
<UMain class="main">
|
<UMain class="main">
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Transition } from 'vue';
|
import { Transition } from 'vue';
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
correctness: {
|
correctness: {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import GuessWord from '../components/GuessWord.vue';
|
import GuessWord from '../components/GuessWord.vue';
|
||||||
import { ref } from 'vue'
|
import Modal from '../components/Modal.vue';
|
||||||
import Modal from '../components/Modal.vue';
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -13,6 +12,8 @@ import Modal from '../components/Modal.vue';
|
|||||||
guesses: [' '],
|
guesses: [' '],
|
||||||
words: [' '],
|
words: [' '],
|
||||||
guess: '',
|
guess: '',
|
||||||
|
tla: '',
|
||||||
|
context: '',
|
||||||
victory: false,
|
victory: false,
|
||||||
loss: false,
|
loss: false,
|
||||||
maxGuesses: 10,
|
maxGuesses: 10,
|
||||||
@@ -25,6 +26,8 @@ import Modal from '../components/Modal.vue';
|
|||||||
.then(response => {
|
.then(response => {
|
||||||
this.hint = response.data.hint;
|
this.hint = response.data.hint;
|
||||||
this.guesses = response.data.guesses;
|
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]
|
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) {
|
if (Number(current_guess[3]) + Number(current_guess[4]) + Number(current_guess[5]) == 12) {
|
||||||
this.victory = !this.victory;
|
this.victory = !this.victory;
|
||||||
|
this.tla = response.data.tla;
|
||||||
|
this.context = response.data.context;
|
||||||
}
|
}
|
||||||
else if (this.guesses.length == this.maxGuesses) {
|
else if (this.guesses.length == this.maxGuesses) {
|
||||||
this.loss = !this.loss;
|
this.loss = !this.loss;
|
||||||
@@ -72,7 +77,7 @@ import Modal from '../components/Modal.vue';
|
|||||||
<UButton label="How to play" color="neutral" variant="subtle" />
|
<UButton label="How to play" color="neutral" variant="subtle" />
|
||||||
|
|
||||||
<template #body>
|
<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.
|
and letters the abbreviation has.
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
@@ -86,12 +91,7 @@ import Modal from '../components/Modal.vue';
|
|||||||
<GuessWord :correctness="1">Correct starting letter, wrong place</GuessWord>
|
<GuessWord :correctness="1">Correct starting letter, wrong place</GuessWord>
|
||||||
</div>
|
</div>
|
||||||
If you have any feedback, <a style="text-decoration: underline;" href="mailto:peter@sc0tt.org">
|
If you have any feedback, <a style="text-decoration: underline;" href="mailto:peter@sc0tt.org">
|
||||||
let me know in an email
|
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>
|
||||||
|
|
||||||
</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>
|
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
</UModal>
|
</UModal>
|
||||||
@@ -120,7 +120,7 @@ import Modal from '../components/Modal.vue';
|
|||||||
</div>
|
</div>
|
||||||
<template v-if="guesses.length < maxGuesses">
|
<template v-if="guesses.length < maxGuesses">
|
||||||
<form ref="main-form" @submit="onSubmit" onsubmit="return false">
|
<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>
|
</form>
|
||||||
</template>
|
</template>
|
||||||
<h3>{{ guesses.length }} / {{ maxGuesses }}</h3>
|
<h3>{{ guesses.length }} / {{ maxGuesses }}</h3>
|
||||||
@@ -130,7 +130,7 @@ import Modal from '../components/Modal.vue';
|
|||||||
|
|
||||||
<Modal v-model:open="victory">
|
<Modal v-model:open="victory">
|
||||||
<h1>Congratulations!</h1>
|
<h1>Congratulations!</h1>
|
||||||
Todays TLA was: whatever you wrote
|
Todays TLA was: {{ tla }}
|
||||||
</Modal>
|
</Modal>
|
||||||
<Modal v-model:open="loss">
|
<Modal v-model:open="loss">
|
||||||
<h1>What a shame!</h1>
|
<h1>What a shame!</h1>
|
||||||
|
|||||||
Reference in New Issue
Block a user