Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: roundup #234

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions packages/server/assets/ingame.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,91 +91,103 @@
<input
type="number"
class="input2"
v-model="overlays[context_overlay.index].width"
@input="overlays[context_overlay.index].width = round_up($event.target.value)"
:value="overlays[context_overlay.index].width"
/>
<input
type="range"
class="input2"
:min="10"
:max="max_width - overlays[context_overlay.index].left"
v-model="overlays[context_overlay.index].width"
@input="overlays[context_overlay.index].width = round_up($event.target.value)"
:value="overlays[context_overlay.index].width"
/>
</div>
<div class="cm-label">
<span>height</span>
<input
type="number"
class="input2"
v-model="overlays[context_overlay.index].height"
@input="overlays[context_overlay.index].height = round_up($event.target.value)"
:value="overlays[context_overlay.index].height"
/>
<input
type="range"
class="input2"
:min="10"
:max="max_height - overlays[context_overlay.index].top"
v-model="overlays[context_overlay.index].height"
@input="overlays[context_overlay.index].height = round_up($event.target.value)"
:value="overlays[context_overlay.index].height"
/>
</div>
<div class="cm-label">
<span>top</span>
<input
type="number"
class="input2"
v-model="overlays[context_overlay.index].top"
@input="overlays[context_overlay.index].top = round_up($event.target.value)"
:value="overlays[context_overlay.index].top"
/>
<input
type="range"
class="input2"
:min="0"
:max="max_height - overlays[context_overlay.index].height"
v-model="overlays[context_overlay.index].top"
@input="overlays[context_overlay.index].top = round_up($event.target.value)"
:value="overlays[context_overlay.index].top"
/>
</div>
<div class="cm-label">
<span>left</span>
<input
type="number"
class="input2"
v-model="overlays[context_overlay.index].left"
@input="overlays[context_overlay.index].left = round_up($event.target.value)"
:value="overlays[context_overlay.index].left"
/>
<input
type="range"
class="input2"
:min="0"
:max="max_width - overlays[context_overlay.index].width"
v-model="overlays[context_overlay.index].left"
@input="overlays[context_overlay.index].left = round_up($event.target.value)"
:value="overlays[context_overlay.index].left"
/>
</div>
<div class="cm-label">
<span>scale</span>
<input
type="number"
class="input2"
v-model="overlays[context_overlay.index].scale"
@input="overlays[context_overlay.index].scale = round_up($event.target.value)"
:value="overlays[context_overlay.index].scale"
/>
<input
type="range"
class="input2"
:min="0.1"
:max="Math.ceil((max_width / overlays[context_overlay.index].width * 100)) / 100"
step="0.1"
v-model="overlays[context_overlay.index].scale"
@input="overlays[context_overlay.index].scale = round_up($event.target.value)"
:value="overlays[context_overlay.index].scale"
/>
</div>
<div class="cm-label">
<span>z-index</span>
<input
type="number"
class="input2"
v-model="overlays[context_overlay.index].z_index"
@input="overlays[context_overlay.index].z_index = round_up($event.target.value)"
:value="overlays[context_overlay.index].z_index"
/>
<input
type="range"
class="input2"
:min="0"
:max="999"
step="1"
v-model="overlays[context_overlay.index].z_index"
@input="overlays[context_overlay.index].z_index = round_up($event.target.value)"
:value="overlays[context_overlay.index].z_index"
/>
</div>
</div>
Expand Down
25 changes: 16 additions & 9 deletions packages/server/assets/ingame.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ const app = createApp({
};


function round_up(value) {
if (value == null || value == '') return 0;

const num = parseFloat(value);
return Number.isFinite(num) ? +num.toFixed(4) : 0;
};

function side_decide(event, is_resize) {
if (is_dragging && is_resize != true) return;
Expand Down Expand Up @@ -308,7 +314,7 @@ const app = createApp({
const scale = initial_scale + offset_x / client_rect.width;
if (scale < 0.1) return;

find.scale = scale;
find.scale = round_up(scale);
return;
};

Expand All @@ -322,8 +328,8 @@ const app = createApp({


if (width >= 10 && left + width <= max_width.value) {
find.left = Math.max(0, left);
find.width = Math.max(10, width / initial_scale);
find.left = round_up(Math.max(0, left));
find.width = round_up(Math.max(10, width / initial_scale));

// element.style.left = `${Math.max(0, left)}px`;
// element.style.width = `${Math.max(10, width / initial_scale)}px`;
Expand All @@ -334,7 +340,7 @@ const app = createApp({
else if (resize_direction.right) {
const width = initial_width + offset_x;
if (initial_left + width <= max_width.value) {
find.width = Math.max(10, width / initial_scale);
find.width = round_up(Math.max(10, width / initial_scale));
// element.style.width = `${Math.max(10, width / initial_scale)}px`;

// console.log('right', initial_scale, element.style.width);
Expand All @@ -347,8 +353,8 @@ const app = createApp({
const top = initial_top + offset_y;

if (height >= 10 && top + height <= max_height.value) {
find.height = Math.max(10, height / initial_scale);
find.top = Math.max(0, top);
find.height = round_up(Math.max(10, height / initial_scale));
find.top = round_up(Math.max(0, top));
// element.style.height = `${Math.max(10, height / initial_scale)}px`;
// element.style.top = `${Math.max(0, top)}px`;

Expand All @@ -358,7 +364,7 @@ const app = createApp({
else if (resize_direction.bottom) {
const height = initial_height + offset_y;
if (initial_top + height <= max_height.value) {
find.height = Math.max(10, height / initial_scale);
find.height = round_up(Math.max(10, height / initial_scale));
// element.style.height = `${Math.max(10, height / initial_scale)}px`;

// console.log('bottom', initial_scale, element.style.height);
Expand Down Expand Up @@ -436,8 +442,8 @@ const app = createApp({
return;
};

find.top = Math.max(0, Math.min(max_height.value - element_height, initial_top + offset_y));
find.left = Math.max(0, Math.min(max_width.value - element_width, initial_left + offset_x));
find.top = round_up(Math.max(0, Math.min(max_height.value - element_height, initial_top + offset_y)));
find.left = round_up(Math.max(0, Math.min(max_width.value - element_width, initial_left + offset_x)));

// console.log('move', { offset_x, offset_y, element_width, element_height });
});
Expand Down Expand Up @@ -738,6 +744,7 @@ const app = createApp({
side_decide, enable_drag, stop_drag,
add_overlay, reset_overlay, remove_overlay,
reset_hover,
round_up,
};
},
});
Expand Down
Loading