Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions boiga/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from . import ast_core as core
from .ast_core import ensure_expression, Literal, LiteralColour

# MOTION
# BEGIN MOTION

class SetXYPos(core.Statement):
def __init__(self, x, y):
Expand Down Expand Up @@ -45,14 +45,14 @@ def __init__(self):

# END MOTION

# LOOKS
# BEGIN LOOKS

class SetCostume(core.Statement):
def __init__(self, costume):
if type(costume) is str:
costume = core.Costume(costume)
super().__init__("looks_switchcostumeto",
COSTUME=costume)
def __init__(self, costume):
if isinstance(costume, (str, int)):
costume = core.Costume(costume)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think int is valid here? The goal of boiga is to only emit scratch code that could have been created manually.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch allows assignment of costume based on integers: try this for example

ScratchInt.png

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but you have to do it via a (() + (0)) block. I am open to supporting this in boiga but it needs to emit code that looks just like this.

super().__init__("looks_switchcostumeto",
COSTUME=costume)

class Say(core.Statement):
def __init__(self, msg):
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(self):

# END SOUND

# EVENTS
# BEGIN EVENTS

class BroadcastAndWait(core.Statement):
def __init__(self, event):
Expand Down Expand Up @@ -178,6 +178,10 @@ class CostumeNumber(core.Expression):
def __init__(self):
pass

class CostumeName(core.Expression):
def __init__(self):
pass

class DaysSince2k(core.Expression):
def __init__(self):
pass
Expand Down
8 changes: 8 additions & 0 deletions boiga/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ def serialise_expression(sprite, expression, parent, shadow=False):
"NUMBER_NAME": ["number", None]
},
}

elif type(expression) is ast.CostumeName:
out = {
"opcode": "looks_costumenumbername",
"fields": {
"NUMBER_NAME": ["name", None]
},
}

elif type(expression) is ast.Touching:
out = {
Expand Down