types
1.0.0
スクラッチは、ライブラリにタイプの定義を提供しないため、独自のライブラリを書きました。
このリポジトリには、バニラ(LLK)スクラッチランタイムとエディターのタイプのみが含まれています。 Turbowarp Runtimesの追加の種類については、 @turbowarp/Types-Twを参照してください。
タイプスクリプト定義のより人間が読む可能性のあるバージョンは、https://turbowarp.github.io/types/にあります。
| モジュール | 状態 |
|---|---|
| スクラッチVM | ✅ |
| スクラッチレンダー | ✅ |
| スクラッチ-SVGレンダラー | ✅ |
| スクラッチレンダーフォント | ✅ |
| スクラッチオーディオ | ✅ |
| スクラッチストレージ | ✅ |
| スクラッチパーサー | ✅ |
| スクラッチブロック | ? |
| スクラッチgui redux | ✅ |
| スクラッチペイントレッドデュース | ✅ |
| スクラッチWWW Redux |
まず、タイプをインストールします。
npm install @turbowarp/types
次に、 tsconfig.jsonを使用してTypeScriptを構成して、タイプを見つける方法を知る必要があります。
{
"compilerOptions" : {
// If you use require() or "module": "CommonJS", remove these lines.
// If you use "module": "ES6", synthetic default imports are required.
"module" : "ES6" ,
"allowSyntheticDefaultImports" : true ,
// Tell TypeScript where to find the types for Scratch libraries.
"paths" : {
"scratch-vm" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-render" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-svg-renderer" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-render-fonts" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-storage" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-audio" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-parser" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-blocks" : [ "./node_modules/@turbowarp/types/index.d.ts" ]
} ,
// Recommended strictness settings. Change as you please.
"strictNullChecks" : true ,
"noImplicitAny" : true ,
"noImplicitThis" : true
}
}次に、JavaScriptまたはTypeScriptで:
import VM from 'scratch-vm' ;
const vm = new VM ( ) ;
vm . loadProject ( /* read a project somehow */ new ArrayBuffer ( 100 ) )
. then ( ( ) => {
vm . start ( ) ;
vm . greenFlag ( ) ;
} ) ;または、require()を使用している場合:
const VM = require ( 'scratch-vm' ) ;
const vm = new VM ( ) ;
vm . loadProject ( /* read a project somehow */ new ArrayBuffer ( 100 ) )
. then ( ( ) => {
vm . start ( ) ;
vm . greenFlag ( ) ;
} ) ; testsフォルダーにはいくつかのテストがあります。これらのファイルは実際に実行されることはありませんが、コードはタイプチェックされます。
タイプ定義とテストコードは、Apache 2.0ライセンスの下でライセンスされています。
文書化されているライブラリは、異なるライセンスに基づいている場合があります。