preload gif frames, move music into resource folder

This commit is contained in:
frank 2022-03-19 18:32:29 -04:00
parent 81beea7f5e
commit e88c4b8937
8 changed files with 34 additions and 23 deletions

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "lib/pgfw"]
path = lib/pgfw
url = /home/pi/projects/scrapeboard_copy/lib/pgfw
url = frank@shampoo.ooo:/var/www/git/pgfw

45
NS.py
View File

@ -814,11 +814,11 @@ class Video(Sprite):
Sprite.__init__(self, parent, 100)
self.next_video_chance = next_video_chance
pattern = join(self.get_resource("gif"), "Boarding_*.gif")
self.gifs = []
gifs = []
for path in iglob(pattern):
self.gifs.append(Image.open(path))
print(self.gifs[-1].info)
self.gif = self.gifs[1]
gifs.append(Image.open(path))
print(gifs[-1].info)
self.gif_index = 0
self.mask = Surface([diameter] * 2, SRCALPHA)
rect = self.mask.get_rect()
alpha = int(self.get_configuration("display", "attract-gif-alpha") * 255)
@ -827,25 +827,36 @@ class Video(Sprite):
self.add_frame(self.mask)
if not self.get_configuration("system", "minimize-load-time"):
self.play()
# preload GIF frames scaled instead of loading each frame like before
self.gif_frames_scaled = []
for gif in gifs:
self.gif_frames_scaled.append([])
for ii in range(0, gif.n_frames):
gif.seek(ii)
frame_scaled = smoothscale(
fromstring(gif.convert("RGBA").tobytes(), gif.size, "RGBA"),
(self.mask.get_width(), int(gif.width * gif.height / self.mask.get_width())))
copy = self.mask.copy()
rect = frame_scaled.get_rect()
rect.bottom = copy.get_rect().bottom
copy.blit(frame_scaled, rect, None, BLEND_RGBA_MIN)
self.gif_frames_scaled[-1].append(copy)
self.load_selection()
def load_selection(self):
self.clear_frames()
for frame in self.gif_frames_scaled[self.gif_index]:
self.add_frame(frame)
def shift_frame(self):
Sprite.shift_frame(self)
if random() < self.next_video_chance:
while True:
selection = choice(self.gifs)
if selection != self.gif:
self.gif = selection
selection = choice(range(0, len(self.gif_frames_scaled)))
if selection != self.gif_index:
self.gif_index = selection
self.load_selection()
break
self.gif.seek((self.gif.tell() + 1) % self.gif.n_frames)
frame = smoothscale(
fromstring(self.gif.convert("RGBA").tobytes(), self.gif.size, "RGBA"),
(self.mask.get_width(), int(self.gif.width * self.gif.height / self.mask.get_width())))
copy = self.mask.copy()
rect = frame.get_rect()
rect.bottom = copy.get_rect().bottom
copy.blit(frame, rect, None, BLEND_RGBA_MIN)
self.clear_frames()
self.add_frame(copy)
class Logo(Sprite):

10
config
View File

@ -80,11 +80,11 @@ ending-timeout = 22000
lizard-hurt-length = 2000
[bgm]
title = resource/bgm/title.ogg, .65
level_0 = /home/frank/storage/audio/bgm/bat-tree-habitat-key/level-0.wav, .65
level_1 = /home/frank/storage/audio/bgm/esp-hadouken/Cube-Levers.ogg, .65
level_2 = /home/frank/storage/audio/bgm/esp-hadouken/Bog.ogg, .65
end = /home/frank/storage/audio/bgm/phone-call-from-magnet.wav, .65
title = bgm/title.ogg, 1.0
level_0 = bgm/level_0.ogg, .65
level_1 = bgm/level_1.ogg, .65
level_2 = bgm/level_2.ogg, .65
end = bgm/end.ogg, .65
[pads]
nw_color = #00FF88

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.