Legend of the Gold Box... A game written for the LOWREZJAM 2018 game jam
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

723 lines
24KB

  1. '''
  2. Filename nodes.py
  3. Author: Bryan "ObsidianBlk" Miller
  4. Date Created: 8/1/2018
  5. Python Version: 3.7
  6. '''
  7. from .display import Display
  8. from .events import Events
  9. from .resource import ResourceManager
  10. import pygame
  11. class NodeError(Exception):
  12. pass
  13. class Node:
  14. def __init__(self, name="Node", parent=None):
  15. self._NODE_DATA={
  16. "parent":None,
  17. "name":name,
  18. "children":[],
  19. "resource":None,
  20. "position":(0,0)
  21. }
  22. if parent is not None:
  23. try:
  24. self.parent = parent
  25. except NodeError as e:
  26. raise e
  27. @property
  28. def parent(self):
  29. return self._NODE_DATA["parent"]
  30. @parent.setter
  31. def parent(self, new_parent):
  32. try:
  33. self.parent_to_node(new_parent)
  34. except NodeError as e:
  35. raise e
  36. @property
  37. def root(self):
  38. if self.parent is None:
  39. return self
  40. return self.parent.root
  41. @property
  42. def name(self):
  43. return self._NODE_DATA["name"]
  44. @name.setter
  45. def name(self, value):
  46. if self.parent is not None:
  47. if self.parent.get_node(value) is not None:
  48. raise NodeError("Parent already contains node named '{}'.".format(name))
  49. self._NODE_DATA["name"] = value
  50. @property
  51. def full_name(self):
  52. if self.parent is None:
  53. return self.name
  54. return self.parent.full_name + "." + self.name
  55. @property
  56. def resource(self):
  57. if self._NODE_DATA["resource"] is None:
  58. # Only bother creating the instance if it's being asked for.
  59. # All ResourceManager instances access same data.
  60. self._NODE_DATA["resource"] = ResourceManager()
  61. return self._NODE_DATA["resource"]
  62. @property
  63. def child_count(self):
  64. return len(this._NODE_DATA["children"])
  65. @property
  66. def position(self):
  67. p = self._NODE_DATA["position"]
  68. return (p[0], p[1])
  69. @position.setter
  70. def position(self, pos):
  71. if not isinstance(pos, (list, tuple)):
  72. raise TypeError("Expected a list or tuple.")
  73. if len(pos) != 2:
  74. raise ValueError("Wrong number of values given.")
  75. try:
  76. self.position_x = pos[0]
  77. self.position_y = pos[1]
  78. except Exception as e:
  79. raise e
  80. @property
  81. def position_x(self):
  82. return self._NODE_DATA["position"][0]
  83. @position_x.setter
  84. def position_x(self, v):
  85. if not isinstance(v, (int, float)):
  86. raise TypeError("Excepted an number value.")
  87. self._NODE_DATA["position"][0] = float(v)
  88. @property
  89. def position_y(self):
  90. return self._NODE_DATA["position"][1]
  91. @position_y.setter
  92. def position_y(self, v):
  93. if not isinstance(v, (int, float)):
  94. raise TypeError("Excepted an number value.")
  95. self._NODE_DATA["position"][1] = float(v)
  96. def get_world_position(self):
  97. if self.parent is None:
  98. return (0,0)
  99. pos = self.position
  100. ppos = self.parent.get_world_position()
  101. return (pos[0] + ppos[0], pos[1] + ppos[1])
  102. def parent_to_node(self, parent, allow_reparenting=False):
  103. if not isinstance(value, Node):
  104. raise NodeError("Node may only parent to another Node instance.")
  105. if self.parent is None or self.parent != parent:
  106. if self.parent is not None:
  107. if allow_Reparenting == False:
  108. raise NodeError("Node already assigned a parent Node.")
  109. if self.parent.remove_node(self) != self:
  110. raise NodeError("Failed to remove self from current parent.")
  111. try:
  112. parent.attach_node(self)
  113. except NodeError as e:
  114. raise e
  115. def attach_node(self, node, reparent=False, index=-1):
  116. if node.parent is not None:
  117. if node.parent == self:
  118. return # Nothing to do. Given node already parented to this node.
  119. if reparent == False:
  120. raise NodeError("Node already parented.")
  121. if node.parent.remove_node(node) != node:
  122. raise NodeError("Failed to remove given node from it's current parent.")
  123. if self.get_node(node.name) is not None:
  124. raise NodeError("Node with name '{}' already attached.".format(node.name))
  125. node._NODE_DATA["parent"] = self
  126. children = self._NODE_DATA["children"]
  127. if index < 0 or index >= len(children):
  128. children.append(node)
  129. else:
  130. children.insert(index, node)
  131. def remove_node(self, node):
  132. if isinstance(node, (str, unicode)):
  133. n = self.get_node(node)
  134. if n is not None:
  135. try:
  136. return self.remove_node(n)
  137. except NodeError as e:
  138. raise e
  139. elif isinstance(node, Node):
  140. if node.parent != self:
  141. if node.parent == None:
  142. raise NodeError("Cannot remove an unparented node.")
  143. try:
  144. return node.parent.remove_node(node)
  145. except NodeError as e:
  146. raise e
  147. if node in self._NODE_DATA["children"]:
  148. self._NODE_DATA["children"].remove(node)
  149. node._NODE_DATA["parent"] = None
  150. return node
  151. else:
  152. raise NodeError("Expected a Node instance or a string.")
  153. return None
  154. def get_node(self, name):
  155. if self.child_count <= 0:
  156. return None
  157. subnames = name.split(".")
  158. for c in self._NODE_DATA["children"]:
  159. if c.name == subnames[0]:
  160. if len(subnames) > 1:
  161. return c.get_node(".".join(subnames[1:-1]))
  162. return c
  163. return None
  164. def _init(self):
  165. if hasattr(self, "on_init"):
  166. self.on_init()
  167. for c in self._NODE_DATA["children"]:
  168. c._init()
  169. def _close(self):
  170. if hasattr(self, "on_close"):
  171. self.on_close()
  172. for c in self._NODE_DATA["children"]:
  173. c._close()
  174. def _pause(self):
  175. if hasattr(self, "on_pause"):
  176. self.on_pause()
  177. for c in self._NODE_DATA["children"]:
  178. c._pause()
  179. def _update(self, dt):
  180. if hasattr(self, "on_update"):
  181. self.on_update(dt)
  182. for c in self._NODE_DATA["children"]:
  183. c._update(dt)
  184. def _render(self, surface):
  185. for c in self._NODE_DATA["children"]:
  186. c._render(surface)
  187. class Node2D(Node):
  188. def __init__(self, name="Node2D", parent=None):
  189. try:
  190. Node.__init__(self, name, parent)
  191. except NodeError as e:
  192. raise e
  193. def _callOnRender(self, surface):
  194. if hasattr(self, "on_render"):
  195. self._ACTIVE_SURF = surface
  196. self.on_render()
  197. del self._ACTIVE_SURF
  198. def _render(self, surface):
  199. self._callOnRender(surface)
  200. Node._render(self, surface)
  201. def draw_image(self, img, pos=(0,0), rect=None):
  202. if not hasattr(self, "_ACTIVE_SURF"):
  203. return
  204. self._ACTIVE_SURF.blit(img, pos, rect)
  205. def fill(self, color):
  206. if not hasattr(self, "_ACTIVE_SURF"):
  207. return
  208. self._ACTIVE_SURF.fill(color)
  209. def draw_lines(self, points, color, thickness=1, closed=False):
  210. if not hasattr(self, "_ACTIVE_SURF"):
  211. return
  212. pygame.draw.lines(self._ACTIVE_SURF, color, closed, points, thickness)
  213. def draw_rect(self, rect, color, thickness=1):
  214. if not hasattr(self, "_ACTIVE_SURF"):
  215. return
  216. pygame.draw.rect(self._ACTIVE_SURF, color, rect, thickness)
  217. def draw_ellipse(self, rect, color, thickness=1, fill_color=None):
  218. if not hasattr(self, "_ACTIVE_SURF"):
  219. return
  220. if fill_color is not None:
  221. pygame.draw.ellipse(self._ACTIVE_SURF, fill_color, rect)
  222. if thickness > 0:
  223. pygame.draw.ellipse(self._ACTIVE_SURF, color, rect, thickness)
  224. def draw_circle(self, pos, radius, color, thickness=1, fill_color=None):
  225. if not hasattr(self, "_ACTIVE_SURF"):
  226. return
  227. if fill_color is not None:
  228. pygame.draw.circle(self._ACTIVE_SURF, fill_color, pos, radius)
  229. if thickness > 0:
  230. pygame.draw.circle(self._ACTIVE_SURF, color, pos, radius, thickness)
  231. def draw_polygon(self, points, color, thickness=1, fill_color=None):
  232. if not hasattr(self, "_ACTIVE_SURF"):
  233. return
  234. if fill_color is not None:
  235. pygame.draw.polygon(self._ACTIVE_SURF, fill_color, points)
  236. if thickness >= 1:
  237. pygame.draw.polygon(self._ACTIVE_SURF, color, points, thickness)
  238. class NodeSurface(Node2D):
  239. def __init__(self, name="NodeSurface", parent=None):
  240. try:
  241. Node2D.__init__(self, name, parent)
  242. except NodeError as e:
  243. raise e
  244. # TODO: Update this class to use the _NODE*_DATA={} structure.
  245. self._scale = (1.0, 1.0)
  246. self._scaleToDisplay = False
  247. self._scaleDirty = False
  248. self._keepAspectRatio = False
  249. self._alignCenter = False
  250. self._surface = None
  251. self._tsurface = None
  252. self.set_surface()
  253. def _updateTransformSurface(self):
  254. if self._surface is None:
  255. return
  256. self._scaleDirty = False
  257. if self._scaleToDisplay:
  258. dsize = Display.resolution
  259. ssize = self._surface.get_size()
  260. self._scale = (dsize[0] / ssize[0], dsize[1] / ssize[1])
  261. if self._keepAspectRatio:
  262. if self._scale[0] < self._scale[1]:
  263. self._scale = (self._scale[0], self._scale[0])
  264. else:
  265. self._scale = (self._scale[1], self._scale[1])
  266. if self._scale[0] == 1.0 and self._scale[1] == 1.0:
  267. self._tsurface = None
  268. return
  269. size = self._surface.get_size()
  270. nw = size[0] * self._scale[0]
  271. nh = 0
  272. if self._keepAspectRatio:
  273. nh = size[1] * self._scale[0]
  274. else:
  275. nh = size[1] * self._scale[1]
  276. self._tsurface = pygame.Surface((nw, nh), pygame.SRCALPHA, self._surface)
  277. self._tsurface.fill(pygame.Color(0,0,0,0))
  278. @property
  279. def resolution(self):
  280. if self._surface is None:
  281. return (0,0)
  282. return self._surface.get_size()
  283. @resolution.setter
  284. def resolution(self, res):
  285. try:
  286. self.set_surface(res)
  287. except (TypeError, ValueError) as e:
  288. raise e
  289. @property
  290. def width(self):
  291. return self.resolution[0]
  292. @property
  293. def height(self):
  294. return self.resolution[1]
  295. @property
  296. def scale(self):
  297. return self._scale
  298. @scale.setter
  299. def scale(self, scale):
  300. if self._keepAspectRatio:
  301. if not isinstance(scale, (int, float)):
  302. raise TypeError("Expected number value.")
  303. self._scale = (scale, self._scale[1])
  304. else:
  305. if not isinstance(scale, tuple):
  306. raise TypeError("Expected a tuple")
  307. if len(scale) != 2:
  308. raise ValueError("Expected tuple of length two.")
  309. if not isinstance(scale[0], (int, float)) or not isinstance(scale[1], (int, float)):
  310. raise TypeError("Expected number values.")
  311. self._scale = scale
  312. self._updateTransformSurface()
  313. @property
  314. def keep_aspect_ratio(self):
  315. return self._keepAspectRatio
  316. @keep_aspect_ratio.setter
  317. def keep_aspect_ratio(self, keep):
  318. self._keepAspectRatio = (keep == True)
  319. self._updateTransformSurface()
  320. @property
  321. def align_center(self):
  322. return self._alignCenter
  323. @align_center.setter
  324. def align_center(self, center):
  325. self._alignCenter = (center == True)
  326. @property
  327. def scale_to_display(self):
  328. return self._scaleToDisplay
  329. @scale_to_display.setter
  330. def scale_to_display(self, todisplay):
  331. if todisplay == True:
  332. self._scaleToDisplay = True
  333. Events.listen("VIDEORESIZE", self._OnVideoResize)
  334. else:
  335. self._scaleToDisplay = False
  336. Events.unlisten("VIDEORESIZE", self._OnVideoResize)
  337. self._updateTransformSurface()
  338. def scale_to(self, target_resolution):
  339. if self._surface is not None:
  340. size = self._surface.get_size()
  341. nscale = (float(size[0]) / float(target_resolution[0]), float(size[1]) / float(target_resolution[1]))
  342. self.scale = nscale
  343. def set_surface(self, resolution=None):
  344. dsurf = Display.surface
  345. if resolution is None:
  346. if dsurf is not None:
  347. self._surface = dsurf.convert_alpha()
  348. self._surface.fill(pygame.Color(0,0,0,0))
  349. self._updateTransformSurface()
  350. else:
  351. if not isinstance(resolution, tuple):
  352. raise TypeError("Expected a tuple.")
  353. if len(resolution) != 2:
  354. raise ValueError("Expected a tuple of length two.")
  355. if not isinstance(resolution[0], int) or not isinstance(resolution[1], int):
  356. raise TypeError("Tuple expected to contain integers.")
  357. if dsurf is not None:
  358. self._surface = pygame.Surface(resolution, pygame.SRCALPHA, dsurf)
  359. else:
  360. self._surface = pygame.Surface(resolution, pygame.SRCALPHA)
  361. self._surface.fill(pygame.Color(0,0,0,0))
  362. self._updateTransformSurface()
  363. def _render(self, surface):
  364. if self._surface is None:
  365. self.set_surface()
  366. if self._surface is not None:
  367. if self._scaleDirty:
  368. self._updateTransformSurface()
  369. Node2D._render(self, self._surface)
  370. else:
  371. Node2D._render(self, surface)
  372. self._scale_and_blit(surface)
  373. def _scale_and_blit(self, dest):
  374. dsize = dest.get_size()
  375. src = self._surface
  376. if self._tsurface is not None:
  377. pygame.transform.scale(self._surface, self._tsurface.get_size(), self._tsurface)
  378. src = self._tsurface
  379. ssize = src.get_size()
  380. posx = self.position_x
  381. posy = self.position_y
  382. if self._alignCenter:
  383. if dsize[0] > ssize[0]:
  384. posx += (dsize[0] - ssize[0]) * 0.5
  385. if dsize[1] > ssize[1]:
  386. posy += (dsize[1] - ssize[1]) * 0.5
  387. pos = (int(posx), int(posy))
  388. dest.blit(src, pos)
  389. def _OnVideoResize(self, event, data):
  390. if self._scaleToDisplay:
  391. self._scaleDirty = True
  392. class NodeSprite(Node2D):
  393. def __init__(self, name="NodeSprite", parent=None):
  394. try:
  395. Node2D.__init__(self, name, parent)
  396. except NodeError as e:
  397. raise e
  398. self._NODESPRITE_DATA={
  399. "rect":[0,0,0,0],
  400. "image":"",
  401. "scale":[1.0, 1.0],
  402. "surface":None
  403. }
  404. @property
  405. def image_width(self):
  406. if self._NODESPRITE_DATA["surface"] is None:
  407. return 0
  408. surf = self._NODESPRITE_DATA["surface"]()
  409. return surf.get_width()
  410. @property
  411. def image_height(self):
  412. if self._NODESPRITE_DATA["surface"] is None:
  413. return 0
  414. surf = self._NODESPRITE_DATA["surface"]()
  415. return surf.get_height()
  416. @property
  417. def sprite_width(self):
  418. return int(self.rect_width * self.scale_x)
  419. @property
  420. def sprite_height(self):
  421. return int(self.rect_height * self.scale_y)
  422. @property
  423. def rect(self):
  424. return (self._NODESPRITE_DATA["rect"][0],
  425. self._NODESPRITE_DATA["rect"][1],
  426. self._NODESPRITE_DATA["rect"][2],
  427. self._NODESPRITE_DATA["rect"][3])
  428. @rect.setter
  429. def rect(self, rect):
  430. if not isinstance(rect, (list, tuple)):
  431. raise TypeError("Expected a list or tuple.")
  432. if len(rect) != 4:
  433. raise ValueError("rect value contains wrong number of values.")
  434. try:
  435. self.rect_x = rect[0]
  436. self.rect_y = rect[1]
  437. self.rect_width = rect[2]
  438. self.rect_height = rect[3]
  439. except Exception as e:
  440. raise e
  441. @property
  442. def rect_x(self):
  443. return self._NODESPRITE_DATA["rect"][0]
  444. @rect_x.setter
  445. def rect_x(self, v):
  446. if not isinstance(v, int):
  447. raise TypeError("Expected integer value.")
  448. self._NODESPRITE_DATA["rect"][0] = v
  449. self._NODESPRITE_ValidateRect()
  450. @property
  451. def rect_y(self):
  452. return self._NODESPRITE_DATA["rect"][1]
  453. @rect_y.setter
  454. def rect_y(self, v):
  455. if not isinstance(v, int):
  456. raise TypeError("Expected integer value.")
  457. self._NODESPRITE_DATA["rect"][1] = v
  458. self._NODESPRITE_ValidateRect()
  459. @property
  460. def rect_width(self):
  461. return self._NODESPRITE_DATA["rect"][2]
  462. @rect_width.setter
  463. def rect_width(self, v):
  464. if not isinstance(v, int):
  465. raise TypeError("Expected integer value.")
  466. self._NODESPRITE_DATA["rect"][2] = v
  467. self._NODESPRITE_ValidateRect()
  468. @property
  469. def rect_height(self):
  470. return self._NODESPRITE_DATA["rect"][3]
  471. @rect_height.setter
  472. def rect_height(self, v):
  473. if not isinstance(v, int):
  474. raise TypeError("Expected integer value.")
  475. self._NODESPRITE_DATA["rect"][3] = v
  476. self._NODESPRITE_ValidateRect()
  477. @property
  478. def center(self):
  479. r = self._NODESPRITE_DATA["rect"]
  480. return (int(r[0] + (r[2] * 0.5)), int(r[1] + (r[3] * 0.5)))
  481. @property
  482. def scale(self):
  483. return (self._NODESPRITE_DATA["scale"][0], self._NODESPRITE_DATA["scale"][1])
  484. @scale.setter
  485. def scale(self, scale):
  486. if not isinstance(scale, (list, tuple)):
  487. raise TypeError("Expected a list or tuple.")
  488. if len(scale) != 2:
  489. raise ValueError("Scale contains wrong number of values.")
  490. try:
  491. self.scale_x = scale[0]
  492. self.scale_y = scale[1]
  493. except Exception as e:
  494. raise e
  495. @property
  496. def scale_x(self):
  497. return self._NODESPRITE_DATA["scale"][0]
  498. @scale_x.setter
  499. def scale_x(self, v):
  500. if not isinstance(v, (int, float)):
  501. raise TypeError("Expected number value.")
  502. self._NODESPRITE_DATA["scale"][0] = float(v)
  503. self._NODESPRITE_DATA["scale_dirty"] = True
  504. @property
  505. def scale_y(self):
  506. return self._NODESPRITE_DATA["scale"][1]
  507. @scale_y.setter
  508. def scale_y(self, v):
  509. if not isinstance(v, (int, float)):
  510. raise TypeError("Expected number value.")
  511. self._NODESPRITE_DATA["scale"][1] = float(v)
  512. self._NODESPRITE_DATA["scale_dirty"] = True
  513. @property
  514. def image(self):
  515. return self._NODESPRITE_DATA["image"]
  516. @image.setter
  517. def image(self, src):
  518. src = src.strip()
  519. if self._NODESPRITE_DATA["image"] == src:
  520. return # Nothing to change... lol
  521. if self._NODESPRITE_DATA["image"] != "":
  522. self._NODESPRITE_DATA["surface"] = None # Clear reference to original surface.
  523. if src != "":
  524. rm = self.resource
  525. try:
  526. if not rm.has("graphic", src):
  527. rm.store("graphic", src)
  528. self._NODESPRITE_DATA["image"] = src
  529. self._NODESPRITE_DATA["surface"] = rm.get("graphic", src)
  530. if self._NODESPRITE_DATA["surface"] is None:
  531. self._NODESPRITE_DATA["image"] = ""
  532. self._NODESPRITE_DATA["rect"]=[0,0,0,0]
  533. else:
  534. # Resetting the rect to identity for the new image.
  535. surf = self._NODESPRITE_DATA["surface"]()
  536. size = surf.get_size()
  537. self._NODESPRITE_DATA["rect"]=[0,0,size[0], size[1]]
  538. except Exception as e:
  539. raise e
  540. else:
  541. self._NODESPRITE_DATA["image"] = ""
  542. self._NODESPRITE_DATA["rect"]=[0,0,0,0]
  543. def _render(self, surface):
  544. # Call the on_render() method, if any
  545. Node2D._callOnRender(self, surface)
  546. # Paint the sprite onto the surface
  547. if self._NODESPRITE_DATA["surface"] is not None:
  548. rect = self._NODESPRITE_DATA["rect"]
  549. scale = self._NODESPRITE_DATA["scale"]
  550. surf = self._NODESPRITE_DATA["surface"]()
  551. # Of course, only bother if we have a surface to work with.
  552. if surf is not None:
  553. # Do some prescaling work, if needed.
  554. if self._NODESPRITE_DATA["scale_dirty"]:
  555. self._NODESPRITE_UpdateScaleSurface(scale, surf)
  556. fsurf = surf # Initial assumption that the surface is also the "frame"
  557. # If we have a "frame" surface, however, let's get it and blit the rect into the frame surface.
  558. if "frame_surf" in self._NODESPRITE_DATA:
  559. fsurf = self._NODESPRITE_DATA["frame_surf"]
  560. fsurf.blit(surf, (0, 0), rect)
  561. # If scaling, then transform (scale) the frame surface into the scale surface and set the frame surface to the scale surface.
  562. if "scale_surf" in self._NODESPRITE_DATA:
  563. ssurf = self._NODESPRITE_DATA["scale_surf"]
  564. pygame.transform.scale(fsurf, ssurf.get_size(), ssurf)
  565. fsurf = ssurf
  566. # Place the sprite! WHEEEEE!
  567. pos = self.position
  568. surface.blit(fsurf, pos)
  569. # Call on all children
  570. Node._render(self, surface)
  571. def _NODESPRITE_UpdateScaleSurface(self, scale, surf):
  572. self._NODESPRITE_DATA["scale_dirty"] = False
  573. ssurf = None
  574. if "scale_surf" in self._NODESPRITE_DATA:
  575. ssurf = self._NODESPRITE_DATA["scale_surf"]
  576. if scale[0] == 1.0 and scale[1] == 1.0:
  577. if ssurf is not None:
  578. del self._NODESPRITE_DATA["scale_surf"]
  579. return
  580. nw = int(self.rect_width * scale[0])
  581. nh = int(self.rect_height * scale[1])
  582. if nw != ssurf.get_width() or nh != ssurf.get_height():
  583. ssurf = pygame.Surface((nw, nh), pygame.SRCALPHA, surf)
  584. ssurf.fill(pygame.Color(0,0,0,0))
  585. self._NODESPRITE_DATA["scale_surf"] = ssurf
  586. def _NODESPRITE_ValidateRect(self):
  587. if self._NODESPRITE_DATA["surface"] is None:
  588. self._NODESPRITE_DATA["rect"] = [0,0,0,0]
  589. else:
  590. rect = self._NODESPRITE_DATA["rect"]
  591. isize = (self.image_width, self.image_height)
  592. if rect[0] < 0:
  593. rect[2] += rect[0]
  594. rect[0] = 0
  595. elif rect[0] >= isize[0]:
  596. rect[0] = isize[0]-1
  597. rect[2] = 0
  598. if rect[1] < 0:
  599. rect[3] += rect[1]
  600. rect[1] = 0
  601. elif rect[1] >= isize[1]:
  602. rect[1] = isize[1]-1
  603. rect[3] = 0
  604. if rect[2] < 0:
  605. rect[2] = 0
  606. elif rect[0] + rect[2] > isize[0]:
  607. rect[2] = isize[0] - rect[0]
  608. if rect[3] < 0:
  609. rect[3] = 0
  610. elif rect[1] + rect[3] > isize[1]:
  611. rect[3] = isize[1] - rect[1]
  612. fssize = [0,0]
  613. if rect[2] > 0 and rect[3] > 0:
  614. if rect[2] < isize[0] or rect[1] < isize[1]:
  615. surf = self._NODESPRITE_DATA["surface"]()
  616. self._NODESPRITE_DATA["frame_surf"] = pygame.Surface((rect[2], rect[3]), pygame.SRCALPHA, surf)
  617. if fssize[0] > 0 and fssize[1] > 0:
  618. pass
  619. elif "frame_surf" in self._NODESPRITE_DATA:
  620. del self._NODESPRITE_DATA["frame_surf"]