80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
import os
|
|
import random
|
|
|
|
class ResolutionReader:
|
|
@classmethod
|
|
def INPUT_TYPES(s):
|
|
base_path = os.path.dirname(os.path.realpath(__file__))
|
|
file_path = os.path.join(base_path, "resolutions", "resolutions.txt")
|
|
|
|
lines = []
|
|
if os.path.exists(file_path):
|
|
with open(file_path, 'r') as f:
|
|
lines = [line.strip() for line in f.readlines() if line.strip()]
|
|
|
|
if not lines:
|
|
lines = ["1024,1024,1.0"]
|
|
|
|
return {
|
|
"required": {
|
|
"resolution": (lines, ),
|
|
"selection_mode": (["manual", "sequential", "random"], {"default": "manual"}),
|
|
"repeat_count": ("INT", {"default": 1, "min": 1, "max": 100, "step": 1}),
|
|
}
|
|
}
|
|
|
|
@classmethod
|
|
def IS_CHANGED(s, resolution, selection_mode, repeat_count):
|
|
if selection_mode == "random" or selection_mode == "sequential":
|
|
return float("nan")
|
|
return resolution
|
|
|
|
RETURN_TYPES = ("INT", "INT", "FLOAT")
|
|
RETURN_NAMES = ("width", "height", "upscale")
|
|
|
|
FUNCTION = "read_resolution"
|
|
CATEGORY = "AODH Pack"
|
|
|
|
_current_index = 0
|
|
_current_count = 0
|
|
_last_selection = None
|
|
|
|
def read_resolution(self, resolution, selection_mode, repeat_count):
|
|
base_path = os.path.dirname(os.path.realpath(__file__))
|
|
file_path = os.path.join(base_path, "resolutions", "resolutions.txt")
|
|
|
|
lines = []
|
|
if os.path.exists(file_path):
|
|
with open(file_path, 'r') as f:
|
|
lines = [line.strip() for line in f.readlines() if line.strip()]
|
|
|
|
if not lines:
|
|
return (0, 0, 0.0)
|
|
|
|
if selection_mode == "manual":
|
|
selected_line = resolution
|
|
elif selection_mode == "sequential":
|
|
if self.__class__._current_count >= repeat_count:
|
|
self.__class__._current_index += 1
|
|
self.__class__._current_count = 0
|
|
selected_line = lines[self.__class__._current_index % len(lines)]
|
|
self.__class__._current_count += 1
|
|
elif selection_mode == "random":
|
|
if self.__class__._current_count >= repeat_count or self.__class__._last_selection is None:
|
|
self.__class__._last_selection = random.choice(lines)
|
|
self.__class__._current_count = 0
|
|
selected_line = self.__class__._last_selection
|
|
self.__class__._current_count += 1
|
|
else:
|
|
selected_line = resolution
|
|
|
|
try:
|
|
# Format: width, height, upscale
|
|
parts = [p.strip() for p in selected_line.split(',')]
|
|
width = int(parts[0])
|
|
height = int(parts[1])
|
|
upscale = float(parts[2])
|
|
return (width, height, upscale)
|
|
except (ValueError, IndexError):
|
|
return (0, 0, 0.0)
|