1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-14 05:44:52 +00:00
CC-Tweaked/tools/screenshots.py
Jonathan Coates 8f92417a2f
Add a system for client-side tests (#1219)
- Add a new ClientJavaExec Gradle task, which is used for client-side
   tests. This:

   - Copies the exec spec from another JavaExec task.
   - Sets some additional system properties to configure on gametest framework.
   - Runs Java inside an X framebuffer (when available), meaning we
     don't need to spin up a new window.

   We also configure this task so that only one instance can run at
   once, meaning we don't spawn multiple MC windows at once!

 - Port our 1.16 client test framework to 1.19. This is mostly the same
   as before, but screenshots no longer do a golden test: they /just/
   write to a folder. Screenshots are compared manually afterwards.

   This is still pretty brittle, and there's a lot of sleeps scattered
   around in the code. It's not clear how well this will play on CI.

 - Roll our own game test loader, rather than relying on the mod loader
   to do it for us. This ensures that loading is consistent between
   platforms (we already had to do some hacks for Forge) and makes it
   easier to provide custom logic for loading client-only tests.

 - Run several client tests (namely those involving monitor rendering)
   against Sodium and Iris too. There's some nastiness here to set up
   new Loom run configurations and automatically configure Iris to use
   Complementary Shaders, but it's not too bad. These tests /don't/ run
   on CI, so it doesn't need to be as reliable.
2022-11-18 23:57:25 +00:00

114 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Combines screenshots from the Forge and Fabric tests into a single HTML page.
"""
import os
import os.path
from dataclasses import dataclass
from typing import TextIO
from textwrap import dedent
import webbrowser
import argparse
PROJECT_LOCATIONS = [
"projects/fabric",
"projects/forge",
]
@dataclass(frozen=True)
class Image:
name: list[str]
path: str
def write_images(io: TextIO, images: list[Image]):
io.write(
dedent(
"""\
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CC:T test screenshots</title>
<style>
body {
padding: 0;
margin: 0;
font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
.content {
margin: 1em;
gap: 1em;
display: grid;
grid-template-columns: repeat(auto-fit,minmax(25em,1fr));
}
.image {
display: flex;
flex-direction: column;
}
.desc { text-align: center; }
.desc-prefix { color: #666; }
</style>
</head>
<body>
<div class="content">
"""
)
)
for image in images:
io.write(
dedent(
f"""\
<div class="image">
<img src="../{image.path}" />
<span class="desc">
<span class="desc-prefix">{" » ".join(image.name[:-2])} »</span>
<span class="desc-main">{image.name[-1]}</span>
</span>
</div>
"""
)
)
io.write("</div></body></html>")
def main():
spec = argparse.ArgumentParser(
description="Combines screenshots from the Forge and Fabric tests into a single HTML page."
)
spec.add_argument(
"--open",
default=False,
action="store_true",
help="Open the output file in a web browser.",
)
args = spec.parse_args()
images: list[Image] = []
for project, dir in {
"Forge": "projects/forge",
"Fabric": "projects/fabric",
}.items():
dir = os.path.join(dir, "build", "testScreenshots")
for file in sorted(os.listdir(dir)):
name = [project, *os.path.splitext(file)[0].split(".")]
images.append(Image(name, os.path.join(dir, file)))
out_file = "build/screenshots.html"
with open(out_file, encoding="utf-8", mode="w") as out:
write_images(out, images)
if args.open:
webbrowser.open(out_file)
if __name__ == "__main__":
main()