Skip to content

Commit

Permalink
refactor: Saparate developer tools blockholder and some blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Dec 29, 2023
1 parent bd143ec commit 3cd2c6b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 50 deletions.
54 changes: 4 additions & 50 deletions app/src/main/java/builtin/blocks/BuiltInBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.graphics.Color;
import android.util.Log;
import android.widget.Toast;
import builtin.blocks.holder.OperatorBlocks;
import com.dragon.ide.objects.Block;
import com.dragon.ide.objects.BlockContent;
import com.dragon.ide.objects.BlocksHolder;
Expand All @@ -19,33 +20,11 @@ public static ArrayList<BlocksHolder> getBuiltInBlocksHolder() {
ArrayList<BlocksHolder> blocksHolder = new ArrayList<BlocksHolder>();
BlocksHolder holder1 = new BlocksHolder();
holder1.setColor("#009900");
holder1.setName("Operators");
holder1.setTags(
new String[] {
"developer", "developerOnly"
});
holder1.setName("Developer tools");
holder1.setTags(new String[] {"developer", "developerOnly"});

ArrayList<Block> blockList = new ArrayList<Block>();

Block blockInHolder1 = new Block();
blockInHolder1.setColor("#009900");
blockInHolder1.setBlockType(Block.BlockType.defaultBlock);
blockInHolder1.setName("addSource");
blockInHolder1.setRawCode("DevKumar DragonIDE parameter DevKumar");
blockInHolder1.setTags(new String[] {"developer", "developerOnly"});

ArrayList<BlockContent> block1ContentList = new ArrayList<BlockContent>();

BlockContent block1Content1 = new BlockContent();
block1Content1.setText("add source");
block1ContentList.add(block1Content1);

SourceContent block1Content2 = new SourceContent();
block1Content2.setId("parameter");
block1ContentList.add(block1Content2);

blockInHolder1.setBlockContent(block1ContentList);

Block blockInHolder2 = new Block();
blockInHolder2.setColor("#ff0000");
blockInHolder2.setBlockType(Block.BlockType.sideAttachableBlock);
Expand All @@ -66,30 +45,6 @@ public static ArrayList<BlocksHolder> getBuiltInBlocksHolder() {

blockInHolder2.setBlockContent(block2ContentList);

ComplexBlock blockInHolder3 = new ComplexBlock();
blockInHolder3.setColor("#009900");
blockInHolder3.setBlockType(Block.BlockType.complexBlock);
blockInHolder3.setName("if");
StringBuilder blockInHolder3StringBuilder = new StringBuilder();
blockInHolder3StringBuilder.append("if (");
blockInHolder3StringBuilder.append(CodeReplacer.getReplacer("condition"));
blockInHolder3StringBuilder.append(") {\n\t");
blockInHolder3StringBuilder.append(CodeReplacer.getReplacer("complexBlockContent"));
blockInHolder3StringBuilder.append("\n}");
blockInHolder3.setRawCode(blockInHolder3StringBuilder.toString());
blockInHolder3.setTags(new String[] {"developer", "developerOnly"});

ArrayList<BlockContent> block3ContentList = new ArrayList<BlockContent>();

BlockContent block3Content1 = new BlockContent();
block3Content1.setText("if");
block3ContentList.add(block3Content1);

BooleanContent block3Content2 = new BooleanContent();
block3Content2.setId("condition");
block3ContentList.add(block3Content2);
blockInHolder3.setBlockContent(block3ContentList);

Block blockInHolder4 = new Block();
blockInHolder4.setColor("#009900");
blockInHolder4.setBlockType(Block.BlockType.returnWithTypeBoolean);
Expand Down Expand Up @@ -142,16 +97,15 @@ public static ArrayList<BlocksHolder> getBuiltInBlocksHolder() {

blockInHolder6.setBlockContent(block6ContentList);

blockList.add(blockInHolder1);
blockList.add(blockInHolder2);
blockList.add(blockInHolder3);
blockList.add(blockInHolder4);
blockList.add(blockInHolder5);
blockList.add(blockInHolder6);

holder1.setBlocks(blockList);

blocksHolder.add(holder1);
blocksHolder.add(OperatorBlocks.getBlockHolder());

return blocksHolder;
}
Expand Down
83 changes: 83 additions & 0 deletions app/src/main/java/builtin/blocks/holder/OperatorBlocks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package builtin.blocks.holder;

import com.dragon.ide.objects.Block;
import com.dragon.ide.objects.BlockContent;
import com.dragon.ide.objects.BlocksHolder;
import com.dragon.ide.objects.ComplexBlock;
import com.dragon.ide.objects.blockcontent.BooleanContent;
import com.dragon.ide.objects.blockcontent.SourceContent;
import com.dragon.ide.utils.CodeReplacer;
import editor.tsd.tools.Language;
import java.util.ArrayList;

public class OperatorBlocks {
public static BlocksHolder getBlockHolder() {
BlocksHolder blocksHolder = new BlocksHolder();
blocksHolder.setColor("#009900");
blocksHolder.setName("Operators");
blocksHolder.setTags(new String[] {Language.HTML, Language.CSS, Language.JavaScript});

ArrayList<Block> blocksList = new ArrayList<Block>();

blocksList.add(getIfBlock());
blocksList.add(getAddSourceBlock());

blocksHolder.setBlocks(blocksList);
return blocksHolder;
}

public static Block getAddSourceBlock() {
Block addSource = new Block();
addSource.setColor("#009900");
addSource.setBlockType(Block.BlockType.defaultBlock);
addSource.setName("addSource");
addSource.setRawCode(CodeReplacer.getReplacer("parameter"));
addSource.setTags(new String[] {Language.HTML, Language.CSS, Language.JavaScript});

ArrayList<BlockContent> addSourceContentList = new ArrayList<BlockContent>();

BlockContent addSourceBlockContent1 = new BlockContent();
addSourceBlockContent1.setText("add source");
addSourceContentList.add(addSourceBlockContent1);

SourceContent addSourceBlockContent2 = new SourceContent();
addSourceBlockContent2.setId("parameter");
addSourceContentList.add(addSourceBlockContent2);

addSource.setBlockContent(addSourceContentList);

return addSource;
}

public static Block getIfBlock() {
ComplexBlock ifBlock = new ComplexBlock();
ifBlock.setColor("#009900");
ifBlock.setBlockType(Block.BlockType.complexBlock);
ifBlock.setName("if");

StringBuilder ifBlockStringBuilder = new StringBuilder();
ifBlockStringBuilder.append("if (");
ifBlockStringBuilder.append(CodeReplacer.getReplacer("condition"));
ifBlockStringBuilder.append(") {\n\t");
ifBlockStringBuilder.append(CodeReplacer.getReplacer("complexBlockContent"));
ifBlockStringBuilder.append("\n}");

ifBlock.setRawCode(ifBlockStringBuilder.toString());

ifBlock.setTags(new String[] {Language.JavaScript});

ArrayList<BlockContent> ifBlockContentList = new ArrayList<BlockContent>();

BlockContent ifBlockBlockContent1 = new BlockContent();
ifBlockBlockContent1.setText("if");
ifBlockContentList.add(ifBlockBlockContent1);

BooleanContent ifBlockBlockContent2 = new BooleanContent();
ifBlockBlockContent2.setId("condition");
ifBlockContentList.add(ifBlockBlockContent2);

ifBlock.setBlockContent(ifBlockContentList);

return ifBlock;
}
}

0 comments on commit 3cd2c6b

Please sign in to comment.