Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
# - run: bun run type-check # FIXME: make type-check pass, it wasn't working when I started working on this
Expand All @@ -16,6 +19,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
- run: bun run build
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
26
9 changes: 9 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# AGENTS.md

このリポジトリで作業する AI エージェント向けの約束ごと。

## 学園祭トップページへのリンクは festival.utcode.net に固定する

- ヘッダーやクリア後の「戻る」の遷移先は `https://festival.utcode.net` にし、`kf77.utcode.net` のような回ごとの URL を書かない。`festival.utcode.net` は utcode.net の DNS 設定で最新の学園祭サイトにリダイレクトされるため。回ごとの URL を書くと、学園祭のたびにこのリポジトリを直す必要がある。
- 文言も「五月祭」「駒場祭」ではなく「学園祭」にする。同じ理由で、回ごとに書き換えずに済むようにするため。
- リンク先が古い学園祭を指しているときは、このリポジトリではなく `festival.utcode.net` のリダイレクト先を直す。手順は ut-code/festival-website の README の「毎世代やること」にある。
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Forked from: https://github.com/ut-code/school-festival

## 依存

- Node.js
- Node.js 26 以上
- Go
- GNU Make

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "はじめてのプログラミング教室",
"scripts": {
"dev": "parcel src/index.html",
"build": "parcel build src/index.html && cp -R public/* dist",
"build": "parcel build src/index.html --no-scope-hoist --public-url ./ && cp -R public/* dist",
"lint": "eslint ./src",
"lint-fix": "eslint ./src --fix",
"type-check": "tsc --noEmit",
Expand Down
5 changes: 2 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { useEffect, useState } from "react";
import { useAtom } from "jotai";
import { GlobalHeader } from "./assets/GlobalHeader";
import {
TutorialDialog,
type TutorialDialogPropsStep,
} from "./components/Dialogs/TutorialDialog";
import { Maze } from "./maze";
import { useAtom } from "jotai";
import { isHintOpen } from "./atoms";

export function App(): JSX.Element {
const [hint, setHint] = useState<TutorialDialogPropsStep[] | null>(null);
const [isHintFirstView, setIsHintFirstView] = useState<boolean>(true);
const [_, setHintVisible] = useAtom(isHintOpen);
const [, setHintVisible] = useAtom(isHintOpen);
useEffect(() => {
hint;
setIsHintFirstView(true);
setHintVisible(true);
}, [hint, setHintVisible]);
Expand Down
8 changes: 4 additions & 4 deletions src/assets/GlobalHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
Spacer,
chakra,
} from "@chakra-ui/react";
import { useEffect, useState } from "react";
import { useState } from "react";
import { RiGithubFill, RiQuestionFill } from "react-icons/ri";
import { useAtom } from "jotai";
import { CommonHelp } from "../components/Dialogs/HelpDialog";
import { Logo } from "../components/Logo";
import { useAtom } from "jotai";
import { isHintOpen } from "../atoms";

type Props = {
Expand All @@ -20,7 +20,7 @@ type Props = {
};
export function GlobalHeader({ Hint, children }: Props) {
const [showCommonHelp, setShowCommonHelp] = useState(false);
const [_, setShowHint] = useAtom(isHintOpen);
const [, setShowHint] = useAtom(isHintOpen);

return (
<>
Expand All @@ -46,7 +46,7 @@ export function GlobalHeader({ Hint, children }: Props) {
window.location.href = "https://festival.utcode.net";
}}
>
五月祭トップページへ
学園祭トップページへ
</Button>
<Button
colorScheme="blue"
Expand Down
1 change: 1 addition & 0 deletions src/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { atom } from "jotai";

export const isHintOpen = atom(false);
36 changes: 17 additions & 19 deletions src/common/blockly.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Blockly, { type VariableModel } from "blockly";
import Blockly from "blockly";
import { useCallback, useEffect, useRef } from "react";
import { javascriptGenerator } from "./types.blockly";
import { templates } from "./templates";
Expand All @@ -22,7 +22,6 @@ export type BlocklyToolboxDefinition =

export type UseBlocklyWorkspaceProps = {
toolboxDefinition: BlocklyToolboxDefinition;
onCodeChange?: (code: string, variableNames: string[]) => void;
};

export type UseBlocklyWorkspaceReturnValue = {
Expand All @@ -33,7 +32,6 @@ export type UseBlocklyWorkspaceReturnValue = {

export function useBlocklyWorkspace({
toolboxDefinition,
onCodeChange,
}: UseBlocklyWorkspaceProps): UseBlocklyWorkspaceReturnValue {
const workspaceAreaRef = useRef<HTMLDivElement>(null);
const workspaceRef = useRef<Blockly.WorkspaceSvg>();
Expand All @@ -54,22 +52,22 @@ export function useBlocklyWorkspace({
const toolbox =
toolboxDefinition.type === "flyout"
? {
kind: "flyoutToolbox",
contents: [
// 通常のブロックを追加
...(toolboxDefinition.type === "flyout"
? toolboxDefinition.blockTypes.map((type) => ({
kind: "block",
type,
}))
: []),
// テンプレートを追加
...templates.map((template) => ({
kind: "block",
blockxml: template.blockxml,
})),
],
}
kind: "flyoutToolbox",
contents: [
// 通常のブロックを追加
...(toolboxDefinition.type === "flyout"
? toolboxDefinition.blockTypes.map((type) => ({
kind: "block",
type,
}))
: []),
// テンプレートを追加
...templates.map((template) => ({
kind: "block",
blockxml: template.blockxml,
})),
],
}
: {
kind: "categoryToolbox",
contents: [
Expand Down
71 changes: 55 additions & 16 deletions src/common/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ Blockly.Blocks[CUSTOM_COMMON_IF] = {
this.appendDummyInput().appendField("もし");
this.appendValueInput(CUSTOM_COMMON_FIELD_EXPRESSION).setCheck("Boolean");
this.appendDummyInput().appendField("ならば");
this.appendStatementInput(CUSTOM_COMMON_FIELD_TRUE_STATEMENTS).setCheck(null);
this.appendStatementInput(CUSTOM_COMMON_FIELD_TRUE_STATEMENTS).setCheck(
null
);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(210);
this.setTooltip("条件が満たされた場合のみ、内部の文を実行します。");
},
};
javascriptGenerator[CUSTOM_COMMON_IF] = (block) => {
const expression = javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) || "false";
const trueStatements = javascriptGenerator.statementToCode(block, CUSTOM_COMMON_FIELD_TRUE_STATEMENTS);
const expression =
javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) ||
"false";
const trueStatements = javascriptGenerator.statementToCode(
block,
CUSTOM_COMMON_FIELD_TRUE_STATEMENTS
);
return `if(${expression}){${trueStatements}}`;
};

Expand All @@ -36,19 +43,33 @@ Blockly.Blocks[CUSTOM_COMMON_IF_ELSE] = {
this.appendDummyInput().appendField("もし");
this.appendValueInput(CUSTOM_COMMON_FIELD_EXPRESSION).setCheck(null);
this.appendDummyInput().appendField("ならば");
this.appendStatementInput(CUSTOM_COMMON_FIELD_TRUE_STATEMENTS).setCheck(null);
this.appendStatementInput(CUSTOM_COMMON_FIELD_TRUE_STATEMENTS).setCheck(
null
);
this.appendDummyInput().appendField("違えば");
this.appendStatementInput(CUSTOM_COMMON_FIELD_FALSE_STATEMENTS).setCheck(null);
this.appendStatementInput(CUSTOM_COMMON_FIELD_FALSE_STATEMENTS).setCheck(
null
);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(210);
this.setTooltip("条件が満たされた場合は1番目の文を、満たされない場合は2番目の文を実行します。");
this.setTooltip(
"条件が満たされた場合は1番目の文を、満たされない場合は2番目の文を実行します。"
);
},
};
javascriptGenerator[CUSTOM_COMMON_IF_ELSE] = (block) => {
const expression = javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) || "false";
const trueStatements = javascriptGenerator.statementToCode(block, CUSTOM_COMMON_FIELD_TRUE_STATEMENTS);
const falseStatements = javascriptGenerator.statementToCode(block, CUSTOM_COMMON_FIELD_FALSE_STATEMENTS);
const expression =
javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) ||
"false";
const trueStatements = javascriptGenerator.statementToCode(
block,
CUSTOM_COMMON_FIELD_TRUE_STATEMENTS
);
const falseStatements = javascriptGenerator.statementToCode(
block,
CUSTOM_COMMON_FIELD_FALSE_STATEMENTS
);
return `if(${expression}){${trueStatements}}else{${falseStatements}}`;
};

Expand All @@ -64,7 +85,10 @@ Blockly.Blocks[CUSTOM_COMMON_WHILE_TRUE] = {
},
};
javascriptGenerator[CUSTOM_COMMON_WHILE_TRUE] = (block) => {
const statements = javascriptGenerator.statementToCode(block, CUSTOM_COMMON_FIELD_STATEMENTS);
const statements = javascriptGenerator.statementToCode(
block,
CUSTOM_COMMON_FIELD_STATEMENTS
);
return `while(true){${statements}}`;
};

Expand All @@ -81,8 +105,13 @@ Blockly.Blocks[CUSTOM_COMMON_WHILE] = {
},
};
javascriptGenerator[CUSTOM_COMMON_WHILE] = (block) => {
const expression = javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) || "false";
const statements = javascriptGenerator.statementToCode(block, CUSTOM_COMMON_FIELD_STATEMENTS);
const expression =
javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) ||
"false";
const statements = javascriptGenerator.statementToCode(
block,
CUSTOM_COMMON_FIELD_STATEMENTS
);
return `while(${expression}){${statements}}`;
};

