rk_island/game/scene.py

90 lines
2.4 KiB
Python
Raw Normal View History

2022-12-31 19:16:44 +01:00
# Copyright (C) 2022 RozK
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class Node:
__slots__ = '_subnodes'
def __init__(self, *subnodes):
self._subnodes = subnodes
def draw(self, time):
for subnode in self._subnodes:
subnode.draw(time)
class SceneNode(Node):
2022-12-31 20:23:27 +01:00
pass
2022-12-31 19:16:44 +01:00
class TextureNode(Node):
__slots__ = '_textures'
def __init__(self, textures, *subnodes):
Node.__init__(self, *subnodes)
self._textures = textures
def draw(self, time):
2022-12-31 21:45:29 +01:00
items = self._textures.items()
for slot, texture in items:
2022-12-31 19:16:44 +01:00
texture.select(slot)
Node.draw(self, time)
2022-12-31 21:45:29 +01:00
for slot, texture in items:
2022-12-31 19:16:44 +01:00
texture.unselect(slot)
class ShaderNode(Node):
__slots__ = '_shader'
def __init__(self, shader, *subnodes):
Node.__init__(self, *subnodes)
self._shader = shader
def draw(self, time):
self._shader.select()
Node.draw(self, time)
self._shader.unselect()
class InputNode(Node):
__slots__ = '_shader', '_input'
def __init__(self, shader, input, *subnodes):
Node.__init__(self, *subnodes)
self._shader = shader
self._input = input
def draw(self, time):
self._input.set_inputs(self._shader)
Node.draw(self, time)
class DrawNode(Node):
__slots__ = '_drawable'
def __init__(self, drawable, *subnodes):
Node.__init__(self, *subnodes)
self._drawable = drawable
def draw(self, time):
self._drawable.draw()
Node.draw(self, time)
class FuncNode(Node):
__slots__ = '_func', '_params'
def __init__(self, func, params, *subnodes):
Node.__init__(self, *subnodes)
self._func = func
self._params = params
def draw(self, time):
self._func(time, *self._params)
Node.draw(self, time)