Skip to content

Commit

Permalink
Fixed import/export functionality (#63)
Browse files Browse the repository at this point in the history
fixed import and export for all minigame configs
  • Loading branch information
13on4rd authored Dec 14, 2024
1 parent 9c10d50 commit 8b80464
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 29 deletions.
9 changes: 8 additions & 1 deletion .nginx/compose/nginx-dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ server {
proxy_pass http://keycloak/keycloak/;
}


location /minigames/bugfinder/api/ {
proxy_pass http://bugfinder-backend/api/;
}
Expand All @@ -41,6 +40,10 @@ server {
proxy_pass http://regexgame-backend/api/;
}

location /minigames/towercrush/api/ {
proxy_pass http://towercrush-backend/api/;
}

location /minigames/towerdefense/api/ {
proxy_pass http://towerdefense-backend/api/;
}
Expand Down Expand Up @@ -77,6 +80,10 @@ server {
proxy_pass http://regexgame/;
}

location /minigames/towercrush/ {
proxy_pass http://towercrush/;
}

location /minigames/towerdefense/ {
proxy_pass http://towerdefense/;
}
Expand Down
8 changes: 8 additions & 0 deletions .nginx/compose/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ server {
proxy_pass http://regexgame-backend/api/;
}

location /minigames/towercrush/api/ {
proxy_pass http://towercrush-backend/api/;
}

location /minigames/towerdefense/api/ {
proxy_pass http://towerdefense-backend/api/;
}
Expand Down Expand Up @@ -76,6 +80,10 @@ server {
proxy_pass http://regexgame/;
}

location /minigames/towercrush/ {
proxy_pass http://towercrush/;
}

location /minigames/towerdefense/ {
proxy_pass http://towerdefense/;
}
Expand Down
47 changes: 46 additions & 1 deletion docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ services:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres

towercrush-db:
container_name: towercrush-db
image: postgres:14-alpine
restart: always
expose:
- "5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres

towerdefense-db:
container_name: towerdefense-db
image: postgres:14-alpine
Expand Down Expand Up @@ -145,6 +155,8 @@ services:
- FINITEQUIZ_URL=http://finitequiz-backend/api/v1
- BUGFINDER_URL=http://bugfinder-backend/api/v1
- MEMORY_URL=http://memory-backend/api/v1
- TOWERCURSH_URL=http://towercrush-backend/api/v1
- TOWERDEFENSE=http://towerdefense-backend/api/v1
- KEYCLOAK_ISSUER=http://localhost/keycloak/realms/Gamify-IT
- KEYCLOAK_URL=http://keycloak/keycloak/realms/Gamify-IT

Expand Down Expand Up @@ -249,6 +261,23 @@ services:
- OVERWORLD_URL=http://overworld-backend/api/v1
- KEYCLOAK_ISSUER=http://localhost/keycloak/realms/Gamify-IT
- KEYCLOAK_URL=http://keycloak/keycloak/realms/Gamify-IT

towercrush-backend:
container_name: towercrush-backend
image: ghcr.io/gamify-it/towercrush-backend:main
restart: always
pull_policy: always
expose:
- "80"
depends_on:
- towercrush-db
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_URL=postgresql://towercrush-db:5432/postgres
- OVERWORLD_URL=http://overworld-backend/api/v1
- KEYCLOAK_ISSUER=http://localhost/keycloak/realms/Gamify-IT
- KEYCLOAK_URL=http://keycloak/keycloak/realms/Gamify-IT

towerdefense-backend:
container_name: towerdefense-backend
Expand All @@ -262,7 +291,7 @@ services:
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_URL=postgresql://regexgame-db:5432/postgres
- POSTGRES_URL=postgresql://towerdefense-db:5432/postgres
- OVERWORLD_URL=http://overworld-backend/api/v1
- KEYCLOAK_ISSUER=http://localhost/keycloak/realms/Gamify-IT
- KEYCLOAK_URL=http://keycloak/keycloak/realms/Gamify-IT
Expand Down Expand Up @@ -331,6 +360,22 @@ services:
restart: always
expose:
- "80"

towercrush:
container_name: towercrush
image: ghcr.io/gamify-it/towercrush:main
pull_policy: always
restart: always
expose:
- "80"

towerdefense:
container_name: towerdefense
image: ghcr.io/gamify-it/towerdefense:main
pull_policy: always
restart: always
expose:
- "80"

# reverse-proxy
reverse-proxy:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<script setup lang="ts">
import { saveAs } from "file-saver";
import { arrayOf, defaultValue, int, object, string } from "checkeasy";
import {
arrayOf,
object,
optional,
string,
int,
nullable,
defaultValue,
} from "checkeasy";
import { importConfiguration } from "@/ts/import-configuration";
import { defineEmits, defineProps, ref, watch } from "vue";
import {
Expand Down Expand Up @@ -250,6 +258,7 @@ async function importFile(event: any) {
wrongAnswers: arrayOf(string()),
})
),
volumeLevel: optional(nullable(int())),
});
try {
const result: ChickenshockConfiguration = await importConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// compatible crosswordpuzzle versions: v0.0.6
const compatibleVersions = ["v0.0.6"];
import { saveAs } from "file-saver";
import { arrayOf, object, optional, string } from "checkeasy";
import { arrayOf, object, optional, string, int, nullable } from "checkeasy";
import { importConfiguration } from "@/ts/import-configuration";
import { defineEmits, defineProps, ref, watch } from "vue";
import { ITask } from "@/ts/models/overworld-models";
Expand Down Expand Up @@ -198,6 +198,7 @@ async function importFile(event: any) {
answer: string(),
})
),
volumeLevel: optional(nullable(int())),
});
try {
const result: CrosswordpuzzleConfiguration = await importConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// compatible finitequiz versions: v0.0.1
const compatibleVersions = ["v0.0.1"];
import { saveAs } from "file-saver";
import { arrayOf, object, string } from "checkeasy";
import { arrayOf, object, string, optional, int, nullable } from "checkeasy";
import { importConfiguration } from "@/ts/import-configuration";
import { defineEmits, defineProps, ref, watch } from "vue";
import { ITask } from "@/ts/models/overworld-models";
Expand Down Expand Up @@ -250,6 +250,7 @@ async function importFile(event: any) {
wrongAnswers: arrayOf(string()),
})
),
volumeLevel: optional(nullable(int())),
});
try {
const result: FinitequizConfiguration = await importConfiguration(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<script setup lang="ts">
import { saveAs } from "file-saver";
import { arrayOf, object, oneOf, string } from "checkeasy";
import {
arrayOf,
object,
oneOf,
string,
optional,
int,
nullable,
} from "checkeasy";
import { importConfiguration } from "@/ts/import-configuration";
import { Ref, defineEmits, defineProps, ref, watch } from "vue";
import {
Expand Down Expand Up @@ -278,6 +286,7 @@ async function importFile(event: any) {
}),
})
),
volumeLevel: optional(nullable(int())),
});
try {
const result: MemoryConfiguration = await importConfiguration(
Expand Down
37 changes: 23 additions & 14 deletions src/components/EditMinigameModals/EditRegexGameModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { saveAs } from "file-saver";
import { arrayOf, defaultValue, int, object, string } from "checkeasy";
import { arrayOf, int, object, string, optional, nullable } from "checkeasy";
import { importConfiguration } from "@/ts/import-configuration";
import { defineEmits, defineProps, ref, watch } from "vue";
import {
Expand Down Expand Up @@ -107,7 +107,7 @@ function setupModal() {
Object.entries(RegexStructure)
.filter((s) => typeof s[1] !== "string")
.forEach((k) => {
structureCheckboxes.value[k[0]] = configuredStructures.includes(k[0]);
structureCheckboxes.value[k[0]] = configuredStructures.has(k[0]);
});
if (configuration.value.riddleTimeoutSeconds === 0) timeEnable.value = false;
Expand All @@ -122,7 +122,7 @@ function handleOk() {
allowedRegexStructures.add(
Object.entries(RegexStructure)
.filter((s) => typeof s[1] !== "string")
.find((s) => s[0] === checkbox[0])![0]
.find((s) => s[0] === checkbox[0])?.[0]
);
});
// eslint-disable-next-line
Expand Down Expand Up @@ -190,21 +190,30 @@ function downloadConfiguration() {
async function importFile(event: any) {
const file = event.target.files[0];
const validator = object({
time: defaultValue(60, int()),
questions: arrayOf(
object({
text: string(),
rightAnswer: string(),
wrongAnswers: arrayOf(string()),
})
),
allowedRegexStructures: arrayOf(string()),
minimumCompletedRounds: int(),
answerCount: int(),
riddleTimeoutSeconds: int(),
volumeLevel: optional(nullable(int())),
});
try {
const result: RegexGameConfiguration = await importConfiguration(
file,
validator,
toast
);
// process allowedRegexStructures
const allowedStructuresSet = new Set(
result.allowedRegexStructures.map((structure: string) => {
return RegexStructure[structure as keyof typeof RegexStructure];
})
);
// update the checkboxes for the new values
Object.entries(RegexStructure)
.filter(([key, value]) => typeof value !== "string")
.forEach(([key, value]) => {
structureCheckboxes.value[key] = allowedStructuresSet.has(value);
});
configuration.value = result;
} catch (e) {
console.log("Import was not successful.");
Expand Down Expand Up @@ -238,7 +247,7 @@ async function importFile(event: any) {
<b-form-input
v-if="timeEnable"
id="time-input"
v-model="configuration.riddleTimeoutSeconds"
v-model.number="configuration.riddleTimeoutSeconds"
:state="configuration.riddleTimeoutSeconds >= 1"
type="number"
/>
Expand All @@ -250,7 +259,7 @@ async function importFile(event: any) {
>
<b-form-input
id="answers-input"
v-model="configuration.answerCount"
v-model.number="configuration.answerCount"
:state="configuration.answerCount > 0"
type="number"
/>
Expand All @@ -262,7 +271,7 @@ async function importFile(event: any) {
>
<b-form-input
id="completedRounds-input"
v-model="configuration.minimumCompletedRounds"
v-model.number="configuration.minimumCompletedRounds"
:state="configuration.minimumCompletedRounds > 0"
type="number"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { saveAs } from "file-saver";
import { arrayOf, object, string } from "checkeasy";
import { arrayOf, object, string, optional, int, nullable } from "checkeasy";
import { importConfiguration } from "@/ts/import-configuration";
import { defineEmits, defineProps, ref, watch } from "vue";
import {
Expand Down Expand Up @@ -249,6 +249,7 @@ async function importFile(event: any) {
wrongAnswers: arrayOf(string()),
})
),
volumeLevel: optional(nullable(int())),
});
try {
const result: TowerDefenseConfiguration = await importConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// compatible towercrush versions: v0.0.1
const compatibleVersions = ["v0.0.1"];
import { saveAs } from "file-saver";
import { arrayOf, object, string } from "checkeasy";
import { arrayOf, object, string, optional, int, nullable } from "checkeasy";
import { importConfiguration } from "@/ts/import-configuration";
import { defineEmits, defineProps, ref, watch } from "vue";
import { ITask } from "@/ts/models/overworld-models";
Expand Down Expand Up @@ -250,6 +250,7 @@ async function importFile(event: any) {
wrongAnswers: arrayOf(string()),
})
),
volumeLevel: optional(nullable(int())),
});
try {
const result: TowercrushConfiguration = await importConfiguration(
Expand Down
2 changes: 1 addition & 1 deletion src/ts/import-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function importConfiguration(
toast.error(
"Something went wrong while reading the configuration file!"
);
reject();
reject(new Error("File read error"));
return;
}
try {
Expand Down
12 changes: 8 additions & 4 deletions src/ts/models/regexgame-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,24 @@ export const defaultRegexStructures: Set<RegexStructure> = new Set([
.map((entry) => entry[1] as RegexStructure),
]);

export class RegexGameConfiguration {
export interface IRegexGameConfiguration {
id?: string;

allowedRegexStructures: Set<RegexStructure>;
minimumCompletedRounds: number;
riddleTimeoutSeconds: number;
answerCount: number;
}

export class RegexGameConfiguration implements IRegexGameConfiguration {
id?: string;
allowedRegexStructures: Set<RegexStructure>;
minimumCompletedRounds = 20;

/**
* how many seconds the user has to solve a given riddle
* the timeout will accumulate over the riddles,
* so the remaining time will be carried over to the next riddle
*/
riddleTimeoutSeconds = 10;

answerCount = 3;

constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/ts/rest-clients/regexgame-rest-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import axios, { AxiosResponse } from "axios";

import config from "@/config";

import { RegexGameConfiguration } from "@/ts/models/regexgame-models";
import { IRegexGameConfiguration } from "@/ts/models/regexgame-models";

export async function postRegexGameConfig(
regexgameConfig: RegexGameConfiguration
regexgameConfig: IRegexGameConfiguration
): Promise<AxiosResponse> {
return axios.post(
`${config.regexgameApiUrl}/configurations`,
Expand Down

0 comments on commit 8b80464

Please sign in to comment.