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

Class Prim

scratchattach/editor/prim.py:63–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61
62
63class Prim(base.SpriteSubComponent):
64 def __init__(self, _primtype: PrimType | PrimTypes, _value: Optional[str | vlb.Variable | vlb.List | vlb.Broadcast] = None,
65 _name: Optional[str] = None, _id: Optional[str] = None, _x: Optional[int] = None,
66 _y: Optional[int] = None, _sprite: sprite.Sprite = build_defaulting.SPRITE_DEFAULT):
67 """
68 Class representing a Scratch string, number, angle, variable etc.
69 Technically blocks but behave differently
70 https://en.scratch-wiki.info/wiki/Scratch_File_Format#Targets:~:text=A%20few%20blocks,13
71 """
72 if isinstance(_primtype, PrimTypes):
73 _primtype = _primtype.value
74
75 self.type = _primtype
76
77 self.value = _value
78
79 self.name = _name
80 """
81 Once you get the object associated with this primitive (sprite.link_prims()),
82 the name will be removed and the value will be changed from ``None``
83 """
84 self.value_id = _id
85 """
86 It's not an object accessed by id, but it may reference an object with an id.
87
88 ----
89
90 Once you get the object associated with it (sprite.link_prims()),
91 the id will be removed and the value will be changed from ``None``
92 """
93
94 self.x = _x
95 self.y = _y
96
97 super().__init__(_sprite)
98
99 def __repr__(self):
100 if self.is_basic:
101 return f"Prim<{self.type.name}: {self.value}>"
102 elif self.is_vlb:
103 return f"Prim<{self.type.name}: {self.value}>"
104 else:
105 return f"Prim<{self.type.name}>"
106
107 @property
108 def is_vlb(self):
109 return self.type.attrs == VLB_ATTRS
110
111 @property
112 def is_basic(self):
113 return self.type.attrs == BASIC_ATTRS
114
115 @staticmethod
116 def from_json(data: list):
117 assert isinstance(data, list)
118
119 _type_idx = data[0]
120 _prim_type = PrimTypes.find(_type_idx, "code")

Callers 1

from_jsonMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected