From 2926a42218ae83642423f2fc0c45461687f3dca0 Mon Sep 17 00:00:00 2001 From: XeroName <63216951+XeroName@users.noreply.github.com> Date: Wed, 16 Aug 2023 12:01:18 +0900 Subject: [PATCH] Add XeroName/Deltatime extension (#622) --- extensions/XeroName/Deltatime.js | 56 +++++++++++++++++++++++ images/README.md | 3 ++ images/XeroName/Deltatime.svg | 8 ++++ website/XeroName/Deltatime.html | 78 ++++++++++++++++++++++++++++++++ website/index.ejs | 6 +++ 5 files changed, 151 insertions(+) create mode 100644 extensions/XeroName/Deltatime.js create mode 100644 images/XeroName/Deltatime.svg create mode 100644 website/XeroName/Deltatime.html diff --git a/extensions/XeroName/Deltatime.js b/extensions/XeroName/Deltatime.js new file mode 100644 index 0000000000..705b90e13c --- /dev/null +++ b/extensions/XeroName/Deltatime.js @@ -0,0 +1,56 @@ +(function (Scratch) { + 'use strict'; + + const icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjAwIiBoZWlnaHQ9IjYwMCIgdmlld0JveD0iMCAwIDYwMCA2MDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxjaXJjbGUgY3g9IjMwMCIgY3k9IjMwMCIgcj0iMzAwIiBmaWxsPSIjMjAyMDIwIi8+CjxwYXRoIGQ9Ik04Ny44NjggNTEyLjEzMkM2MC4wMTA0IDQ4NC4yNzQgMzcuOTEyNSA0NTEuMjAzIDIyLjgzNjEgNDE0LjgwNUM3Ljc1OTcyIDM3OC40MDcgLTMuNDQ0MTZlLTA2IDMzOS4zOTcgMCAzMDBDMy40NDQxNmUtMDYgMjYwLjYwMyA3Ljc1OTc0IDIyMS41OTMgMjIuODM2MiAxODUuMTk1QzM3LjkxMjYgMTQ4Ljc5NyA2MC4wMTA0IDExNS43MjYgODcuODY4IDg3Ljg2NzlDMTE1LjcyNiA2MC4wMTA0IDE0OC43OTcgMzcuOTEyNSAxODUuMTk1IDIyLjgzNjFDMjIxL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jU0ODYgNDEzLjYyOUM4MC4yODU4IDQxNC4yODUgODAuNzY5NiA0MTUgODEuNDc3IDQxNUgyNzguNTIzQzI3OS4yMyA0MTUgMjc5LjcxNCA0MTQuMjg1IDI3OS40NTEgNDEzLjYyOVoiIHN0cm9rZT0id2hpdGUiIHN0cm9rZS13aWR0aD0iMzIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPgo8L3N2Zz4K'; + + if (!Scratch.extensions.unsandboxed) { + throw new Error('DeltaTime must be run unsandboxed'); + } + + const vm = Scratch.vm; + + let deltaTime = 0; + let previousTime = 0; + + vm.runtime.on('BEFORE_EXECUTE', () => { + const now = performance.now(); + deltaTime = previousTime === 0 ? 0 : (now - previousTime) / 1000; + previousTime = now; + }); + + class Dt { + getInfo() { + return { + id: 'dtbyxeroname', + name: 'Deltatime', + docsURI: 'https://extensions.turbowarp.org/XeroName/Deltatime.html', + color1: '#333333', + color2: '#444444', + color3: '#ffffff', + menuIconURI: icon, + blocks: [ + { + opcode: 'dt', + blockType: Scratch.BlockType.REPORTER, + text: 'ΔT' + }, + { + opcode: 'fps', + blockType: Scratch.BlockType.REPORTER, + text: 'fps' + } + ] + }; + } + + dt() { + return deltaTime; + } + + fps() { + return +(1 / deltaTime).toFixed(2); + } + } + + Scratch.extensions.register(new Dt()); +})(Scratch); diff --git a/images/README.md b/images/README.md index 0600c79be7..de3105dca5 100644 --- a/images/README.md +++ b/images/README.md @@ -252,3 +252,6 @@ All images in this folder are licensed under the [GNU General Public License ver - Created by [@LilyMakesThings](https://github.com/LilyMakesThings). - Dango based on dango from [Twemoji](https://twemoji.twitter.com/) under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). - Background "blobs" by Scratch. + +## XeroName/Deltatime.svg + - Created by [@XeroName](https://scratch.mit.edu/users/plant2014/) in https://github.com/TurboWarp/extensions/pull/622 diff --git a/images/XeroName/Deltatime.svg b/images/XeroName/Deltatime.svg new file mode 100644 index 0000000000..ed5d6c4ccb --- /dev/null +++ b/images/XeroName/Deltatime.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/website/XeroName/Deltatime.html b/website/XeroName/Deltatime.html new file mode 100644 index 0000000000..c812040e1c --- /dev/null +++ b/website/XeroName/Deltatime.html @@ -0,0 +1,78 @@ +

Documenation of Deltatime

+ +
+

[en-US] English Guide

+

Introduction

+ +

Basic knoledgement

+ +

FPS & ΔT

+

FPS and ΔT value of dtbx have following properties :

+ +

Filtering

+ +

Calculating

+ +
+

[ko-KR] 한국어 도움말

+

소개

+ +

개념 설명

+ +

FPS 및 ΔT

+

dtbxFPSΔT 값은 다음과 같은 속성을 가집니다.

+ +

필터링

+ +

계산

+ diff --git a/website/index.ejs b/website/index.ejs index d2b314a15f..4e7f852871 100644 --- a/website/index.ejs +++ b/website/index.ejs @@ -542,6 +542,12 @@

Display notifications.

+
+ <%- banner('XeroName/Deltatime') %> +

Deltatime

+

Precise delta timing blocks. Created by XeroName.

+
+
<%- banner('ar') %>

Augmented Reality