Skip to content

Commit

Permalink
Merge pull request #97 from HebaruSan/fix/ksp2-versions
Browse files Browse the repository at this point in the history
Strip KSP2 build IDs, multi-game for DLC
  • Loading branch information
HebaruSan committed Dec 31, 2023
2 parents 4498fe4 + 64ef068 commit 55b9f0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
11 changes: 1 addition & 10 deletions ckan_meta_tester/dummy_game_instance.py
Expand Up @@ -10,10 +10,7 @@


class DummyGameInstance:

SAVED_REGISTRY=Path('/tmp/registry.json')
MAKING_HISTORY_VERSION=GameVersion('1.4.1')
BREAKING_GROUND_VERSION=GameVersion('1.7.1')

def __init__(self, where: Path, ckan_exe: Path, addl_repo: Path, main_ver: GameVersion, other_versions: List[GameVersion], cache_path: Path, game: Game) -> None:
self.where = where
Expand All @@ -36,7 +33,7 @@ def __enter__(self) -> 'DummyGameInstance':
'--game', self.game.short_name,
'--set-default', '--headless',
'dummy', self.where, str(self.main_ver),
*self._available_dlcs(self.main_ver)],
*self.game.dlc_cmdline_flags(self.main_ver)],
capture_output=self.capture)
for ver in self.other_versions:
logging.debug('Setting version %s compatible', ver)
Expand Down Expand Up @@ -66,12 +63,6 @@ def __enter__(self) -> 'DummyGameInstance':
logging.debug('Dummy instance is ready')
return self

def _available_dlcs(self, ver: GameVersion) -> List[str]:
return [
*(['--MakingHistory', '1.1.0'] if ver >= self.MAKING_HISTORY_VERSION else []),
*(['--BreakingGround', '1.0.0'] if ver >= self.BREAKING_GROUND_VERSION else [])
]

def __exit__(self, exc_type: Type[BaseException],
exc_value: BaseException, traceback: TracebackType) -> None:
logging.debug('Removing instance from CKAN instance list')
Expand Down
26 changes: 20 additions & 6 deletions ckan_meta_tester/game.py
Expand Up @@ -19,6 +19,9 @@ def short_name(self) -> str:
def _versions_from_json(self, json: object) -> List[GameVersion]:
raise NotImplementedError

def dlc_cmdline_flags(self, ver: GameVersion) -> List[str]:
return []

@staticmethod
def from_id(game_id: str = 'KSP') -> 'Game':
if game_id == 'KSP':
Expand All @@ -31,25 +34,36 @@ def from_id(game_id: str = 'KSP') -> 'Game':
class Ksp1(Game):
BUILDS_URL = 'https://raw.githubusercontent.com/KSP-CKAN/CKAN-meta/master/builds.json'
BUILD_PATTERN=re.compile(r'\.[0-9]+$')
MAKING_HISTORY_VERSION=GameVersion('1.4.1')
BREAKING_GROUND_VERSION=GameVersion('1.7.1')

@property
def short_name(self) -> str:
return 'KSP'

def _versions_from_json(self, json: object) -> List[GameVersion]:
def dlc_cmdline_flags(self, ver: GameVersion) -> List[str]:
return [*(['--MakingHistory', '1.1.0'] if ver >= self.MAKING_HISTORY_VERSION else []),
*(['--BreakingGround', '1.0.0'] if ver >= self.BREAKING_GROUND_VERSION else [])]

return [GameVersion(v) for v in OrderedDict.fromkeys(map(
lambda v: self.BUILD_PATTERN.sub('', v),
cast(Dict[str, Dict[str, str]], json).get('builds', {}).values()))]
def _versions_from_json(self, json: object) -> List[GameVersion]:
return [GameVersion(v)
for v
in OrderedDict.fromkeys(map(lambda v: self.BUILD_PATTERN.sub('', v),
cast(Dict[str, Dict[str, str]], json)
.get('builds', {})
.values()))]


class Ksp2(Game):
BUILDS_URL = 'https://raw.githubusercontent.com/KSP-CKAN/KSP2-CKAN-meta/master/builds.json'
BUILD_PATTERN=re.compile(r'\.[0-9]+$')

@property
def short_name(self) -> str:
return 'KSP2'

def _versions_from_json(self, json: object) -> List[GameVersion]:
# The KSP2 builds.json doesn't have build ids
return [GameVersion(v) for v in cast(List[str], json)]
return [GameVersion(v)
for v
in OrderedDict.fromkeys(map(lambda v: self.BUILD_PATTERN.sub('', v),
cast(List[str], json)))]

0 comments on commit 55b9f0f

Please sign in to comment.