samelhusseini / pxt-holidays

A Holiday Card sample target embedding PXT inside a React web app
https://samelhusseini.github.io/pxt-holidays/controller.html
MIT License
41 stars 10 forks source link

Can't add/change name of block categories #7

Closed NoobDoesMC closed 5 years ago

NoobDoesMC commented 5 years ago

Remove hideCategories line from pxtarget.json

Try adding

//% color=190 weight=100 icon="\uf1ec" block="Test"
namespace pxsim.test {
  //% blockId=return_one block="return one"
  export function sayit(): number {
    return 1;
  }
}

to sim/api.ts and then pxt serve.

It makes a new grey category that crashes the toolbar when it is clicked

screenshot 2018-12-11 at 21 00 22 screenshot 2018-12-11 at 21 00 28

samelhusseini commented 5 years ago

So a couple of things here. Looks like there's a bug with the default namespace color if it's not set which I can fix in pxt-core, but there's a workaround.

Add the following in libs/ns.ts


//% color=190
namespace test {

}
NoobDoesMC commented 5 years ago

@samelhusseini that workaround didn't work?

Unless it isn't meant to work yet? I guess I can update my local pxt before pxt update will.

samelhusseini commented 5 years ago

The issue is only for inverted toolboxes, so you could also just change:

        "invertedToolbox": false,

to false in pxtarget.json until the fix is propagated.

NoobDoesMC commented 5 years ago

@samelhusseini how did you get your card and lights categories to display properly?

Removing the invertedToolbox line from pxtarget.json stops the crashing, but the color, icon, and weight are all still wrong.

NoobDoesMC commented 5 years ago

@samelhusseini but I still get the problem? The category is always grey with the puzzle icon.

samelhusseini commented 5 years ago

Sorry that was auto closed from pushing the PR. I think you still need to set the colour over in libs/ns.ts. Have you tried that?

NoobDoesMC commented 5 years ago

@samelhusseini Yeah.

/libs/ns.ts

//% color=190
namespace pxsim.blocks {
}

and inside of /sim/api.ts I added

//% color=190 weight=100 icon="\uf1ec" block="Blocks"
namespace pxsim.blocks {
  //% blockId=gargle block="set block"
  export function setBlock(): void {
    return;
  }
}

screenshot 2018-12-12 at 21 31 00

samelhusseini commented 5 years ago

Your issue is that you added the namespace pxsim.blocks in ns.ts.

The namespace blocks underlibs is mapped to pxsim.blocks under sim/ and vice versa, so you should try setting the colour on the blocks namespace in libs/ns.ts. ie:

//% color=190
namespace blocks {

}
NoobDoesMC commented 5 years ago

@samelhusseini that also doesn't work, it fails in the same way.

Oh, I just added it to libs/core/ns.ts and it seems to work now.

samelhusseini commented 5 years ago

Great!