Skip to content

Commit

Permalink
fix #49
Browse files Browse the repository at this point in the history
  • Loading branch information
Govorunb committed Jun 20, 2024
1 parent 535498d commit e7da16c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type EnumParam = ParameterBase & {

export type VectorParam = ParameterBase & {
type: LiteralTypes.Vector;
defaultValues?: number[];
defaultValue?: [number, number, number];
min?: number[];
max?: number[];
};
Expand Down
3 changes: 1 addition & 2 deletions ebs/src/modules/game/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isStressTesting, startStressTest, StressTestRequest } from "./stresstes

export let connection: GameConnection = new GameConnection();

app.ws("/private/socket", (ws, req) => {
app.ws("/private/socket", (ws) => {
connection.setSocket(ws);
});

Expand Down Expand Up @@ -36,7 +36,6 @@ app.post(
);

app.post("/private/setresult", (req, res) => {
//console.log(req.body);
const msg = {
...connection.makeMessage(MessageType.Result),
...req.body,
Expand Down
30 changes: 18 additions & 12 deletions frontend/www/src/modules/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const $modalConfirm = document.getElementById("modal-confirm")! as HTMLButtonEle
const $modalCancel = document.getElementById("modal-cancel")! as HTMLButtonElement;

/* Options */
const $modalOptionsForm: HTMLFormElement = document.getElementById("modal-options-form")! as HTMLFormElement;
const $modalOptionsForm = document.getElementById("modal-options-form")! as HTMLFormElement;
const $modalOptions = document.getElementById("modal-options")!;
const $paramToggle = document.getElementById("modal-toggle")!;
const $paramText = document.getElementById("modal-text")!;
Expand Down Expand Up @@ -196,13 +196,16 @@ function checkForm() {

function setCartArgsFromForm(form: HTMLFormElement) {
const formData = new FormData(form);
formData.forEach((v, k) => {
if (k.endsWith("[]")) {
k = k.slice(0, -2);

if (!cart!.args[k]) cart!.args[k] = [];
cart!.args[k].push(v);
} else cart!.args[k] = v;
formData.forEach((val, name) => {
const match = /(?<paramName>\w+)\[(?<index>\d{1,2})\]$/.exec(name);
if (!match?.length) {
cart!.args[name] = val;
} else {
const paramName = match.groups!["paramName"];
cart!.args[paramName] ??= [];
const index = parseInt(match.groups!["index"]);
cart!.args[paramName][index] = val;
}
});
}

Expand Down Expand Up @@ -361,15 +364,18 @@ function addVector(modal: HTMLElement, param: VectorParam) {
input.min = param.min?.toString() ?? "";
input.max = param.max?.toString() ?? "";

setupField(field, input, param, true);
setupField(field, input, param, i);

if (Number.isFinite((param.defaultValues ?? [])[i])) input.value = (param.defaultValues ?? [])![i]!.toString();
const defVal = param.defaultValue?.[i];
input.value = Number.isFinite(defVal)
? defVal!.toString()
: "0";
}

modal.appendChild(field);
}

function setupField(field: HTMLElement, inputElem: HTMLSelectElement | HTMLInputElement, param: Parameter, isArray?: boolean) {
function setupField(field: HTMLElement, inputElem: HTMLSelectElement | HTMLInputElement, param: Parameter, arrayIndex?: number) {
const label = field.querySelector("label")!;

field.id += "-" + param.name;
Expand All @@ -379,7 +385,7 @@ function setupField(field: HTMLElement, inputElem: HTMLSelectElement | HTMLInput
}

inputElem.id += "-" + param.name;
inputElem.name = param.name.concat(isArray !== undefined ? "[]" : "");
inputElem.name = param.name.concat(arrayIndex !== undefined ? `[${arrayIndex}]` : "");

label.id += "-" + param.name;
label.htmlFor = inputElem.id;
Expand Down

0 comments on commit e7da16c

Please sign in to comment.