MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / Block

Class Block

scratchattach/editor/block.py:11–599  ·  view source on GitHub ↗

Represents a block in the scratch editor, as a subcomponent of a sprite.

Source from the content-addressed store, hash-verified

9
10
11class Block(base.SpriteSubComponent):
12 """
13 Represents a block in the scratch editor, as a subcomponent of a sprite.
14 """
15
16 _id: Optional[str] = None
17
18 def __init__(
19 self,
20 _opcode: str,
21 _shadow: bool = False,
22 _top_level: Optional[bool] = None,
23 _mutation: Optional[mutation.Mutation] = None,
24 _fields: Optional[dict[str, field.Field]] = None,
25 _inputs: Optional[dict[str, inputs.Input]] = None,
26 x: int = 0,
27 y: int = 0,
28 pos: Optional[tuple[int, int]] = None,
29 _next: Optional[Block] = None,
30 _parent: Optional[Block] = None,
31 *,
32 _next_id: Optional[str] = None,
33 _parent_id: Optional[str] = None,
34 _sprite: commons.SpriteInput = build_defaulting.SPRITE_DEFAULT,
35 ):
36 # Defaulting for args
37 if _fields is None:
38 _fields = {}
39 if _inputs is None:
40 _inputs = {}
41
42 if pos is not None:
43 x, y = pos
44
45 self.opcode = _opcode
46 self.is_shadow = _shadow
47 self.is_top_level = _top_level
48
49 self.x, self.y = x, y
50
51 self.mutation = _mutation
52 self.fields = _fields
53 self.inputs = _inputs
54
55 # Temporarily stores id of next block. Will be used later during project instantiation to find the next block object
56 self._next_id = _next_id
57
58 # Temporarily stores id of parent block. Will be used later during project instantiation to find the parent block object
59 self._parent_id = _parent_id
60
61 self.next = _next
62 self.parent = _parent
63
64 self.check_toplevel()
65
66 super().__init__(_sprite)
67 self.link_subcomponents()
68

Callers 1

from_jsonMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected