Skip to content

Commit

Permalink
Merge pull request #324 from HebaruSan/add/first-person-tag
Browse files Browse the repository at this point in the history
Analyze first-person tag
  • Loading branch information
HebaruSan authored Dec 23, 2023
2 parents f83d013 + 0a0098c commit 61b4fc7
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions netkan/netkan/mod_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import tempfile
from pathlib import Path
from zipfile import ZipFile, is_zipfile, ZipInfo
from typing import Dict, List, Any, Union, Pattern, Iterable
from typing import Dict, List, Set, Any, Union, Pattern, Iterable

from .common import download_stream_to_file
from .cli.common import Game


class ModAspect:
def __init__(self, tags: List[str], depends: List[str]) -> None:
def __init__(self, tags: Set[str], depends: List[str]) -> None:
self.tags = tags
self.depends = depends

def apply_match(self, analyzer: 'ModAnalyzer') -> None:
analyzer.tags += self.tags
analyzer.tags |= self.tags
analyzer.depends += [{'name': dep} for dep in self.depends]

def analyze(self, analyzer: 'ModAnalyzer') -> None:
Expand All @@ -24,7 +24,7 @@ def analyze(self, analyzer: 'ModAnalyzer') -> None:


class FilenameAspect(ModAspect):
def __init__(self, name_regex: str, tags: List[str], depends: List[str]) -> None:
def __init__(self, name_regex: str, tags: Set[str], depends: List[str]) -> None:
super().__init__(tags, depends)
self.name_pattern = re.compile(name_regex)

Expand All @@ -35,7 +35,7 @@ def analyze(self, analyzer: 'ModAnalyzer') -> None:

class CfgAspect(ModAspect):

def __init__(self, cfg_regex: str, tags: List[str], depends: List[str]) -> None:
def __init__(self, cfg_regex: str, tags: Set[str], depends: List[str]) -> None:
super().__init__(tags, depends)
self.cfg_pattern = re.compile(cfg_regex, re.MULTILINE)

Expand All @@ -48,28 +48,31 @@ class ModAnalyzer:

ASPECTS: List[ModAspect] = [
CfgAspect(r'^\s*[@+$\-!%]|^\s*[a-zA-Z0-9_]+:',
[], ['ModuleManager']),
CfgAspect(r'^\s*PART\b', ['parts'], []),
CfgAspect(r'^\s*INTERNAL\b', ['crewed'], []),
CfgAspect(r'^\s*@TechTree\b', ['tech-tree'], []),
CfgAspect(r'^\s*@Kopernicus\b', ['planet-pack'], ['Kopernicus']),
CfgAspect(r'^\s*STATIC\b', ['buildings'], ['KerbalKonstructs']),
CfgAspect(r'^\s*TUFX_PROFILE\b', ['graphics'], ['TUFX']),
CfgAspect(r'^\s*CONTRACT_TYPE\b', ['career'], ['ContractConfigurator']),
CfgAspect(r'^\s*@CUSTOMBARNKIT\b', [], ['CustomBarnKit']),
set(), ['ModuleManager']),
CfgAspect(r'^\s*PART\b', {'parts'}, []),
CfgAspect(r'^\s*INTERNAL\b', {'crewed',
'first-person'}, []),
CfgAspect(r'^\s*PROP\b', {'first-person'}, []),
CfgAspect(r'^\s*@TechTree\b', {'tech-tree'}, []),
CfgAspect(r'^\s*@Kopernicus\b', {'planet-pack'}, ['Kopernicus']),
CfgAspect(r'^\s*STATIC\b', {'buildings'}, ['KerbalKonstructs']),
CfgAspect(r'^\s*TUFX_PROFILE\b', {'graphics'}, ['TUFX']),
CfgAspect(r'^\s*CONTRACT_TYPE\b', {'career'}, ['ContractConfigurator']),
CfgAspect(r'^\s*@CUSTOMBARNKIT\b', set(), ['CustomBarnKit']),
CfgAspect(r'^\s*name\s*=\s*ModuleB9PartSwitch\b',
[], ['B9PartSwitch']),
set(), ['B9PartSwitch']),
CfgAspect(r'^\s*name\s*=\s*ModuleWaterfallFX\b',
['graphics'], ['Waterfall']),
{'graphics'}, ['Waterfall']),
CfgAspect(r'^\s*VertexMitchellNetravaliHeightMap\b',
[], ['VertexMitchellNetravaliHeightMap']),

FilenameAspect(r'\.ks$', ['config',
'control'], ['kOS']),
FilenameAspect(r'swinfo\.json$', [], ['SpaceWarp']),
FilenameAspect(r'\.dll$', ['plugin'], []),
FilenameAspect(r'\.cfg$', ['config'], []),
FilenameAspect(r'\.patch$', ['config'], ['PatchManager']),
set(), ['VertexMitchellNetravaliHeightMap']),

FilenameAspect(r'\.ks$', {'config',
'control'}, ['kOS']),
FilenameAspect(r'swinfo\.json$', set(), ['SpaceWarp']),
FilenameAspect(r'\.dll$', {'plugin'}, []),
FilenameAspect(r'\.cfg$', {'config'}, []),
FilenameAspect(r'\.patch$', {'config'}, ['PatchManager']),
FilenameAspect(r'/(Spaces|Props)/', {'first-person'}, []),
]
FILTERS = [
'__MACOSX', '.DS_Store',
Expand Down Expand Up @@ -99,7 +102,7 @@ def __init__(self, ident: str, download_url: str, game: Game) -> None:

self.mod_root_path = game.mod_root

self.tags: List[str] = []
self.tags: Set[str] = set()
self.depends: List[Dict[str, str]] = []
for aspect in self.ASPECTS:
aspect.analyze(self)
Expand Down Expand Up @@ -245,7 +248,7 @@ def get_netkan_properties(self) -> Dict[str, Any]:
if self.has_spacewarp_info():
props['$vref'] = '#/ckan/space-warp'
if self.tags:
props['tags'] = self.tags
props['tags'] = list(sorted(self.tags))
if self.depends:
props['depends'] = self.depends
props.update(self.get_install_stanzas())
Expand Down

0 comments on commit 61b4fc7

Please sign in to comment.