36 def __init__(self, offset_x = 0, image_width = 0, image_height = 0, position_x = 0.0, position_y = 0.0, velocity_x = 0.0, velocity_y = 0.0) -> None:
79 def Context(self, context : Flyweight_Context) ->
None:
109 def __init__(self, resource = None, context = Flyweight_Context()) ->
None:
148 def Render(self, display : list[bytearray], offset_x : int, image_width : int, image_height : int, position_x : int, position_y : int) ->
None:
150 self.
_resource.
Render(display, offset_x, image_width, image_height, position_x, position_y)
204 def __init__(self, resource : list[bytearray], resourceId : int):
229 def Render(self, display : list[bytearray], offset_x : int, image_width : int, image_height : int, position_x : int, position_y : int) ->
None:
230 display_width = len(display[0])
231 display_height = len(display)
232 starting_position_x = position_x
233 starting_position_y = position_y
237 image_render_width = image_width
238 image_render_height = image_height
242 starting_row_in_image = 0
243 starting_col_in_image = offset_x
246 if starting_position_x < 0:
247 starting_col_in_image = -starting_position_x
248 image_render_width += starting_position_x
249 starting_position_x = 0
250 elif (starting_position_x + image_render_width) > display_width:
251 image_render_width = display_width - starting_position_x
253 if starting_position_y < 0:
254 starting_row_in_image = -starting_position_y
255 image_render_height += starting_position_y
256 starting_position_y = 0
257 elif (starting_position_y + image_render_height) > display_height:
258 image_render_height = display_height - starting_position_y
261 if image_render_width > 0
and image_render_height > 0:
262 current_display_row = starting_position_y
263 current_image_row = starting_row_in_image
264 for row
in range(0, image_render_height):
265 for col
in range(0, image_render_width):
266 display[current_display_row][starting_position_x + col] = \
267 self.
_resource[current_image_row][starting_col_in_image + col]
268 current_display_row += 1
269 current_image_row += 1
319 nextId = BigResourceManager._nextResourceId
320 ++BigResourceManager._nextResourceId
334 for resource
in BigResourceManager._resources:
335 if resource.ResourceId == resourceId:
336 foundResource = resource
349 newResourceId = BigResourceManager.GetNextResourceId()
350 BigResourceManager._resources.append(
BigResource(rawResource, newResourceId))
368 def CreateFlyweight(bigResourceId : int, context : Flyweight_Context) -> Flyweight_Class:
369 flyweightClass =
None
370 bigResource = BigResourceManager.FindResource(bigResourceId)
372 flyweightClass = bigResource.CreateFlyweight(context)
373 return flyweightClass
Represents some big resource.
int ImageWidth(self)
Property getter for the "image" width of the resource: value = o.ImageWidth
int ImageHeight(self)
Property getter for the "image" height of the resource: value = o.ImageHeight
None Render(self, list[bytearray] display, int offset_x, int image_width, int image_height, int position_x, int position_y)
Render the big resource into the given display at the given position.
_resource
a list of bytearrays representing the image (big resource)
Flyweight_Class CreateFlyweight(self, Flyweight_Context context)
Generate a Flyweight instance that will represent this big resource in some context-dependent way.
int ResourceId(self)
Property getter for the resource ID for this resource: value = o.ResourceId
_resourceId
The unique ID for this resource.
def __init__(self, list[bytearray] resource, int resourceId)
Constructor (accessibly only to the class factory).
Represents a manager for big resources.
Flyweight_Class CreateFlyweight(int bigResourceId, Flyweight_Context context)
Create a new instance of the Flyweight_Class associated with the given big resource and a context,...
int AddResource(list[bytearray] rawResource)
Add a new big resource and return the ID of the resource.
int GetNextResourceId()
Retrieve the next resource ID that can be used.
BigResource FindResource(int resourceId)
Retrieve the BigResource corresponding to the specified ID.
Associates a context with a big resource.
int ImageWidth(self)
Property getter for the "image" width from underlying big resource: value = o.ImageWidth
int ImageHeight(self)
Property getter for the "image" height from underlying big resource: value = o.ImageHeight
_context
The context associated with this class.
None Render(self, list[bytearray] display, int offset_x, int image_width, int image_height, int position_x, int position_y)
Render the image associated with this flyweight instance into the given display at the given position...
_resource
The big resource being referenced by this flyweight class.
None __init__(self, resource=None, context=Flyweight_Context())
Constructor.
Flyweight_Context Context(self)
Property getter for the context for this class instance: value = o.Context
Represents the context for an instance of the Flyweight_Class.
Velocity_X
X velocity as a float.
None __init__(self, offset_x=0, image_width=0, image_height=0, position_x=0.0, position_y=0.0, velocity_x=0.0, velocity_y=0.0)
Constructor.
Position_X
X position of the top left corner of the big resource.
OffsetXToImage
Offset from left edge of big resource image to the left edge of the image for this context.
ImageWidth
Width of image for this context.
Position_Y
Y position of the top left corner of the big resource.
ImageHeight
Height of image for this context.
Velocity_Y
Y velocity, as a float.