5.1.1 release #62

Merged
coolestskinnieinthejungle merged 96 commits from 5.1.1 into master 2021-07-21 18:45:22 +00:00
1 changed files with 8 additions and 59 deletions
Showing only changes of commit 8117fa1981 - Show all commits

View File

@ -83,28 +83,23 @@ init python:
# Appends extra spaces at the end
# () -> None
def loadGallery():
from os import listdir, getcwd
from os.path import isfile, join
cgPath = "images/cgs/"
workingDirPath = getcwd().replace("\\", "/")
cgDirPath = workingDirPath + "/game/" + cgPath
# Reset gallery
galleryItems = []
g = Gallery()
g.transition = dissolve
list_img = renpy.list_images()
# Add each image to the gallery
for cgFile in listdir(cgDirPath):
filePath = join(cgDirPath, cgFile)
if isfile(filePath):
ext = cgFile[-3:].lower()
if (ext in ACCEPTED_EXTENSIONS):
attr = getImageFileAttributes(filePath)
fname = str(cgFile[0:-4])
unlocked = fname in persistent.cggallery
addGalleryItem(fname, ext, attr["w"], attr["h"], unlocked)
for str in list_img:
_str = cgPath+str+"."+ACCEPTED_EXTENSIONS[0]
if renpy.loadable(_str): #brute force
unlocked = renpy.seen_image(str)
image = renpy.image_size(Image(_str))
addGalleryItem(str, ACCEPTED_EXTENSIONS[0], image[0], image[1], unlocked)
# Add empty items to fill grid after last cg button
extraSpaces = GALLERY_COLS - (len(galleryItems) % GALLERY_COLS)
@ -115,52 +110,6 @@ init python:
"ext": None
})
# Get width/height of image by absolute path
# based on https://stackoverflow.com/questions/8032642/how-to-obtain-image-size-using-standard-python-class-without-using-external-lib
# (filePath: string) -> { w: int; h: int } | None
def getImageFileAttributes(filePath):
try:
from struct import unpack
from imghdr import what
w, h = 0, 0
with open(filePath, "rb") as file:
ext = what(filePath)
header = file.read(24)
if (len(header) != 24):
raise Exception("File header invalid for " + filePath)
if (ext == 'png'):
checksum = unpack('>i', header[4:8])[0]
if (checksum != 0x0d0a1a0a):
raise Exception("File checksum invalid for " + filePath)
w, h = unpack('>ii', head[16:24])
if (ext == 'jpeg' or ext == 'jpg'):
file.seek(0)
size = 2
ftype = 0
while not 0xc0 <= ftype <= 0xcf:
file.seek(size, 1)
byte = file.read(1)
while ord(byte) == 0xff:
byte = file.read(1)
ftype = ord(byte)
size = unpack('>H', file.read(2))[0] - 2
file.seek(1, 1)
h, w = unpack('>HH', file.read(4))
return { "w": w, "h": h }
except Exception:
#TODO: log error
return None
# Returns what params to call im.FactorScale with for cg button size
# Basically the delta diff dimensions
# (w: int; h: int) -> { x: float; y: float }