albertz / PyOverheadGame

simple Python game with 2D top-down perspective
Apache License 2.0
9 stars 3 forks source link

pyglet.graphics.Batch: AttributeError: 'Batch' object has no attribute 'add' #1

Open albertz opened 2 years ago

albertz commented 2 years ago
Traceback (most recent call last):
  File "/Users/az/Programmierung/PyOverheadGame/main.py", line 20, in <module>
    line: main()
    locals:
      main = <local> <function main at 0x120cdeee0>
  File "/Users/az/Programmierung/PyOverheadGame/game/app.py", line 129, in main
    line: App().main()
    locals:
      App = <global> <class 'game.app.App'>
      main = <global> <function main at 0x120cdeee0>
  File "/Users/az/Programmierung/PyOverheadGame/game/app.py", line 18, in App.__init__
    line: self.game = Game()
    locals:
      self = <local> <game.app.App object at 0x117f05fd0>
      self.game = <local> !AttributeError: 'App' object has no attribute 'game'
      Game = <global> <class 'game.game.Game'>
  File "/Users/az/Programmierung/PyOverheadGame/game/game.py", line 69, in Game.__init__
    line: self.main_menu = MainMenu(game=self)
    locals:
      self = <local> <game.game.Game object at 0x126f8adf0>
      self.main_menu = <local> !AttributeError: 'Game' object has no attribute 'main_menu'
      MainMenu = <global> <class 'game.game.MainMenu'>
      game = <not found>
  File "/Users/az/Programmierung/PyOverheadGame/game/game.py", line 358, in MainMenu.__init__
    line: ("Save", SaveGameMenu(game=game).open),
    locals:
      SaveGameMenu = <global> <class 'game.game.SaveGameMenu'>
      game = <local> <game.game.Game object at 0x126f8adf0>
      open = <builtin> <built-in function open>
  File "/Users/az/Programmierung/PyOverheadGame/game/game.py", line 433, in SaveGameMenu.__init__
    line: super(SaveGameMenu, self).__init__(
              window_stack=game.window_stack, title="Save game under name:",
              callback=self.save_game)
    locals:
      super = <builtin> <class 'super'>
      SaveGameMenu = <global> <class 'game.game.SaveGameMenu'>
      self = <local> <game.game.SaveGameMenu object at 0x132af0d60>
      __init__ = <not found>
      window_stack = <not found>
      game = <local> <game.game.Game object at 0x126f8adf0>
      game.window_stack = <local> <game.gui.WindowStack object at 0x126f9c730>
      title = <not found>
      callback = <not found>
      self.save_game = <local> <bound method SaveGameMenu.save_game of <game.game.SaveGameMenu object at 0x132af0d60>>
  File "/Users/az/Programmierung/PyOverheadGame/game/gui.py", line 286, in TextInput.__init__
    line: self.rectangle = Rectangle(
              x - pad, y - pad,
              x + self.text_width + pad, y + self.text_height + pad, self.batch)
    locals:
      self = <local> <game.game.SaveGameMenu object at 0x132af0d60>
      self.rectangle = <local> !AttributeError: 'SaveGameMenu' object has no attribute 'rectangle'
      Rectangle = <global> <class 'game.gui.Rectangle'>
      x = <local> 0
      pad = <local> 2
      y = <local> 0
      self.text_width = <local> 240
      self.text_height = <local> 28
      self.batch = <local> <pyglet.graphics.Batch object at 0x132af0d90>
  File "/Users/az/Programmierung/PyOverheadGame/game/gui.py", line 250, in Rectangle.__init__
    line: self.vertex_list = batch.add(4, pyglet.gl.GL_QUADS, None,
              ('v2i', [x1, y1, x2, y1, x2, y2, x1, y2]),
              ('c4B', [200, 200, 220, 255] * 4)
          )
    locals:
      self = <local> <game.gui.Rectangle object at 0x132b818e0>
      self.vertex_list = <local> !AttributeError: 'Rectangle' object has no attribute 'vertex_list'
      batch = <local> <pyglet.graphics.Batch object at 0x132af0d90>
      batch.add = <local> !AttributeError: 'Batch' object has no attribute 'add'
      pyglet = <local> <module 'pyglet' from '/Users/az/.local/lib/python3.9/site-packages/pyglet/__init__.py'>
      pyglet.gl = <local> <module 'pyglet.gl' from '/Users/az/.local/lib/python3.9/site-packages/pyglet/gl/__init__.py'>
      pyglet.gl.GL_QUADS = <local> 7
      x1 = <local> -2
      y1 = <local> -2
      x2 = <local> 242
      y2 = <local> 30
AttributeError: 'Batch' object has no attribute 'add'
albertz commented 2 years ago

Reported upstream: https://github.com/pyglet/pyglet/issues/696

albertz commented 2 years ago

It seems I need to migrate some pyglet Batch related code to pyglet 2.

I think I have done that now. However, now I stumble upon some Arcade error. Probably I need to migrate sth there as well...

...
  File "/Users/az/Programmierung/PyOverheadGame/game/gui.py", line 123, in <listcomp>
    line: arcade.create_text(
              act[0], color=arcade.color.BLACK, anchor_y="center", font_size=20)
    locals:
      arcade = <global> <module 'arcade' from '/Users/az/.local/lib/python3.9/site-packages/arcade/__init__.py'>
      arcade.create_text = <global> !AttributeError: module 'arcade' has no attribute 'create_text'
      act = <local> ("Game 'robot'", <function SelectGameMenu.__init__.<locals>.make_load_action_tuple.<locals>.<lambda> at 0x12fac6d30>), _[0]: {len = 12}
      color = <not found>
      arcade.color = <global> <module 'arcade.color' from '/Users/az/.local/lib/python3.9/site-packages/arcade/color/__init__.py'>
      arcade.color.BLACK = <global> (0, 0, 0)
      anchor_y = <not found>
      font_size = <not found>
AttributeError: module 'arcade' has no attribute 'create_text'

I found that someone reported this here: https://github.com/pythonarcade/arcade/issues/1339