Skip to content

Commit

Permalink
Add game image support to preview generator
Browse files Browse the repository at this point in the history
  • Loading branch information
joaorb64 committed Nov 7, 2024
1 parent bf13fca commit 7fdcc14
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
1 change: 0 additions & 1 deletion layout/scoreboard_roa2/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ body {
drop-shadow(0 -1px 2px rgba(0, 0, 0, 0.1));
letter-spacing: 1;
background-size: cover;
background-image: url("https://cdn.discordapp.com/attachments/1016678165764120666/1299114778681282660/Sample_RoA2_1.png?ex=6725e9ab&is=6724982b&hm=04b8e06bfc5faf1b7e2aa9c51f3cfaae59e7debaf16d4710181d93b93f221443&");
}

.container {
Expand Down
Binary file added layout/scoreboard_roa2/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added layout/scoreboard_roa2/index_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 35 additions & 7 deletions scripts/render_webpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def __init__(self, parent=None):
QtWebEngineCore.QWebEngineSettings.WebAttribute.LocalContentCanAccessFileUrls):
settings.setAttribute(attr, True)

self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
self.setStyleSheet("background: transparent;")

self.page().setBackgroundColor(QtCore.Qt.transparent)

self.loadFinished.connect(self.save)
self.setAttribute(QtCore.Qt.WA_DontShowOnScreen, True)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
Expand Down Expand Up @@ -49,9 +54,35 @@ def saveScreenshot(self):
print(u"width: %d,hight: %d" % (size.width(), size.height()))
img = QtGui.QImage(size.width(), size.height(),
QtGui.QImage.Format_ARGB32)
img.fill(QtGui.QColor(255, 192, 203))
painter = QtGui.QPainter(img)

# Check for a background image
bg_image = None

game_screenshot = self.current[1].rsplit("_preview")[0]+".png"
if os.path.isfile(game_screenshot):
bg_image = game_screenshot
print("Found background image")
else:
default_game_screenshot = os.path.join(
os.path.dirname(self.current[1]), "default.png")

if os.path.isfile(default_game_screenshot):
bg_image = default_game_screenshot
print("Found default background image")

if bg_image:
bg = QtGui.QImage(bg_image)
painter.drawImage(
QtCore.QRect(0, 0, 1920, 1080),
bg
)

# Render html
self.render(painter, QtCore.QPoint(0, 0),
QtCore.QRect(0, 0, 1920, 1080))

painter.end()
filename = self.current[1]
if img.save(filename):
Expand All @@ -73,16 +104,13 @@ def saveScreenshot(self):
in_out = []

for path, subdirs, files in os.walk(os.path.abspath("../layout/")):
if not os.path.isdir("renders"):
os.mkdir("renders")
for name in files:
if name.endswith(".html"):
print(os.path.join(path, name))
in_out.append([
f"file:///{os.path.join(path, name).replace(os.path.sep, '/')}",
path.replace(os.path.sep, '/')+"/" +
name.split(".")[0]+"_preview.png"
])
in_out.append([f"file:///{os.path.join(path, name).replace(os.path.sep, '/')}",
path.replace(os.path.sep, '/')+"/" +
name.split(".")[0]+"_preview.png"
])
print(in_out)

shotter = PageShotter()
Expand Down

0 comments on commit 7fdcc14

Please sign in to comment.