Toby Chui 1 неделя назад
Родитель
Сommit
852cee8569
4 измененных файлов с 26 добавлено и 19 удалено
  1. 5 2
      src/web/Blocky/README.md
  2. 3 3
      src/web/Blocky/js/game.js
  3. 4 1
      src/web/Blocky/js/player.js
  4. 14 13
      src/web/Blocky/js/ui.js

+ 5 - 2
src/web/Blocky/README.md

@@ -637,8 +637,11 @@ the HTML interface (hotbar, chat) is not part of it.
 
 ## Creative palette
 
-Clicking a held stack onto the item grid, or dragging a stack from a slot
-and letting go over it, deletes the stack like the bin does.
+Clicking an item in the grid takes one on the cursor, and each further click
+on it one more; Shift click takes a whole stack on the cursor. Clicking a held
+stack of anything else onto the item grid, or dragging a stack from a slot and
+letting go over it, deletes the stack like the bin does, and so does Shift
+clicking a hotbar slot.
 
 ## Pick block
 

+ 3 - 3
src/web/Blocky/js/game.js

@@ -782,7 +782,7 @@ export class Game {
         }
 
         //Bow: hold to draw, let go to shoot
-        const useBlock = rightClick && hit && BLOCKS[hit.id].interact && !p.sneaking;
+        const useBlock = rightClick && hit && BLOCKS[hit.id].interact && !p.shiftHeld;
         if (held && held.id === I.BOW && !useBlock) {
             if (rightDown) {
                 if (this.creative || this.inventory.count(I.ARROW) > 0) {
@@ -797,7 +797,7 @@ export class Game {
         this.bowDraw = 0;
 
         //Eating
-        if (rightDown && heldDef && heldDef.food && !this.creative && p.food < 20 && !(hit && BLOCKS[hit.id].interact && !p.sneaking)) {
+        if (rightDown && heldDef && heldDef.food && !this.creative && p.food < 20 && !(hit && BLOCKS[hit.id].interact && !p.shiftHeld)) {
             this.eatT += dt;
             this.eatSound -= dt;
             if (this.eatSound <= 0) {
@@ -1018,7 +1018,7 @@ export class Game {
         const p = this.player, inv = this.inventory, w = this.world;
         const held = inv.held;
         const it = held && ITEMS[held.id];
-        if (rawHit && BLOCKS[rawHit.id].interact && !p.sneaking) {
+        if (rawHit && BLOCKS[rawHit.id].interact && !p.shiftHeld) {
             this.interactBlock(rawHit);
             return;
         }

+ 4 - 1
src/web/Blocky/js/player.js

@@ -46,6 +46,8 @@ export class Player {
         this.onLadder = false;
         this.flying = false;
         this.sneaking = false;
+        //Shift is down, also while flying (where it sinks instead of sneaks)
+        this.shiftHeld = false;
         this.sprinting = false;
         this.horizontalHit = false;
         this.fallDistance = 0;
@@ -135,7 +137,8 @@ export class Player {
         if (!this.creative) {
             this.flying = false;
         }
-        this.sneaking = !!input.sneak && !this.flying;
+        this.shiftHeld = !!input.sneak;
+        this.sneaking = this.shiftHeld && !this.flying;
         const canSprint = this.creative || this.food > 6 || this.difficulty === 0;
         if (input.sprint && input.forward > 0 && !this.sneaking && canSprint) {
             this.sprinting = true;

+ 14 - 13
src/web/Blocky/js/ui.js

@@ -197,8 +197,10 @@ export class UI {
                 this.dragging = !!this.cursor;
                 return;
             }
-            //Creative: whatever is held and clicked onto the palette is gone
-            if (this.cursor && e.target.closest(".palette")) {
+            //Creative: whatever is held and clicked onto the palette is gone,
+            //unless it is the item clicked, which takes one more
+            const onPal = e.target.closest(".pal");
+            if (this.cursor && e.target.closest(".palette") && !(onPal && Number(onPal.dataset.id) === this.cursor.id)) {
                 e.preventDefault();
                 this.cursor = null;
                 this.after();
@@ -844,8 +846,13 @@ export class UI {
 
     quickMove(ref) {
         const s = this.getStack(ref);
-        //Creative only shows the hotbar, so there is nowhere to move things to
-        if (!s || this.screen.kind === "creative") {
+        if (!s) {
+            return;
+        }
+        //Creative only shows the hotbar, so there is nowhere to move things
+        //to: the stack is deleted instead
+        if (this.screen.kind === "creative") {
+            this.setStack(ref, null);
             return;
         }
         const range = (p, a, b) => {
@@ -878,16 +885,10 @@ export class UI {
         }
     }
 
+    //One on the cursor (one more each click), Shift a whole stack on the cursor
     paletteClick(id, button, shift) {
-        if (this.cursor && button === 0 && this.cursor.id !== id) {
-            this.cursor = null;
-        } else if (shift) {
-            this.game.inventory.add(id, maxStack(id));
-        } else if (this.cursor && this.cursor.id === id && button === 0) {
-            this.cursor.count = Math.min(maxStack(id), this.cursor.count + 1);
-        } else {
-            this.cursor = { id, count: button === 2 ? 1 : maxStack(id), dmg: 0 };
-        }
+        const held = this.cursor ? this.cursor.count : 0;
+        this.cursor = { id, count: shift ? maxStack(id) : Math.min(maxStack(id), held + 1), dmg: 0 };
         this.after();
     }