Skip to content

Latest commit

 

History

History
19 lines (19 loc) · 5.54 KB

README_eng.md

File metadata and controls

19 lines (19 loc) · 5.54 KB

OOP for Turbowarp

Русский README здесь! This extension adds classes, methods and objects to Turbowarp.

Examples of using

  1. Cat class
    image

How to install:

  1. Copy the code:
!function(e){"use strict";e.extensions.register(new class{getInfo(){return console.log("OOP extension by @timaaos. Download it on https://github.com/timaaos/OOPTurbowarp"),{id:"oop",name:"ObjectOrientedProgramming",blocks:[{opcode:"class_labels",blockType:e.BlockType.LABEL,text:"Classes"},{opcode:"class",blockType:e.BlockType.HAT,text:"Class [NAME]",arguments:{NAME:{defaultValue:"Cat",type:e.ArgumentType.STRING}}},{opcode:"class_end",blockType:e.BlockType.COMMAND,text:"End class"},{opcode:"class_init",blockType:e.BlockType.REPORTER,text:"Init class [NAME]",arguments:{NAME:{type:e.ArgumentType.STRING,menu:"classes"}}},{opcode:"function_labels",blockType:e.BlockType.LABEL,text:"Functions"},{opcode:"class_func",blockType:e.BlockType.CONDITIONAL,text:"Function [NAME]",arguments:{NAME:{defaultValue:"Meow",type:e.ArgumentType.STRING}}},{opcode:"call_obj",blockType:e.BlockType.COMMAND,text:"Call function [FUNC] of [OBJ]",arguments:{FUNC:{type:e.ArgumentType.STRING,defaultValue:"Meow"},OBJ:{type:e.ArgumentType.STRING,menu:"vars"}}},{opcode:"props_labels",blockType:e.BlockType.LABEL,text:"Properties"},{opcode:"class_prop",blockType:e.BlockType.COMMAND,text:"Property [NAME] [VALUE]",arguments:{NAME:{defaultValue:"age",type:e.ArgumentType.STRING},VALUE:{defaultValue:"4",type:e.ArgumentType.STRING}}},{opcode:"property_obj",blockType:e.BlockType.REPORTER,text:"Property [NAME] of [OBJ]",arguments:{NAME:{type:e.ArgumentType.STRING,defaultValue:"age"},OBJ:{type:e.ArgumentType.STRING,menu:"vars"}}},{opcode:"setProperty",blockType:e.BlockType.COMMAND,text:"Set property [NAME] of [OBJ] to [VALUE]",arguments:{NAME:{type:e.ArgumentType.STRING,defaultValue:"age"},OBJ:{type:e.ArgumentType.STRING,menu:"vars"},VALUE:{type:e.ArgumentType.STRING,defaultValue:"5"}}},{opcode:"thisprops_labels",blockType:e.BlockType.LABEL,text:"THIS Properties"},{opcode:"this_property",blockType:e.BlockType.REPORTER,text:"THIS Property [NAME]",arguments:{NAME:{type:e.ArgumentType.STRING,defaultValue:"age"}}},{opcode:"set_this_property",blockType:e.BlockType.COMMAND,text:"Set THIS Property [NAME] to [VALUE]",arguments:{NAME:{type:e.ArgumentType.STRING,defaultValue:"age"},VALUE:{type:e.ArgumentType.STRING,defaultValue:"5"}}}],menus:{classes:"dynClasses",vars:"varList",properties:"prop_list"}}}tryinit(){null==e.oop&&(e.oop={classes:{},calldata:{}})}getVarIdByName(t){for(const a of e.vm.runtime.targets)for(const e of Object.values(a.variables))if(e.name==t)return e.id;return-1}varList(){var t=[];for(const a of e.vm.runtime.targets)for(const e of Object.values(a.variables))t.push(e.name);return t}dynClasses(){return this.tryinit(),0==Object.keys(e.oop.classes).length?["No classes yet!"]:Object.keys(e.oop.classes)}class({NAME:t}){return this.tryinit(),Object.keys(e.oop.classes).includes(t)||(e.oop.classes[t]={}),"init"==e.oop.calldata.type&&e.oop.calldata.class==t||"func"==e.oop.calldata.type&&e.oop.calldata.class==t}this_property(t,a){if(this.tryinit(),"func"==e.oop.calldata.type&&null!=e.oop.calldata.obj){var o=this.getVarIdByName(e.oop.calldata.obj);return o=e.vm.getVariableValue(a.target.id,o),JSON.parse(o)[t.NAME]}return"undefined"}set_this_property(t,a){if(this.tryinit(),"func"==e.oop.calldata.type&&null!=e.oop.calldata.obj){var o=this.getVarIdByName(e.oop.calldata.obj),l=e.vm.getVariableValue(a.target.id,o);return(l=JSON.parse(l))[t.NAME]=t.VALUE.toString(),e.vm.setVariableValue(a.target.id,o,JSON.stringify(l)),!0}return"undefined"}async call_obj(t,a){this.tryinit();var o=this.getVarIdByName(t.OBJ);o=e.vm.getVariableValue(a.target.id,o);var l=JSON.parse(o).__class;for(e.oop.calldata={type:"func",class:l,func:t.FUNC,ready:!1,result:{},obj:t.OBJ};!e.oop.calldata.ready;)await this.__delay__(50);return e.oop.calldata={},!0}class_func(t,a){return this.tryinit(),"func"==e.oop.calldata.type&&e.oop.calldata.func==t.NAME&&a.startBranch(1,!1),!1}class_prop({NAME:t,VALUE:a}){return e.oop.calldata.result[t]=a,!0}property_obj(t,a){var o=this.getVarIdByName(t.OBJ);return o=e.vm.getVariableValue(a.target.id,o),JSON.parse(o)[t.NAME]}setProperty(t,a){var o=this.getVarIdByName(t.OBJ),l=e.vm.getVariableValue(a.target.id,o);return(l=JSON.parse(l))[t.NAME]=t.VALUE.toString(),e.vm.setVariableValue(a.target.id,o,JSON.stringify(l)),!0}class_end(){return e.oop.calldata.ready=!0,!0}async __delay__(e){return new Promise((t=>{e=e||2e3,setTimeout((function(){t()}),e)}))}async class_init({NAME:t}){if(this.tryinit(),null!=e.oop.classes[t]){for(e.oop.calldata={type:"init",class:t,ready:!1,result:{__class:t}};!e.oop.calldata.ready;)await this.__delay__(50);var a=e.oop.calldata.result;return e.oop.calldata={},JSON.stringify(a)}return"undefined"}}),e.vm._events.BLOCK_DRAG_UPDATE.push((function(){null!=e.oop&&(e.oop.classes={})}))}(Scratch);
  1. Go to Turbowarp
  2. Click this button:
    image
  3. We are looking for such an extension:
    image
  4. Click, select Text, check the "outside the sandbox" download box and paste the copied code into the field.
    image
  5. Click Load and start using!