Skip to content

Commit

Permalink
added ranges in int parser and fixed xyz parser
Browse files Browse the repository at this point in the history
  • Loading branch information
vytdev committed Jun 18, 2024
1 parent cd1f18e commit c832ba7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/catalyst/core/cmdparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,28 @@ registerCommandTypeParser('int', (argv, argDef) => {
err.token = argv[0];
throw err;
}
return { value: +argv[0]?.text };

// range
const val = +argv[0]?.text;
if (argDef.range) {
const range: [number | null, number | null] = argDef.range;

// min range
if (typeof range[0] == 'number' && val < range[0]) {
const err = new CommandError(`${val} is too low, it must be atleast ${range[0]}`);
err.token = argv[0];
throw err;
}

// max range
if (typeof range[1] == 'number' && val > range[1]) {
const err = new CommandError(`${val} is too high, it must be atmost ${range[1]}`);
err.token = argv[0];
throw err;
}
}

return { value: val };
});

registerCommandTypeParser('boolean', (argv, argDef) => {
Expand Down Expand Up @@ -549,21 +570,21 @@ registerCommandTypeParser('xyz', (argv, argDef) => {
}

function handleFn(org: vec3, rot: vec2): vec3 {
let finalX = org.x;
let finalY = org.y;
let finalZ = org.z;
let finalX = x;
let finalY = y;
let finalZ = z;

// radians of thr rot
const pitch = degToRad(rot.x);
const yaw = degToRad(rot.y);

// compute modifiers
if (xRel) finalX += x;
if (xRot) finalX += x * Math.cos(pitch) * -Math.sin(yaw);
if (yRel) finalY += y;
if (yRot) finalY += y * -Math.sin(pitch);
if (zRel) finalZ += z;
if (zRot) finalZ += z * Math.cos(pitch) * Math.cos(yaw);
if (xRel) finalX = org.x + x;
if (xRot) finalX = org.x + x * Math.cos(pitch) * -Math.sin(yaw);
if (yRel) finalY = org.y + y;
if (yRot) finalY = org.y + y * -Math.sin(pitch);
if (zRel) finalZ = org.z + z;
if (zRot) finalZ = org.z + z * Math.cos(pitch) * Math.cos(yaw);

return {
x: finalX,
Expand Down
1 change: 1 addition & 0 deletions src/server/commands/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const info: commandSub = {
name: "lineCount",
dest: "lines",
type: "int",
range: [ 1, null ],
default: 100,
}
]
Expand Down
1 change: 1 addition & 0 deletions src/server/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const info: commandSub = {
type: "int",
name: "page",
dest: "page",
range: [ 0, null ],
required: false,
default: 1,
}
Expand Down

0 comments on commit c832ba7

Please sign in to comment.