Expand All @@ -99,8 +128,13 @@ Blockly.Blocks[CUSTOM_COMMON_DO_UNTIL] = {
},
};
javascriptGenerator[CUSTOM_COMMON_DO_UNTIL] = (block) => {
const expression = javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) || "false";
const statements = javascriptGenerator.statementToCode(block, CUSTOM_COMMON_FIELD_STATEMENTS);
const expression =
javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) ||
"false";
const statements = javascriptGenerator.statementToCode(
block,
CUSTOM_COMMON_FIELD_STATEMENTS
);
return `while(!(${expression})){${statements}}`;
};

Expand All @@ -120,7 +154,12 @@ let tempVariableIndex = 0;
javascriptGenerator[CUSTOM_COMMON_TIMES] = (block) => {
const tempVariableName = `blocklyTempVariable${CUSTOM_COMMON_TIMES}${tempVariableIndex}`;
tempVariableIndex += 1;
const expression = javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) || "0";
const statements = javascriptGenerator.statementToCode(block, CUSTOM_COMMON_FIELD_STATEMENTS);
const expression =
javascriptGenerator.valueToCode(block, CUSTOM_COMMON_FIELD_EXPRESSION, 0) ||
"0";
const statements = javascriptGenerator.statementToCode(
block,
CUSTOM_COMMON_FIELD_STATEMENTS
);
return `for (var ${tempVariableName} = 0; ${tempVariableName} < (${expression}); ${tempVariableName}++) {${statements}}`;
};
48 changes: 31 additions & 17 deletions src/common/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export type UseBlocklyInterpreterProps = {
onStep?(blockId: string | null): void;
};

