dcc/dcc/config.py

92 lines
2.6 KiB
Python

import io
import pathlib
import os
import re
DOOM=pathlib.Path.home().joinpath("doom")
DSDA_DIR=DOOM.joinpath("dsda-doom")
DSDA_VER='0.28.3'
DSDA=DSDA_DIR.joinpath('dsda-doom-{}-Linux.appimage'.format(DSDA_VER))
IWADS=DOOM.joinpath("iwads")
PWADS=DOOM.joinpath("pwads")
DEMOS=DOOM.joinpath("demos")
OUTPUT=DOOM.joinpath("fabricate")
DEFAULT_IWAD=IWADS.joinpath("DOOM2.WAD")
THUMB_WIDTH=1280
THUMB_HEIGHT=720
FONT="League-Spartan-Bold"
TEXT_FILL_COLOR="white"
TEXT_STROKE_COLOR="srgb(176,0,0)"
MIRROR="https://youfailit.net/pub/idgames" # NYC
def DsdaPreamble(wad, mapstr):
args = []
pwadpath = PWADS.joinpath(wad)
iwad = DEFAULT_IWAD
iwadpath = pwadpath.joinpath("iwad")
if iwadpath.exists():
with io.open(iwadpath) as f:
iwad = IWADS.joinpath(f.read().strip() + ".WAD")
args = args + ["-iwad", iwad]
wads = sorted(pwadpath.glob('*.wad', case_sensitive=False))
if len(wads) > 0:
args = args + ["-file"] + wads
dehs = sorted(pwadpath.glob('*.deh', case_sensitive=False))
if len(dehs) > 0:
args = args + ["-deh"] + dehs
complevel = pwadpath.joinpath("complevel")
if not complevel.exists():
raise Exception("No complevel set in PWAD dir {}.".format(pwadpath))
with io.open(complevel) as f:
args = args + ["-complevel", f.read().strip()]
args = args + ["-skill", "4"]
args = args + ["-warp", mapstr] # TODO: UDoom
return args
def DemoInPath(wad, mapstr):
candidates = [x for x in DEMOS.joinpath(wad).glob("{}_map{}*.lmp".format(wad, mapstr))]
if len(candidates) == 0:
raise Exception("no suitable demo candidates for WAD {} MAP {}.", wad, mapstr)
if len(candidates) == 1:
return candidates[0]
return sorted(filter(lambda s : re.search("-", str(s)), candidates))[-1]
def DsdaTextPath(wad, mapstr):
return Ensure(DEMOS.joinpath(wad)).joinpath("{}_map{}.txt".format(wad, mapstr))
def DemoOutPath(wad, mapstr):
return Ensure(DEMOS.joinpath(wad)).joinpath(DemoName(wad, mapstr))
def DemoName(wad, mapstr):
return "{}_map{}.lmp".format(wad, mapstr)
def PwadPath(wad):
return Ensure(PWADS.joinpath(wad))
def BaseThumbPath(wad, mapstr):
return Ensure(OUTPUT.joinpath(wad)).joinpath("{}_map{}_base.png".format(wad, mapstr))
def MDoomPath(wad):
return Ensure(OUTPUT.joinpath(wad)).joinpath("M_DOOM_scaled.png")
def TextThumbPath(wad, mapstr):
return Ensure(OUTPUT.joinpath(wad)).joinpath("{}_map{}_text.png".format(wad, mapstr))
def ThumbPath(wad, mapstr):
return Ensure(OUTPUT.joinpath(wad)).joinpath("{}_map{}_thumb.png".format(wad, mapstr))
def VideoPath(wad, mapstr):
return Ensure(OUTPUT.joinpath(wad)).joinpath("{}_map{}.mp4".format(wad, mapstr))
def Ensure(path):
if not path.exists():
os.mkdir(path)
return path