Skip to content

Commit c292721

Browse files
authored
sounds; draggable console (#256)
1 parent 33bb888 commit c292721

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

src/_includes/footer.njk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@
6767
</div>
6868

6969
<div class="space-y-1 mb-2">
70-
<button onclick="addExperience(5)" class="w-full flex justify-between px-2 py-1 bg-cyan-500/5 text-cyan-400 text-[8px] border border-cyan-500/20 rounded">
70+
<button onclick="addExperience(5); playSound('click');" class="w-full flex justify-between px-2 py-1 bg-cyan-500/5 text-cyan-400 text-[8px] border border-cyan-500/20 rounded">
7171
<span>💎 SKILL_MINER</span>
7272
<span class="opacity-50">+5</span>
7373
</button>
7474
<button onclick="addExperience(15); playSound('restore');" class="w-full flex justify-between px-2 py-1 bg-pink-500/5 text-pink-400 text-[8px] border border-pink-500/20 rounded">
7575
<span>🛠️ SYS_OPTIMIZE</span>
7676
<span class="opacity-50">+15</span>
7777
</button>
78-
<button onclick="triggerMagicXP()" class="w-full flex justify-between px-2 py-1.5 bg-gradient-to-r from-purple-600/20 to-blue-600/20 text-purple-400 text-[8px] border border-purple-500/30 rounded hover:from-purple-600/40 hover:to-blue-600/40 transition-all group">
78+
<button onclick="triggerMagicXP(); playSound('levelUp');" class="w-full flex justify-between px-2 py-1.5 bg-gradient-to-r from-purple-600/20 to-blue-600/20 text-purple-400 text-[8px] border border-purple-500/30 rounded hover:from-purple-600/40 hover:to-blue-600/40 transition-all group">
7979
<span>✨ CAST_MAGIC_XP</span>
8080
<span class="group-hover:animate-pulse">+50 XP</span>
8181
</button>
@@ -130,8 +130,8 @@
130130
<div id="matrix-console-container" class="fixed bottom-6 right-6 w-80 z-[1000] transition-all duration-300 ease-in-out">
131131
<div class="bg-black/90 backdrop-blur-xl border border-green-500/30 rounded-t-lg overflow-hidden shadow-2xl">
132132

133-
<div class="bg-green-500/10 border-b border-green-500/30 px-3 py-2 flex justify-between items-center cursor-default select-none">
134-
<div class="flex items-center gap-2">
133+
<div class="bg-green-500/10 border-b border-green-500/30 px-3 py-2 flex justify-between items-center cursor-grab select-none">
134+
<div class="flex items-center gap-2">
135135
<span class="text-[10px] font-mono text-green-500 uppercase tracking-widest opacity-70">System_Log</span>
136136
</div>
137137

@@ -142,7 +142,7 @@
142142
</div>
143143
</div>
144144

145-
<div id="matrix-console-output" class="h-48 p-3 overflow-y-auto font-mono text-[11px] leading-tight transition-all duration-300">
145+
<div id="matrix-console-output" class="h-48 p-3 overflow-y-auto font-mono text-[11px] leading-tight">
146146
<p class="text-green-500/40">// Terminal link established...</p>
147147
</div>
148148
</div>

src/assets/css/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,3 +730,11 @@ a:hover {
730730
background-size: 100% 2px, 3px 100%;
731731
pointer-events: none;
732732
}
733+
.cursor-grab:active {
734+
cursor: grabbing;
735+
}
736+
737+
/* Prevents the terminal text from getting highlighted while you move the window */
738+
#matrix-console-container.is-dragging {
739+
user-select: none;
740+
}

src/assets/js/script.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,51 @@ function getRank(lvl) {
358358
const consoleContainer = document.getElementById('matrix-console-container');
359359
const consoleOutput = document.getElementById('matrix-console-output');
360360

361+
const dragContainer = document.getElementById('matrix-console-container');
362+
const dragHeader = dragContainer.querySelector('.bg-green-500\\/10'); // Selects the header bar
363+
364+
let isDragging = false;
365+
let offsetLeft = 0;
366+
let offsetTop = 0;
367+
368+
dragHeader.addEventListener('mousedown', (e) => {
369+
// Prevent dragging when clicking the minimize/close buttons
370+
if (e.target.tagName === 'BUTTON') return;
371+
372+
isDragging = true;
373+
374+
// Calculate where the mouse is relative to the top-left of the console
375+
const rect = dragContainer.getBoundingClientRect();
376+
offsetLeft = e.clientX - rect.left;
377+
offsetTop = e.clientY - rect.top;
378+
379+
// Change cursor to indicate moving
380+
dragHeader.style.cursor = 'grabbing';
381+
});
382+
383+
document.addEventListener('mousemove', (e) => {
384+
if (!isDragging) return;
385+
386+
// Calculate new position
387+
let x = e.clientX - offsetLeft;
388+
let y = e.clientY - offsetTop;
389+
390+
// Boundary Check (Optional: keeps it inside the screen)
391+
x = Math.max(0, Math.min(x, window.innerWidth - dragContainer.offsetWidth));
392+
y = Math.max(0, Math.min(y, window.innerHeight - dragContainer.offsetHeight));
393+
394+
// Apply position and remove Tailwind's 'bottom' and 'right' so they don't fight the 'top'/'left'
395+
dragContainer.style.bottom = 'auto';
396+
dragContainer.style.right = 'auto';
397+
dragContainer.style.left = `${x}px`;
398+
dragContainer.style.top = `${y}px`;
399+
});
400+
401+
document.addEventListener('mouseup', () => {
402+
isDragging = false;
403+
dragHeader.style.cursor = 'grab';
404+
});
405+
361406
function minimizeConsole() {
362407
// Toggles the height of the output area
363408
if (consoleOutput.style.display === 'none') {

0 commit comments

Comments
 (0)