Experimenting with the Block Enhancement Tool Set extension by Justin

mdotedot

  • Posts: 1654
Justin made a toolset extension with which you can enhance your Engine Extensions.

Today, I experimented with it.

Source: https://github.com/polydes/enhanced-block-defs


Actions in Stencyl:
* Extensions : Extension Repositories : Add repository
*  New Repository: http://www.polydes.com/repo
* Extensions : Toolset Extension Manager : Enable the Enhanced Block Definitions

This extension is not visible in the Dashboard under Extensions.

When enabled you can use extra functionality in your Engine Extensions.

As a demonstration I created an engine Extension:
* mkdir  %AppData%\Stencyl\stencylworks\engine-extensions\EnhancedBlocksTest
Using notepad (++) create these:


%AppData%\Stencyl\stencylworks\engine-extensions\EnhancedBlocksTest\blocks.xml
Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<blocks>

<block
tag="EventAddremoveListener"
spec="%1 listener %2 for enhanced event %0"
code='EnhancedBlocksTest.#1EventListener(#0, EnhancedBlocksTest._customEvent_#2);'
type="action"
color="gray"
returns="void">
<fields>
<dropdown order="0">
<choices>
<c text="Test" code="MyType.Test1"/>
</choices>
</dropdown>
<dropdown order="1">
<choices>
<c text="add" code="add"/>
<c text="remove" code="remove"/>
</choices>
</dropdown>
<text order="2"/>
</fields>
</block>


</blocks>

The magic is in : EnhancedBlocksTest.#1EventListener(#0, EnhancedBlocksTest._customEvent_#2);'
Where the #0 through #2 are replaced by the toolset extension.

Note the tag: "EventAddremoveListener"
You have to have the same tag in the blocks-enhancements.xml file. That xml file is used by the toolset extension.
the blocks-enhancements.xml file has a relation with the blocks.xml !!

%AppData%\Stencyl\stencylworks\engine-extensions\EnhancedBlocksTest\blocks-enhancements.xml
Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<blocks-enhancements>

<imports>

</imports>

<block
tag="EventAddremoveListener">
<fields>
<code order="2"/>
</fields>
</block>

</blocks-enhancements>


%AppData%\Stencyl\stencylworks\engine-extensions\EnhancedBlocksTest\EnhancedBlocksTest.hx
Code: [Select]
class EnhancedBlocksTest {

public static function addEventListener(type:MyType, fn:Void->Void):Void{
trace("ADD Listener: The Type is :"+type);
trace("ADD Listener: The function is : "+fn);
if(fn != null) fn();
}
public static function removeEventListener(type:MyType, fn:Void->Void):Void{
trace("REMOVE Listener: The Type is :"+type);
trace("REMOVE Listener: The function is : "+fn);
}
   
public static function _customEvent_hello(){
trace("CustomEvent HELLO Called");
}
}

%AppData%\Stencyl\stencylworks\engine-extensions\EnhancedBlocksTest\MyType.hx
Code: [Select]
@:enum
abstract MyType(String)
{
var Test1 = "TEST1";

}

%AppData%\Stencyl\stencylworks\engine-extensions\EnhancedBlocksTest\include.xml
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<project>

</project>

%AppData%\Stencyl\stencylworks\engine-extensions\EnhancedBlocksTest\info.txt
Code: [Select]
name=EnhancedBlocksTest
description=EnhancedBlocksTest
author=M.E.
website=http://www.polydes.com/repo
version=1.0.0
compatibility=all
dependencies=toolset-com.polydes.blockdefs-0.1.0,stencyl-4.0.2
repository=http://www.polydes.com/repo

Put an icon in the folder: %AppData%\Stencyl\stencylworks\engine-extensions\EnhancedBlocksTest\icon.png

Restart Stencyl

through settings enable the EnhancedBlocksTest extension and you can now use the new block:

* [add/remove]  listener [hello] for enhanced event [Test]

Which will produce the following haxe code : EnhancedBlocksTest.addEventListener(MyType.Test1, EnhancedBlocksTest._customEvent_hello);

Running this it will output the trace information in your log viewer or browser console.

I used static class but this is not a requirement!


Personally I have to figure out how and when I will use this in my own engine extensions but it is a cool addition !!!


Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.