Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use path objects in configgen generators #12932

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game

if configFile.exists():
config.read(configFile)

# Ensure the [Graphics] section exists
if 'Graphics' not in config:
config['Graphics'] = {}

if system.isOptSet("devilutionx_stretch") and system.config["devilutionx_stretch"] == "true":
config['Graphics']['Fit to Screen'] = '1'
else:
config['Graphics']['Fit to Screen'] = '0'

with open(configFile, 'w') as file:
with configFile.open('w') as file:
config.write(file)

commandArray = [
'devilutionx', '--data-dir', '/userdata/roms/devilutionx',
'--config-dir', configDir, '--save-dir', saveDir
Expand All @@ -53,7 +53,7 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game

if system.isOptSet('showFPS') and system.getOptBoolean('showFPS'):
commandArray.append('-f')

return Command.Command(
array=commandArray,
env={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import annotations

import logging
import os
from pathlib import Path
from typing import TYPE_CHECKING, Final

from ... import Command
from ...batoceraPaths import CONFIGS, SAVES
from ...batoceraPaths import CONFIGS, SAVES, mkdir_if_not_exists
from ...controller import generate_sdl_game_controller_config
from ..Generator import Generator

Expand Down Expand Up @@ -43,8 +42,9 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game
_DHEWM3_CONFIG_DIR = _DHEWM3_CONFIG / directory
_DHEWM3_CONFIG_BASE_FILE = _DHEWM3_CONFIG_BASE_DIR / "dhewm.cfg"
_DHEWM3_CONFIG_FILE = _DHEWM3_CONFIG_DIR / "dhewm.cfg"
os.makedirs(_DHEWM3_CONFIG_BASE_DIR, exist_ok=True)
os.makedirs(_DHEWM3_CONFIG_DIR, exist_ok=True)

mkdir_if_not_exists(_DHEWM3_CONFIG_BASE_DIR)
mkdir_if_not_exists(_DHEWM3_CONFIG_DIR)

options_to_set = {
"seta r_mode": "-1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import annotations

import logging
import os

from pathlib import Path
from typing import TYPE_CHECKING, Final

Expand Down Expand Up @@ -75,7 +73,7 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game

commandArray += ["--machine", machine]
tos = HatariGenerator.findBestTos(BIOS, machine, tosversion, toslang)
commandArray += [ "--tos", BIOS / tos]
commandArray += [ "--tos", tos]

# RAM (ST Ram) options (0 for 512k, 1 for 1MB)
memorysize = 0
Expand Down Expand Up @@ -169,7 +167,7 @@ def generateConfig(system, playersControllers):
config.write(configfile)

@staticmethod
def findBestTos(biosdir: Path, machine, tos_version, language) -> str:
def findBestTos(biosdir: Path, machine: str, tos_version: str, language: str, /) -> Path:
# all languages by preference, when value is "auto"
all_languages = ["us", "uk", "de", "es", "fr", "it", "nl", "ru", "se", ""]

Expand Down Expand Up @@ -197,11 +195,11 @@ def findBestTos(biosdir: Path, machine, tos_version, language) -> str:
biosversion = v_tos_version
else:
biosversion = f"tos{v_tos_version}"
filename = f"{biosversion}{v_language}.img"
if os.path.exists(f"{biosdir}/{filename}"):
eslog.debug(f"tos filename: {filename}")
return filename
tos_path = biosdir / f"{biosversion}{v_language}.img"
if tos_path.exists():
eslog.debug(f"tos filename: {tos_path.name}")
return tos_path
else:
eslog.warning(f"tos filename {filename} not found")
eslog.warning(f"tos filename {tos_path.name} not found")

raise Exception(f"no bios found for machine {machine}")
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import os

from typing import TYPE_CHECKING

from ... import controllersConfig
Expand Down Expand Up @@ -2836,7 +2834,7 @@ def generateCoreSettings(coreSettings: UnixSettings, system: Emulator, rom: Path
coreSettings.save('hatarib_borders', '"0"')

# Harddrive image support
rom_extension = os.path.splitext(os.path.basename(rom))[1].lower()
rom_extension = rom.suffix.lower()
if rom_extension == '.hd':
coreSettings.save('hatarib_hardimg', '"hatarib/hdd"')
coreSettings.save('hatarib_hardboot', '"1"')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from typing import TYPE_CHECKING, Final

from ... import Command
import toml

from ... import Command
from ...batoceraPaths import BIOS, CHEATS, CONFIGS, ROMS, SAVES, mkdir_if_not_exists
from ..Generator import Generator

Expand Down Expand Up @@ -31,10 +32,10 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game

# Config file path
configFileName = _MELONDS_CONFIG / "melonDS.toml"

# Load existing config if file exists
if configFileName.exists():
with open(configFileName, "r") as toml_file:
with configFileName.open() as toml_file:
config = toml.load(toml_file)
else:
config = {}
Expand Down Expand Up @@ -103,35 +104,35 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game
# Override Renderer if system option is set
if system.isOptSet("melonds_renderer"):
base_config["3D"]["Renderer"] = int(system.config["melonds_renderer"])

if system.isOptSet("melonds_vsync"):
base_config["Screen"]["VSync"] = system.config["melonds_vsync"]
base_config["Screen"]["VSyncInterval"] = 1

# Cheater! Enable cheats if the option is set
if system.isOptSet("melonds_cheats"):
base_config["Instance0"]["EnableCheats"] = system.config["melonds_cheats"]
else:
base_config["Instance0"]["EnableCheats"] = False

# Framerate
if system.isOptSet("melonds_framerate"):
base_config["LimitFPS"] = system.config["melonds_framerate"]
else:
base_config["LimitFPS"] = True

# Resolution
if system.isOptSet("melonds_resolution"):
base_config["3D"]["GL"]["ScaleFactor"] = int(system.config["melonds_resolution"])
if system.config["melonds_resolution"] == "2":
base_config["3D"]["GL"]["HiresCoordinates"] = True
else:
base_config["3D"]["GL"]["HiresCoordinates"] = False

# Polygons
if system.isOptSet("melonds_polygons"):
base_config["3D"]["GL"]["BetterPolygons"] = system.config["melonds_polygons"]

# Rotation
if system.isOptSet("melonds_rotation"):
base_config["Instance0"]["Window0"]["ScreenRotation"] = int(system.config["melonds_rotation"])
Expand All @@ -149,25 +150,25 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game
base_config["Instance0"]["Window0"]["ScreenLayout"] = int(system.config["melonds_layout"])
else:
base_config["Instance0"]["Window0"]["ScreenLayout"] = 0

# Screen Sizing
if system.isOptSet("melonds_screensizing"):
base_config["Instance0"]["Window0"]["ScreenSizing"] = int(system.config["melonds_screensizing"])
else:
base_config["Instance0"]["Window0"]["ScreenSizing"] = 0

# Integer Scaling
if system.isOptSet("melonds_scaling"):
base_config["Instance0"]["Window0"]["IntegerScaling"] = system.config["melonds_scaling"]
else:
base_config["Instance0"]["Window0"]["IntegerScaling"] = 0

# OSD
if system.isOptSet("melonds_osd"):
base_config["Instance0"]["Window0"]["ShowOSD"] = system.config["melonds_osd"]
else:
base_config["Instance0"]["Window0"]["ShowOSD"] = False

# Console
if system.isOptSet("melonds_console"):
base_config["Emu"]["ConsoleType"] = int(system.config["melonds_console"])
Expand All @@ -189,7 +190,7 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game
"x": "X",
"y": "Y"
}

val = -1
for controller, pad in sorted(playersControllers.items()):
# Only use Player 1 controls
Expand Down Expand Up @@ -217,7 +218,7 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game
config.update(base_config)

# Write updated configuration back to the file
with open(configFileName, "w") as toml_file:
with configFileName.open("w") as toml_file:
toml.dump(config, toml_file)

commandArray = ["/usr/bin/melonDS", "-f", rom]
Expand Down
Loading