Phaser 3: Change “Hitbox”/Interactive area of sprite without physics

The game I’m creating doesn’t require any physics, however you are able to interact when hovering over/clicking on the sprite by using sprite.setInteractive({cursor: "pointer"});, sprite.on('pointermove', function(activePointer) {...}); and similar. However I noticed two issues with that:

  1. The sprite has some area which are transparent. The interactive functions will still trigger when clicking on those transparent areas, which is unideal.

  2. When playing a sprite animation, the interactive area doesn’t seem to entirely (at all?) change, thus if the sprite ends on a frame bigger than the previous, there end up being small areas I can’t interact with.

One option I thought of was to create a polygon over my sprite, which covers the area I want to be interactive. However before I do that, I simply wanted to ask if there are simpler ways to fix these issues.

Move y-Axis and hide in Chart.JS V3

So I’ve created this chart, and I’m trying to move the axis around so the Dark red is on the left, and the Blue and the sub of the bar charts is displayed, but I’m having trouble moving the dark red to the right side of this graf. I did try to use the position: 'right', but nothing changed.

I’m trying to make it look like this:

axis

But I can only get this:

var canvas = document.createElement('canvas');
    div = document.getElementById('container');
    canvas.id = "myChart";
    canvas.style.zIndex = 8;
    div.appendChild(canvas);
    const labels = [
        '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '1', '2', '3', '4', '5', '6', '7'
    ];

    const data = {
        labels: labels,
        datasets: [{
                label: 'Red',
                backgroundColor: 'rgb(255,0,0)',
                borderColor: 'rgb(255,0,0)',
                data: [3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8],
                stack: 'combined',
                type: 'bar',
                order: 4
            },
            {
                label: 'Yellow',
                backgroundColor: 'rgb(255,255,0)',
                borderColor: 'rgb(255,255,0)',
                data: [0, 2, 2, 0, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                stack: 'combined',
                type: 'bar',
                order: 4
            },
            {
                label: 'Orange',
                backgroundColor: 'rgb(255,159,64)',
                borderColor: 'rgb(255,159,64)',
                data: [9, 21, 21, 0, 21, 21, 21, 21, 18, 18, 18, 18, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
                stack: 'combined',
                type: 'bar',
                order: 4
            },
            {
                label: 'Grey light',
                backgroundColor: 'rgb(224,224,224)',
                borderColor: 'rgb(224,224,224)',
                data: [9, 20, 20, 0, 20, 20, 21, 21, 19, 19, 19, 19, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
                stack: 'combined',
                type: 'bar',
                order: 4
            },
            {
                label: 'Blue',
                backgroundColor: 'rgb(30,144,255)',
                borderColor: 'rgb(30,144,255)',
                data: [328, 421, 421, 0, 421, 421, 422, 422, 344, 344, 344, 344, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328],
                stack: 'combined_first',
                yAxisID: 'Blue',
                order: 1
            },
            {
                label: 'Dark Red',
                backgroundColor: 'rgb(165,42,42)',
                borderColor: 'rgb(165,42,42)',
                data: [0.45, 1.55, 1.55, 0, 1.55, 1.55, 1.55, 1.55, 1.15, 1.15, 1.15, 1.15, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45],
                stack: 'combined_second',
                yAxisID: 'DarkR',
                order: 2
            },
            {
                label: 'Dark Grey',
                backgroundColor: 'rgb(80,80,80)',
                borderColor: 'rgb(80,80,80)',
                data: [18, 43, 43, 0, 43, 43, 44, 44, 38, 38, 38, 38, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18],
                stack: 'combined_third',
                yAxisID: 'GreyD',
                order: 3
            }
        ]
    };

    const config = {
        type: 'line',
        data: data,
        options: {
            plugins: {
                title: {
                    display: true,
                    text: 'WDC History Chart'
                },
                zoom: {
                    zoom: {
                        wheel: {
                            enabled: true,
                        },
                        pinch: {
                            enabled: true
                        },
                        drag: {
                            enabled: true
                        },
                        mode: 'x',
                    }
                }
            },

            scales: {
                y: {
                    stacked: true
                }
            }
        },
    };
    const myChart = new Chart(
        document.getElementById('myChart'),
        config
    );
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div id="container" class="wdc-canvas-size">
</div>

Responsive accessible navigation dropdown issue

I have a responive navigation which has a dropdown that cases me headaches.
Currenlty the navigatio has a event listener mouse over for desktop and on devices has a click event that adds a .is-active class.

For some reason the events aren’t working. I get this error. Uncaught ReferenceError: j is not defined.

I can’t figure it out. I leave the code below. hopefully you gus can help me out to find the issue.

const navBlocks = document.querySelectorAll(".nav-container");
const mediaQuery = window.matchMedia("(min-width: 900px)");
const navBp = "(min-width: 900px)";

let isMenuOpen = false;

for (var i = 0; i < navBlocks.length; i++) {
  const menu = navBlocks[i].querySelector(".sliding-nav .nav-wrap");
  const nav = navBlocks[i].querySelector(".sliding-nav");
  let btn = navBlocks[i].querySelector(".nav-cta");
  let navLinks = navBlocks[i].querySelectorAll(".sliding-nav .nav-items > li");
  //let isSubNavLink = navBlocks[i].querySelector(".has-nav-panel");

  btn.onclick = function (e) {
    e.preventDefault();
    isMenuOpen = !isMenuOpen;
    btn.setAttribute("aria-expanded", String(isMenuOpen));
    menu.hidden = !isMenuOpen;

    if (isMenuOpen) {
      nav.classList.add("is-open");
      document.body.classList.add("is-no-scroll", "is-fixed");
      //console.log(isMenuOpen);
    } else {
      nav.classList.remove("is-open");
      document.body.classList.remove("is-no-scroll", "is-fixed");
      //console.log(!isMenuOpen);
    }
  };

  Array.prototype.forEach.call(navLinks, function (el, i) {
    var currentNavLink = navLinks[i];

    currentNavLink.addEventListener("click", function () {
      megaNavClickAndTouchHandler(navLinks, currentNavLink);
    });

    currentNavLink.addEventListener("mouseover", function () {
      megaNavMouseOverHandler(navLinks, currentNavLink, navBp);
    });

    currentNavLink.addEventListener("mouseleave", function () {
      megaNavMouseLeaveHandler(navLinks, currentNavLink, navBp);
    });

    megaNavResetOnBreakPoint(navLinks, currentNavLink, mediaQuery);
  });

  function megaNavResetOnBreakPoint(elements, currentElement, mqNav) {
    if (matchMedia) {
      var navigationBar = currentElement.closest(".header");
      var navigationItems = currentElement.closest(".sliding-nav");

      mqNav.addListener(function () {
        if (mqNav.matches) {
          document.querySelectorAll("body")[0].classList.remove("is-no-scroll");
          navigationBar.classList.remove("is-active");
          navigationItems.classList.remove("is-active");
          navigationBar
            .querySelectorAll(".burger")[0]
            .classList.remove("is-active");
          megaNavClosePanels(elements);
        } else {
          megaNavClosePanels(elements);
        }
      });
    }
  }

  function megaNavClickAndTouchHandler(elements, currentElement) {
    var isSubNavLink = currentElement.classList.contains("has-nav-panel");
    var isSubNavLinkActive = currentElement.classList.contains("is-active");
    var navBarContainer = currentElement.closest(".header");

    if (!isSubNavLink) {
      window.location = currentElement.firstElementChild.getAttribute("href");
    } else if (isSubNavLink && !isSubNavLinkActive) {
      megaNavClosePanels(elements);
      currentElement.classList.add("is-active");
    } else {
      megaNavClosePanels(elements);
    }
  }
  function megaNavClosePanels(elements) {
    for (j = 0; j < elements.length; j++) {
      if (elements[j].classList.contains("has-nav-panel")) {
        elements[j].classList.remove("is-active");
      }
    }
  }
  function megaNavMouseOverHandler(elements, currentElement, breakPoint) {
    if (window.innerWidth >= breakPoint) {
      var isSubNavLink = currentElement.classList.contains("has-nav-panel");

      megaNavClosePanels(elements);
      currentElement.classList.add("is-active");
    }
  }

  function megaNavMouseLeaveHandler(elements, currentElement, breakPoint) {
    if (window.innerWidth >= breakPoint) {
      currentElement.classList.remove("is-active");
    }
  }

  function handleTabletChange(e) {
    // Check if the media query is true

    if (e.matches) {
      console.log("desktop");
      btn.setAttribute("aria-expanded", false);
      menu.removeAttribute("hidden");
      nav.classList.remove("is-open");
      document.body.classList.remove("is-no-scroll", "is-fixed");
    } else {
      console.log("mobile");
      btn.setAttribute("aria-expanded", false);
    }
  }

  // Register event listener
  mediaQuery.addListener(handleTabletChange);

  // Initial check
  handleTabletChange(mediaQuery);

  // TRAP TAB INSIDE NAV WHEN OPEN
  nav.addEventListener("keydown", (e) => {
    // abort if menu isn't open or modifier keys are pressed
    if (!isMenuOpen || e.ctrlKey || e.metaKey || e.altKey) {
      return;
    }

    // listen for tab press and move focus
    // if we're on either end of the navigation
    const menuLinks = menu.querySelectorAll(".nav-link");
    if (e.keyCode === 9) {
      if (e.shiftKey) {
        if (document.activeElement === menuLinks[0]) {
          menuToggle.focus();
          e.preventDefault();
        }
      } else if (document.activeElement === menuToggle) {
        menuLinks[0].focus();
        e.preventDefault();
      }
    }
  });
}

demo in codepen, please fork it to modify

One of attribute lost data when assign javascript object

I spend a day for investigating this case, but seen no hope.

const Tests = (state = INIT_STATE, action) => {
switch (action.type) {
case GET_TEST_DETAIL:
return {
…state,
test: {},
error: {},
updatingTest: true,
}

    case GET_TEST_DETAIL_SUCCESS:
        const test = action.payload
        console.log(action.payload.shortName)//has data
        test["shortName2"] = action.payload.shortName//has data
        test["shortName"] = action.payload.shortName//empty string

        console.log(test)

        return {
            ...state,
            test: test,
            updatingTest: false,
        }

There is the picture captured when I console.log in firefox, and Edge:
enter image description here

How to use assets folder to load images with dynamic path in Nuxt?

I am using the latest Nuxt 2 version and I want to have my images cached and preload them before animation, static folder doesn’t allow me to cache images because this folder is not parsed by webpack, so for that documentation says that I should use assets folder and let webpack parse it for me, the problem is that everything works with static path for the images when I want to add src dynamically my whole path is copied over and it’s no longer using webpack for this.

This works:

<img class="lady" src="~/assets/lady/lady_001.png" />

Result: http://localhost:3000/_nuxt/assets/lady/lady_001.png

This not:

<img class="lady" :src="activeImage" alt="" />

Result: http://localhost:3000/~/assets/lady/lady_124.png

...
computed: {
    activeImage() {
      return `~/assets/lady/lady_${this.activeTimeline}.png`;
    },
  },

activeTimeline is just sequence of number from 000 to 180 converted to string. Is there any way to achieve this or I am forced to use some external library for caching static content?

JavaScript Date UTC datetime-local

I have a form where user can introduce date and time with input format datetime-local. When the form is summited a problem appears for the start-date “Value must 11:52 AM or earlier”, my local time is 13:52″. So i have to select -2 hours. How can I remove this problem. The form is limited for the start date to select only today and last 72 hours, same for end time.
The code is the following:

 <input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
 <input type="datetime-local" name="end_timestamp" id="end_timestamp" required>

<script>
    //Do not let to select END-TIME and START TIME  in the PAST
    var today = new Date();
    var past = new Date(today.setDate(today.getDate() - 3)).toISOString().slice(0, 16);
    var today = new Date().toISOString().slice(0, 16);

    document.getElementsByName("start_timestamp")[0].min = past;
    document.getElementsByName("start_timestamp")[0].max = today;
</script>

<script>
    var today = new Date();
    var future = new Date(today.setDate(today.getDate() + 3)).toISOString().slice(0, 16);
    var today = new Date().toISOString().slice(0, 16);

    document.getElementsByName("end_timestamp")[0].min = today;
    document.getElementsByName("end_timestamp")[0].max = future;
</script>

I have an image also:

enter image description here

firestore query wait for nested foreach loop

I’m trying to populate an array with names from all documents in a collection, and also populate another array with all the subcollection documents from those parent documents.

  let data = []
  let names = []
  
  const suppliers = await db.collection('suppliers').get()
  
  suppliers.forEach(async supplier => {

    names.push({name: supplier.data().name, id: supplier.id })

    const deliveries = await db.collection('suppliers').doc(supplier.id).collection('deliveries').get()
    
    deliveries.forEach(delivery => {
      
      data.push(delivery.data())
    })
  })

  console.log(names) // Populated
  console.log(data) // Empty

The problem is that it doesn’t wait for the inner loop to finish before executing the code outside. The names array gets populated but the the data array is empty. How can i make the nested loop finish before executing the outside code?

How to pass a value between two different nodejs functions called by 2 different graphql mutations?

I’m trying to pass the data between two things. I will now explain it in detail. First graphql query calls a function func1() which is like

func1(){
  const a = await func2();
  return a;
}

func2(){
  return 7;
}

func3(value){
  return value
}

this func2 is returning an integer for example 7. For now I was using console input but now I want to get this result from another graphql mutation which calls a function func3(). I pass the required value for example 7 in the graphql mutation arguments which gets passed to function func3. How can I wait for this func3’s value in func1? Please help and if you want me to elaborate any specific thing, I’d be happy to do so.

Mocha async with await

According to this https://mochajs.org/#using-async-await when using await to test async function, there is no need to call done(). But with my code below it is complaining
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
I don’t want to use the hack to increase timeout.

describe('test', function () {
  it('upload all', async () => {
    const c = await setup();
    const files = await Test(c);
    expect(files.length).to.equal(3); 
  })
})

Any help is much appreciated

Each value can’t be stored in a variable?

You can keep almost anything in variables just by assigning the new value for a named variable with an equal sign. Also, following PEP 8, one space before and after the assignment sign is considered good practice.

Does someone know some value that is not allowed?

Thanks

React Router without Hooks – ID dynamic routes

i’m totally beginner in react.
I tried to improve my skill day after day.
Today im stuck on problem, i want to create dynamic route with JSON characters (here dragon ball z)
My routes are correct but i want to show biography on only clicked characters like “i click on goku show goku bio”
I want to make it without REACT HOOKS (dont useLocation, useParams ect..).
At moment i’m totally stuck

Can you help me ? how can i do?

Thanks for help 🙂

here is the blitzstack of my project:

REACT ROUTER DBZ EXERCICE – WITHOUT HOOKS

React MUI 4 SelectInput.js:340 Uncaught TypeError: Cannot read properties of undefined (reading ‘value’)

This error happens when you provide an empty array as options.

The error log:

SelectInput.js:340 Uncaught TypeError: Cannot read properties of undefined (reading 'value')
    at SelectInput.js:340:1
    at Array.map (<anonymous>)
    at SelectInput.js:339:1
    at invokePassiveEffectCreate (react-dom.development.js:23487:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
    at invokeGuardedCallback (react-dom.development.js:4056:1)
    at flushPassiveEffectsImpl (react-dom.development.js:23574:1)
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushPassiveEffects (react-dom.development.js:23447:1)
    at performSyncWorkOnRoot (react-dom.development.js:22269:1)
    at react-dom.development.js:11327:1
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11322:1)
    at flushSyncCallbackQueue (react-dom.development.js:11309:1)
    at flushPassiveEffectsImpl (react-dom.development.js:23620:1)
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushPassiveEffects (react-dom.development.js:23447:1)
    at react-dom.development.js:23324:1
    at workLoop (scheduler.development.js:417:1)
    at flushWork (scheduler.development.js:390:1)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js:157:1)