Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/microsoft/pxt into srietk…
Browse files Browse the repository at this point in the history
…erk/share-dialog-accessibility
  • Loading branch information
srietkerk committed May 8, 2024
2 parents 9ae3b08 + c48ddb0 commit 267701a
Show file tree
Hide file tree
Showing 67 changed files with 696 additions and 520 deletions.
64 changes: 32 additions & 32 deletions common-docs/teachertool/catalog-shared.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
{
"criteria": [
{
"id": "D21D76A2-D9FD-4F9B-B0AC-973CB870EA78",
"use": "variable_set",
"template": "At least one custom variable is set",
"docPath": "/teachertool",
"description": "At least one user-defined variable is set to a value.",
"maxCount": 1
},
{
"id": "0173898D-8A48-4266-AAB9-CE934471A734",
"use": "variable_accessed",
"template": "At least one variable is accessed",
"docPath": "/teachertool",
"description": "At least one variable's value is read.",
"maxCount": 1
},
{
"id": "7AE7EA2A-3AC8-42DC-89DB-65E3AE157156",
"use": "block_comment_used",
"template": "At least ${count} comments",
"description": "The project contains at least the specified number of comments.",
"docPath": "/teachertool",
"maxCount": 1,
"params": [
{
"name": "count",
"type": "number",
"default": 1,
"paths": ["checks[0].count"]
}
]
},
{
"id": "59AAC5BA-B0B3-4389-AA90-1E767EFA8563",
"use": "block_used_n_times",
Expand All @@ -52,6 +20,22 @@
}
]
},
{
"id": "7AE7EA2A-3AC8-42DC-89DB-65E3AE157156",
"use": "block_comment_used",
"template": "At least ${count} comments",
"description": "The project contains at least the specified number of comments.",
"docPath": "/teachertool",
"maxCount": 1,
"params": [
{
"name": "count",
"type": "number",
"default": 1,
"paths": ["checks[0].count"]
}
]
},
{
"id": "B8987394-1531-4C71-8661-BE4086CE0C6E",
"use": "n_loops",
Expand Down Expand Up @@ -83,6 +67,22 @@
"default": 1
}
]
},
{
"id": "0DFA44C8-3CA5-4C77-946E-AF09F6C03879",
"use": "variable_usage",
"template": "Uses at least ${count} variables",
"docPath": "/teachertool",
"description": "The program creates and uses at least this many user-defined variables.",
"maxCount": 1,
"params": [
{
"name": "count",
"type": "number",
"paths": ["checks[0].count"],
"default": 1
}
]
}
]
}
57 changes: 25 additions & 32 deletions common-docs/teachertool/validator-plans-shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,38 +86,6 @@
}
]
},
{
".desc": "A variable's value is set",
"name": "variable_set",
"threshold": 1,
"checks": [
{
"validator": "blocksExist",
"blockCounts": [
{
"blockId": "variables_set",
"count": 1
}
]
}
]
},
{
".desc": "A variable's value is used",
"name": "variable_accessed",
"threshold": 1,
"checks": [
{
"validator": "blocksExist",
"blockCounts": [
{
"blockId": "variables_get",
"count": 1
}
]
}
]
},
{
".desc": "A parameter's value is used",
"name": "parameter_variable_accessed",
Expand Down Expand Up @@ -301,6 +269,31 @@
"count": 0
}
]
},
{
".desc": "Variable creation & usage validation, with optional name filtering",
"name": "variable_usage",
"threshold": 1,
"checks": [
{
"validator": "variableUsage",
"count": 0,
"name": ""
}
]
},
{
".desc": "The zero number block is present.",
"name": "number_zero",
"threshold": 1,
"checks": [
{
"validator": "blockFieldValueExists",
"fieldType": "NUM",
"fieldValue": 0,
"blockType": "math_number"
}
]
}
]
}
15 changes: 15 additions & 0 deletions docfiles/pxtweb/cookieCompliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace pxt {
let analyticsLoaded = false;
let interactiveConsent = false;
let isProduction = false;
let partnerName: string;

class TelemetryQueue<A, B, C> {
private q: [A, B, C][] = [];
Expand Down Expand Up @@ -185,6 +186,16 @@ namespace pxt {
}

export function initializeAppInsightsInternal(includeCookie = false) {
try {
const params = new URLSearchParams(window.location.search);
if (params.has("partner")) {
partnerName = params.get("partner");
}
}
catch (e) {
console.warn("Could not parse search string", e);
}

// loadAppInsights is defined in docfiles/tracking.html
const loadAI = (window as any).loadAppInsights;
if (loadAI) {
Expand Down Expand Up @@ -221,6 +232,10 @@ namespace pxt {
telemetryItem.properties["target"] = pxtConfig.targetId;
telemetryItem.properties["stage"] = (pxtConfig.relprefix || "/--").replace(/[^a-z]/ig, '')

if (partnerName) {
telemetryItem.properties["partner"] = partnerName;
}

const userAgent = navigator.userAgent.toLowerCase();
const electronRegexResult = /\belectron\/(\d+\.\d+\.\d+.*?)(?: |$)/i.exec(userAgent); // Example navigator.userAgent: "Mozilla/5.0 Chrome/61.0.3163.100 Electron/2.0.0 Safari/537.36"
if (electronRegexResult) {
Expand Down
1 change: 1 addition & 0 deletions docs/writing-docs/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ You can write, edit, and test a tutorial with the online [**Tutorial Tool**](htt
* [Multi-language](/writing-docs/tutorials/multi-lang) - Tutorials for both Blocks and Code
* [Adding Resources](/writing-docs/tutorials/resources) - Including a resource section in a tutorial
* [Publish](/writing-docs/tutorials/publish) - How to publish a tutorial
* [Troubleshoot](/writing-docs/tutorials/troubleshooting) - Troubleshooting problems with a tutorial
51 changes: 50 additions & 1 deletion docs/writing-docs/tutorials/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,59 @@ The asset block might look something like the following example.
```
````

If you need to modify the assets for the tutoral, reopen and edit the project saved in the `.txt.mkcd` file.
If you need to modify the assets for the tutorial, reopen and edit the project saved in the `.txt.mkcd` file.
You can simply drag the file into the editor, make your changes, and download it again. Open the project
file in a text editor, copy the new asset data, and replace the contents of your tutorial's ```` ```assetjson ````
block with it.

The assets are shown as the initial view in a tutorial by using the [@preferredEditor](/writing-docs/tutorials/control-options#preferred-editor-view) option. This option causes the tutorial to open with the Asset Editor
rather than showing the editor for Blocks or Code.

## Creating asset packs

### ~ alert

#### MackeCode Arcade only

Asset packs only work with MakeCode Arcade.

### ~

Asset packs are resource projects that are separate from a tutorial file. They contain images, animations, tilemaps, and other resources for use in a tutorial. An asset pack can help reduce the size of a tutorial when it's using many resources or very large resources. You may place some or all your tutorial resources into an asset pack project.

Here are the instructions for creating an asset pack:

1. Create a new project. The name of this project will end up being the namespace of the asset pack you create, so make sure to rename it to a valid javascript variable name (no spaces, only letters, underscores, and numbers). For example, `my_asset_pack`.
2. Switch to the **Assets** tab.
3. Create a new image (or other asset item). Copy the image text your tutorial and paste it into image space in the editor for the new asset.
4. Give the asset a name in the bottom right of the image editor. This name will be the name you reference in your code, so make sure it’s a valid javascript variable name. For example, `background1`.
5. Close the image editor and switch to the **JavaScript** tab.
6. On the left, in the file explorer underneath the simulator, open up pxt.json
7. Click "Edit settings as text".
8. Underneath the line that says "description", paste in this line:<br/> `"assetPack": true`<br/>
9. In the file explorer, switch back to main.ts.
10. Turn this project into a GitHub repo using the GitHub button in the bottom toolbar (for example, my_github_username/my_asset_pack).

Now that you have an asset pack, you can include it in your tutorial just like you would an extension. Add an annotation like this at the bottom of your markdown file:

````
```package
my_asset_pack=github:my_github_username/my_asset_pack
```
````

**Important**: Make sure that the name on the left hand side of the "=" matches the name of your extension from Step 1. However, if the asset pack's repository name contains "-" such as `github:my_github_username/my-asset-pack`, the name on the left of the "=" should remove the "-" characters such that `my-asset-pack` becomes `myassetpack`.

Now, instead of including the background image in your code snippets, you can reference it like so:

````
```blocks
scene.setBackgroundImage(my_asset_pack.background1)
```
````

For more details on how to create an asset pack for your tutorial, watch this helpful video:

https://youtu.be/ikz15E24F2k

If you have other assets you want to include, you can insert them into the pack in the same manner.
50 changes: 50 additions & 0 deletions docs/writing-docs/tutorials/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Troubleshooting

If your tutorial is not behaving properly or you receive an error message, you can check some of these common trouble situations to help resolve the problem with your custom tutorial.

### ~ hint

#### Tutorial format or content problems

If MakeCode can't load your tutorial, you will likely see the message:

```
Please check your internet connection and check the tutorial is valid
```

This may indicate that your tutorial has a problem with it's content or it can't be located at the path you provided.

### ~

## Tutorial file is too large

Tutorial markdown files are required to be less than **128K** bytes.

### Asset packs in MakeCode Arcade

There can be several images and/or very large images within the asset sections or instructions of a tutorial markdown file. Often these will make the tutorial file size exceed the 128K byte limit. You can reduce the size of the tutorial file by moving the images into a separate asset pack. See the instructions in the [resources](/writing-docs/tutorials/resources) page for creating an [asset pack](/writing-docs/tutorials/resources#creating-asset-packs).

## Tutorial game screen just shows activity spinner

If activity indicator on the game screen in the tutorial seems to just spin and never load, there's probably an error. Start by opening the JavaScript console and try to re-run the tutorial. It should give you an idea of what's causing it to not work.

## Kind types aren't working in MakeCode Arcade

If you added a "kind" and MakeCode generated the code for you, it won't work correctly in the tutorial. You need to add `//% isKind` before each declaration.

The kind that was declared in your tutorial code, such as:

```typescript
namespace SpriteKind {
export const Veggies = SpriteKind.create()
}
```

You should add `//% isKind` to the declaration:

```typescript
namespace SpriteKind {
//% isKind
export const Veggies = SpriteKind.create()
}
```
6 changes: 6 additions & 0 deletions localtypings/validatorPlan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ declare namespace pxt.blocks {
count: number;
}

export interface VariableUsageValidatorCheck extends ValidatorCheckBase {
validator: "variableUsage";
count: number;
name?: string;
}

export interface EvaluationResult {
result?: boolean;
notes?: string;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pxt-core",
"version": "10.0.20",
"version": "10.0.21",
"description": "Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors",
"keywords": [
"TypeScript",
Expand Down
20 changes: 20 additions & 0 deletions pxteditor/code-validation/runValidatorPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { validateBlocksInSetExist } from "./validateBlocksInSetExist";
import { validateBlockCommentsExist } from "./validateCommentsExist";
import { validateSpecificBlockCommentsExist } from "./validateSpecificBlockCommentsExist";
import { getNestedChildBlocks } from "./getNestedChildBlocks";
import { validateVariableUsage } from "./validateVariableUsage";

export function runValidatorPlan(usedBlocks: Blockly.Block[], plan: pxt.blocks.ValidatorPlan, planLib: pxt.blocks.ValidatorPlan[]): boolean {
const startTime = Date.now();
Expand All @@ -32,6 +33,9 @@ export function runValidatorPlan(usedBlocks: Blockly.Block[], plan: pxt.blocks.V
case "blockFieldValueExists":
[successfulBlocks, checkPassed] = [...runBlockFieldValueExistsValidation(usedBlocks, check as pxt.blocks.BlockFieldValueExistsCheck)];
break;
case "variableUsage":
[successfulBlocks, checkPassed] = [...runVariableUsageValidation(usedBlocks, check as pxt.blocks.VariableUsageValidatorCheck)];
break;
default:
pxt.debug(`Unrecognized validator: ${check.validator}`);
checkPassed = false;
Expand Down Expand Up @@ -104,3 +108,19 @@ function runBlockFieldValueExistsValidation(usedBlocks: Blockly.Block[], inputs:
});
return [blockResults.successfulBlocks, blockResults.passed];
}

function runVariableUsageValidation(usedBlocks: Blockly.Block[], inputs: pxt.blocks.VariableUsageValidatorCheck): [Blockly.Block[], boolean] {
const blockResults = validateVariableUsage({
usedBlocks,
count: inputs.count,
name: inputs.name
});

// Flatten the map of passing variable definition blocks
const passingVarDefinitions: Blockly.Block[] = [];
for (const blocks of blockResults.passingVarDefinitions.values()) {
passingVarDefinitions.push(...blocks);
}

return [passingVarDefinitions, blockResults.passed];
}
Loading

0 comments on commit 267701a

Please sign in to comment.