Skip to content

Commit

Permalink
Reduce linewidth type to uint8, since that's enough, as it doesn't ne…
Browse files Browse the repository at this point in the history
…ed to be sacled anyway.
  • Loading branch information
Bios-Marcel committed Nov 16, 2024
1 parent 7d1b490 commit 8dec5c8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
17 changes: 7 additions & 10 deletions internal/frontend/templates/lobby.html
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@
const offsetY = (touch.clientY - clientRect.top);

// drawing functions must check for context boundaries
drawLineAndSendEvent(context, lastX, lastY, offsetX, offsetY, localColor, localLineWidth);
drawLineAndSendEvent(context, lastX, lastY, offsetX, offsetY);
lastX = offsetX;
lastY = offsetY;

Expand Down Expand Up @@ -1868,7 +1868,7 @@
const offsetY = (event.clientY - clientRect.top);

// drawing functions must check for context boundaries
drawLineAndSendEvent(context, lastX, lastY, offsetX, offsetY, localColor, localLineWidth);
drawLineAndSendEvent(context, lastX, lastY, offsetX, offsetY);
lastX = offsetX;
lastY = offsetY;
}
Expand All @@ -1882,8 +1882,7 @@
if (localTool === fillBucket) {
fillAndSendEvent(context, event.offsetX, event.offsetY, localColor);
} else {
drawLineAndSendEvent(context, event.offsetX, event.offsetY,
event.offsetX, event.offsetY, localColor, localLineWidth);
drawLineAndSendEvent(context, event.offsetX, event.offsetY, event.offsetX, event.offsetY);
}
}
}
Expand Down Expand Up @@ -2029,12 +2028,10 @@
}
}

function drawLineAndSendEvent(context, x1, y1, x2, y2, color, lineWidth) {
if (localTool === rubber) {
color = rubberColor;
}
function drawLineAndSendEvent(context, x1, y1, x2, y2) {
const color = localTool === rubber ? rubberColor : localColor;

drawLine(context, x1, y1, x2, y2, color, lineWidth);
drawLine(context, x1, y1, x2, y2, color, localLineWidth);

const drawInstruction = {
type: "line",
Expand All @@ -2044,7 +2041,7 @@
toX: scaelUpAndPrepareFloatForServer(x2),
toY: scaelUpAndPrepareFloatForServer(y2),
color: color,
lineWidth: scaelUpAndPrepareFloatForServer(lineWidth),
lineWidth: localLineWidthUnscaled,
}
};
socket.send(JSON.stringify(drawInstruction));
Expand Down
4 changes: 2 additions & 2 deletions internal/game/lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func (lobby *Lobby) HandleEvent(eventType string, payload []byte, player *Player

// In case the line is too big, we overwrite the data of the event.
// This will prevent clients from lagging due to too thick lines.
if line.Data.LineWidth > float32(MaxBrushSize) {
if line.Data.LineWidth > MaxBrushSize {
line.Data.LineWidth = MaxBrushSize
} else if line.Data.LineWidth < float32(MinBrushSize) {
} else if line.Data.LineWidth < MinBrushSize {
line.Data.LineWidth = MinBrushSize
}

Expand Down
2 changes: 1 addition & 1 deletion internal/game/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type LineEvent struct {
ToX float32 `json:"toX"`
ToY float32 `json:"toY"`
Color RGBColor `json:"color"`
LineWidth float32 `json:"lineWidth"`
LineWidth uint8 `json:"lineWidth"`
} `json:"data"`
}

Expand Down
8 changes: 4 additions & 4 deletions internal/game/shared_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/game/words.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"embed"
"errors"
"fmt"
"log"
"math/rand/v2"
"strings"
"unicode/utf8"
Expand Down Expand Up @@ -96,6 +97,8 @@ func readWordListInternal(
// a panic before, however, this could enable a user to forcefully crash the
// whole application.
func readDefaultWordList(lowercaser cases.Caser, chosenLanguage string) ([]string, error) {
log.Printf("Loading wordlist '%s'\n", chosenLanguage)
defer log.Printf("Wordlist loaded '%s'\n", chosenLanguage)
return readWordListInternal(lowercaser, chosenLanguage, func(key string) (string, error) {
wordBytes, err := wordFS.ReadFile("words/" + key)
if err != nil {
Expand Down

0 comments on commit 8dec5c8

Please sign in to comment.