export type BlocklyInterpreterState = "stopped" | "running" | "paused" | "finished";
export type BlocklyInterpreterState =
| "stopped"
| "running"
| "paused"
| "finished";

export type BlocklyInterpreter = {
state: BlocklyInterpreterState;
Expand Down Expand Up @@ -47,33 +51,43 @@ export function useBlocklyInterpreter({
*/
const highlightedBlockIdRef = useRef<string>();

const [executionState, setExecutionState] = useState<BlocklyInterpreterState>("stopped");
const [executionState, setExecutionState] =
useState<BlocklyInterpreterState>("stopped");

const prepareExecution = useCallback(
(code: string) => {
jsInterpreterRef.current = new JSInterpreter(code, (newInterpreter, globalScope) => {
Object.entries(globalFunctions).forEach(([functionName, globalFunction]) => {
newInterpreter.setProperty(globalScope, functionName, newInterpreter.createNativeFunction(globalFunction));
});
newInterpreter.setProperty(
globalScope,
STATEMENT_PREFIX_FUNCTION,
newInterpreter.createNativeFunction((blockId: string) => {
highlightedBlockIdRef.current = blockId;
onStep?.(blockId);
}),
);
});
jsInterpreterRef.current = new JSInterpreter(
code,
(newInterpreter, globalScope) => {
Object.entries(globalFunctions).forEach(
([functionName, globalFunction]) => {
newInterpreter.setProperty(
globalScope,
functionName,
newInterpreter.createNativeFunction(globalFunction)
);
}
);
newInterpreter.setProperty(
globalScope,
STATEMENT_PREFIX_FUNCTION,
newInterpreter.createNativeFunction((blockId: string) => {
highlightedBlockIdRef.current = blockId;
onStep?.(blockId);
})
);
}
);
},
[globalFunctions, onStep],
[globalFunctions, onStep]
);

const startExecution = useCallback(
(code: string) => {
prepareExecution(code);
setExecutionState("running");
},
[prepareExecution],
[prepareExecution]
);
const pauseExecution = useCallback(() => {
setExecutionState("paused");
Expand Down
2 changes: 1 addition & 1 deletion src/common/templates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//xml形式で左手法のテンプレートを作成できる
// xml形式で左手法のテンプレートを作成できる
export const templates = [
{
name: "Template 1",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialogs/ClearDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function ClearDialog(props: {
) : (
<Text mb={3}>
お疲れ様でした!これでこの企画は終わりとなります。
五月祭トップページに戻る場合は「戻る」ボタンをおしてください!
学園祭トップページに戻る場合は「戻る」ボタンをおしてください!
もう一度遊びたい場合、他の迷路も試してみたい場合は、「キャンセル」をおしてください。
遊んでくださり、ありがとうございました!
</Text>
Expand Down
Loading
Loading