Skip to content

Commit

Permalink
bug(Notes): Varia small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruptein authored Jan 21, 2024
1 parent d1c63de commit 0877596
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
17 changes: 12 additions & 5 deletions client/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export function callbackProvider(): {
};
}

// This only works in HTTPS (or localhost) context!
// It will throw an error otherwise.
async function sha1(source: string): Promise<string> {
const sourceBytes = new TextEncoder().encode(source);
const digest = await crypto.subtle.digest("SHA-1", sourceBytes);
Expand All @@ -107,11 +109,16 @@ const wordMemory = new Map<string, string>();
export async function word2color(word: string): Promise<string> {
const mem = wordMemory.get(word);
if (mem !== undefined) return mem;
const hash = await sha1(word);
const r = parseInt(hash.substring(0, 2), 16);
const g = parseInt(hash.substring(2, 4), 16);
const b = parseInt(hash.substring(4, 6), 16);
const rgb = `rgb(${r}, ${g}, ${b})`;
let rgb;
try {
const hash = await sha1(word);
const r = parseInt(hash.substring(0, 2), 16);
const g = parseInt(hash.substring(2, 4), 16);
const b = parseInt(hash.substring(4, 6), 16);
rgb = `rgb(${r}, ${g}, ${b})`;
} catch {
rgb = "rgba(0, 0, 0, 0.5)";
}
wordMemory.set(word, rgb);
return rgb;
}
3 changes: 3 additions & 0 deletions client/src/game/systems/notes/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { POSITION, useToast } from "vue-toastification";

import type { ApiNote, ApiNoteAccessEdit, ApiNoteSetBoolean, ApiNoteSetString, ApiNoteShape } from "../../../apiTypes";
import SingleButtonToastVue from "../../../core/components/toasts/SingleButtonToast.vue";
import { coreStore } from "../../../store/core";
import { socket } from "../../api/socket";
import { getLocalId } from "../../id";

Expand All @@ -18,6 +19,8 @@ socket.on("Notes.Set", async (notes: ApiNote[]) => {
socket.on("Note.Add", async (data: ApiNote) => {
await noteSystem.newNote(data, false);

if (data.creator === coreStore.state.username) return;

toast.info(
{
component: SingleButtonToastVue,
Expand Down
17 changes: 16 additions & 1 deletion client/src/game/ui/notes/NoteEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function removeShape(shape: LocalId): void {
<font-awesome-icon icon="location-dot" title="Go to shape on the map" />
{{ (shape.name?.length ?? 0) > 15 ? `${shape.name?.slice(0, 12)}...` : shape.name }}
<div style="flex-grow: 1"></div>
<font-awesome-icon icon="trash-alt" title="Remove shape link" @click="removeShape(shape.id)" />
<font-awesome-icon icon="trash-alt" title="Remove shape link" @click.stop="removeShape(shape.id)" />
</div>
</div>
<div v-else id="note-triggers" class="tab-container">
Expand Down Expand Up @@ -503,6 +503,7 @@ header {
padding: 0.5rem;
border: solid 1px transparent;
display: flex;
align-items: center;
> svg:first-child {
margin-right: 0.5rem;
Expand Down Expand Up @@ -534,6 +535,20 @@ header {
}
}
}
button {
background-color: lightblue;
border: solid 2px lightblue;
border-width: 1px;
border-radius: 1rem;
padding: 0.5rem 0.75rem;
margin-left: 1rem;
&:hover {
cursor: pointer;
background-color: rgba(173, 216, 230, 0.5);
}
}
}
#note-triggers {
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/ui/notes/NoteList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function clearShapeFilter(): void {
<footer>
<div style="flex-grow: 1"></div>
<div id="new-note-selector" @click="$emit('mode', NoteManagerMode.Create)">
New note{{ shapeProps ? `for ${shapeProps.name}` : "" }}
New note{{ shapeProps ? ` for ${shapeProps.name}` : "" }}
</div>
</footer>
</template>
Expand Down

0 comments on commit 0877596

Please sign in to comment.