Ejemplo n.º 1
0
def parse_aiwfile(filename):
    aiw = AIW()

    with rfactortools.open_read(filename) as fout:
        parse_waypoints = False

        waypoint = Waypoint()
        for line in fout.read().splitlines():
            if line == "[Waypoint]":
                parse_waypoints = True

            if parse_waypoints:
                m = keyvalue_regex.match(line)
                if m:
                    key, value = m.group(1), m.group(2)
                    if key == "wp_pos":
                        waypoint = Waypoint()
                        aiw.waypoints.append(waypoint)
                        waypoint.pos = vec3(value)
                    elif key == "wp_bitfields":
                        waypoint.bitfields = int1(value)
                    elif key == "wp_branchID":
                        waypoint.branch_id = int1(value)
                    else:
                        pass  # logging.info("unhandled: \"%s\"" % key)

    return aiw
Ejemplo n.º 2
0
def parse_aiwfile(filename):
    aiw = AIW()

    with rfactortools.open_read(filename) as fout:
        parse_waypoints = False

        waypoint = Waypoint()
        for line in fout.read().splitlines():
            if line == "[Waypoint]":
                parse_waypoints = True

            if parse_waypoints:
                m = keyvalue_regex.match(line)
                if m:
                    key, value = m.group(1), m.group(2)
                    if key == "wp_pos":
                        waypoint = Waypoint()
                        aiw.waypoints.append(waypoint)
                        waypoint.pos = vec3(value)
                    elif key == "wp_bitfields":
                        waypoint.bitfields = int1(value)
                    elif key == "wp_branchID":
                        waypoint.branch_id = int1(value)
                    else:
                        pass  # logging.info("unhandled: \"%s\"" % key)

    return aiw
Ejemplo n.º 3
0
def parse_vehfile(filename):
    veh = Veh()

    veh.filename = filename

    with rfactortools.open_read(filename) as fin:
        for orig_line in fin.read().splitlines():
            line = orig_line

            m = comment_regex.match(line)
            if m:
                # comment = m.group(2)
                line = m.group(1)

            m = keyvalue_regex.match(line)
            if m:
                key, value = m.group(1), m.group(2)
                if key.lower() == "graphics":
                    veh.graphics_file = rfactortools.nt2posixpath(value.strip())
                elif key.lower() == "spinner":
                    veh.spinner_file = rfactortools.nt2posixpath(value.strip())
                elif key.lower() == "classes":
                    veh.classes = [c.strip() for c in unquote(value).split(",")]
                elif key.lower() == "category":
                    veh.category = [c.strip() for c in unquote(value).split(",")]
                elif key.lower() == "driver":
                    veh.driver = unquote(value)
                elif key.lower() == "team":
                    veh.team = unquote(value)
                else:
                    pass

    return veh
Ejemplo n.º 4
0
def modify_sfxfile(fout, filename, on_wav_file):
    with rfactortools.open_read(filename) as fin:
        lines = fin.read().splitlines()

    for orig_line in lines:
        m = comment_regex.match(orig_line)
        if m:
            comment = m.group(2)
            line = m.group(1)
        else:
            comment = ""
            line = orig_line

        suffix = comment

        m = wav1_regex.match(line)
        if m:
            wav = on_wav_file(rfactortools.nt2posixpath(m.group(3)))
            if wav is not None:
                wav = ntpath.normpath(wav)
            else:
                wav = m.group(3)
            fout.write("%s=%s,%s%s\n" % (m.group(1), m.group(2), wav, suffix))
        else:
            m = wav2_regex.match(line)
            if m:
                wav = on_wav_file(rfactortools.nt2posixpath(m.group(2)))
                if wav is not None:
                    wav = ntpath.normpath(wav)
                else:
                    wav = m.group(2)
                fout.write("%s=%s%s\n" % (m.group(1), wav, suffix))
            else:
                fout.write(orig_line)
                fout.write("\n")
Ejemplo n.º 5
0
def modify_sfxfile(fout, filename, on_wav_file):
    with rfactortools.open_read(filename) as fin:
        lines = fin.read().splitlines()

    for orig_line in lines:
        m = comment_regex.match(orig_line)
        if m:
            comment = m.group(2)
            line = m.group(1)
        else:
            comment = ""
            line = orig_line

        suffix = comment

        m = wav1_regex.match(line)
        if m:
            wav = on_wav_file(rfactortools.nt2posixpath(m.group(3)))
            if wav is not None:
                wav = ntpath.normpath(wav)
            else:
                wav = m.group(3)
            fout.write("%s=%s,%s%s\n" % (m.group(1), m.group(2), wav, suffix))
        else:
            m = wav2_regex.match(line)
            if m:
                wav = on_wav_file(rfactortools.nt2posixpath(m.group(2)))
                if wav is not None:
                    wav = ntpath.normpath(wav)
                else:
                    wav = m.group(2)
                fout.write("%s=%s%s\n" % (m.group(1), wav, suffix))
            else:
                fout.write(orig_line)
                fout.write("\n")
Ejemplo n.º 6
0
    def convert_trk(self, source_file, target_file):
        with rfactortools.open_read(source_file) as fin:
            lines = fin.readlines()

        with open(target_file, "wt", newline='\r\n', encoding="latin-1", errors="replace") as fout:
            for line in lines:
                fout.write(line)
Ejemplo n.º 7
0
    def convert_track_scn(self, source_file, target_file, modname):
        with rfactortools.open_read(source_file) as fin:
            lines = fin.readlines()

        with open(target_file,
                  "wt",
                  newline='\r\n',
                  encoding="latin-1",
                  errors="replace") as fout:
            for line in lines:
                # fix light intensity
                if self.cfg.fix_light_intensity:
                    m = re.match(
                        r'\s*Type=Directional.*Intensity=\(([0-9.]+)\).*',
                        line)
                    if m:
                        try:
                            intensity = float(m.group(1))
                            if intensity > 1.0:
                                intensity = 0.9
                                line = re.sub(r'Intensity=\([^\)]*\)',
                                              r'Intensity=(%f)' % intensity,
                                              line,
                                              flags=re.IGNORECASE)
                        except ValueError:
                            logging.exception(
                                "%s: couldn't parse light intensity: %s",
                                source_file, m.group(1))

                fout.write(line)
Ejemplo n.º 8
0
    def convert_gdb(self, filename, target_file):
        with rfactortools.open_read(filename) as fin:
            lines = fin.readlines()

        with open(target_file, "wt", newline='\r\n', encoding="latin-1", errors="replace") as fout:
            for line in lines:
                line = re.sub(r'Filter Properties *=.*',
                              r'Filter Properties = %s' % self.cfg.track_filter_properties,
                              line, flags=re.IGNORECASE)

                if self.cfg.track_category:
                    line = re.sub(r'^(\s*)VenueName\s*=\s*(.*)',
                                  r'\1VenueName = %s, \2' % self.cfg.track_category,
                                  line, flags=re.IGNORECASE)

                fout.write(line)

        if self.cfg.copy_missing_textures:
            missing_textures = ["racegroove.dds", "skidhard.dds",
                                "sky00.dds", "sky01.dds", "sky02.dds",
                                "sky03.dds", "sky04.dds"]

            for tex in missing_textures:
                source_tex_file = os.path.join("data", tex)
                target_tex_file = os.path.join(os.path.dirname(target_file), tex)

                if not rfactortools.file_exists(target_tex_file):
                    try:
                        shutil.copy(source_tex_file, target_tex_file)
                    except Exception:
                        logging.exception("%s: %s: rfactortools.convert_gdb texture copy failed",
                                          source_tex_file, target_tex_file)
Ejemplo n.º 9
0
    def convert_trk(self, source_file, target_file):
        with rfactortools.open_read(source_file) as fin:
            lines = fin.readlines()

        with open(target_file,
                  "wt",
                  newline='\r\n',
                  encoding="latin-1",
                  errors="replace") as fout:
            for line in lines:
                fout.write(line)
Ejemplo n.º 10
0
    def test_cmaps_dontfix(self):
        """Make sure that MASFile=cmaps.mas is not fixed when the cmaps is in another mod directory"""

        input_directory = os.path.join(self.test_datadir, "cmaps_dontfix/GameData/")
        output_directory = os.path.join(self.tmpdir, "cmap_dontfix")

        cfg = rfactortools.rFactorToGSC2013Config()
        converter = rfactortools.rFactorToGSC2013(input_directory, cfg)
        converter.convert_all(output_directory)

        with rfactortools.open_read(os.path.join(output_directory,
                                                 "GameData/Vehicles/TheMod/Subdir/graphics.gen")) as fin:
            self.assertEqual(fin.read(),
                             "MASFile=cmaps.mas\n")
Ejemplo n.º 11
0
    def test_cmaps_dontfix(self):
        """Make sure that MASFile=cmaps.mas is not fixed when the cmaps is in another mod directory"""

        input_directory = os.path.join(self.test_datadir,
                                       "cmaps_dontfix/GameData/")
        output_directory = os.path.join(self.tmpdir, "cmap_dontfix")

        cfg = rfactortools.rFactorToGSC2013Config()
        converter = rfactortools.rFactorToGSC2013(input_directory, cfg)
        converter.convert_all(output_directory)

        with rfactortools.open_read(
                os.path.join(
                    output_directory,
                    "GameData/Vehicles/TheMod/Subdir/graphics.gen")) as fin:
            self.assertEqual(fin.read(), "MASFile=cmaps.mas\n")
Ejemplo n.º 12
0
    def convert_veh(self, source_file, target_file, mod_name):
        with rfactortools.open_read(source_file) as fin:
            lines = fin.readlines()

        if self.cfg.unique_team_names:
            team_suffix = " %s" % mod_name
        else:
            team_suffix = ""

        with open(target_file,
                  "wt",
                  newline='\r\n',
                  encoding="latin-1",
                  errors="replace") as fout:
            for line in lines:
                # reiza5 (Mini Challenge) is needed for the cars to
                # show up in the car list
                if self.cfg.clear_classes:
                    line = re.sub(r'^Classes=".*',
                                  r'Classes="%s"' % self.cfg.reiza_class,
                                  line,
                                  flags=re.IGNORECASE)
                elif self.cfg.reiza_class:
                    line = re.sub(r'^Classes="',
                                  r'Classes="%s,' % self.cfg.reiza_class,
                                  line,
                                  flags=re.IGNORECASE)

                # Adding a suffix to Team is needed as conflicts in
                # Team names lead to cars getting sorted into the
                # wrong hierachy (e.g. a F1 car would show up in the
                # wrong year of F1, as multiple F1 years share the
                # same team names)
                line = re.sub(r'^Team="([^"]*)"',
                              r'Team="\1%s"' % team_suffix,
                              line,
                              flags=re.IGNORECASE)

                if self.cfg.vehicle_category:
                    line = re.sub(r'^Category="([^"]*)"',
                                  r'Category="%s, \1"' %
                                  self.cfg.vehicle_category,
                                  line,
                                  flags=re.IGNORECASE)

                fout.write(line)
Ejemplo n.º 13
0
    def convert_gdb(self, filename, target_file):
        with rfactortools.open_read(filename) as fin:
            lines = fin.readlines()

        with open(target_file,
                  "wt",
                  newline='\r\n',
                  encoding="latin-1",
                  errors="replace") as fout:
            for line in lines:
                line = re.sub(r'Filter Properties *=.*',
                              r'Filter Properties = %s' %
                              self.cfg.track_filter_properties,
                              line,
                              flags=re.IGNORECASE)

                if self.cfg.track_category:
                    line = re.sub(r'^(\s*)VenueName\s*=\s*(.*)',
                                  r'\1VenueName = %s, \2' %
                                  self.cfg.track_category,
                                  line,
                                  flags=re.IGNORECASE)

                fout.write(line)

        if self.cfg.copy_missing_textures:
            missing_textures = [
                "racegroove.dds", "skidhard.dds", "sky00.dds", "sky01.dds",
                "sky02.dds", "sky03.dds", "sky04.dds"
            ]

            for tex in missing_textures:
                source_tex_file = os.path.join("data", tex)
                target_tex_file = os.path.join(os.path.dirname(target_file),
                                               tex)

                if not rfactortools.file_exists(target_tex_file):
                    try:
                        shutil.copy(source_tex_file, target_tex_file)
                    except Exception:
                        logging.exception(
                            "%s: %s: rfactortools.convert_gdb texture copy failed",
                            source_tex_file, target_tex_file)
Ejemplo n.º 14
0
def parse_sfxfile(filename):
    sfx = SFX()

    with rfactortools.open_read(filename) as fin:
        for orig_line in fin.read().splitlines():
            m = comment_regex.match(orig_line)
            if m:
                # comment = m.group(2)
                line = m.group(1)
            else:
                # comment = None
                line = orig_line

            m = wav1_regex.match(line)
            if m:
                sfx.wavs.append(rfactortools.nt2posixpath(m.group(3)))
            else:
                m = wav2_regex.match(line)
                if m:
                    sfx.wavs.append(rfactortools.nt2posixpath(m.group(2)))
    return sfx
Ejemplo n.º 15
0
def parse_sfxfile(filename):
    sfx = SFX()

    with rfactortools.open_read(filename) as fin:
        for orig_line in fin.read().splitlines():
            m = comment_regex.match(orig_line)
            if m:
                # comment = m.group(2)
                line = m.group(1)
            else:
                # comment = None
                line = orig_line

            m = wav1_regex.match(line)
            if m:
                sfx.wavs.append(rfactortools.nt2posixpath(m.group(3)))
            else:
                m = wav2_regex.match(line)
                if m:
                    sfx.wavs.append(rfactortools.nt2posixpath(m.group(2)))
    return sfx
Ejemplo n.º 16
0
    def convert_track_scn(self, source_file, target_file, modname):
        with rfactortools.open_read(source_file) as fin:
            lines = fin.readlines()

        with open(target_file, "wt", newline='\r\n', encoding="latin-1", errors="replace") as fout:
            for line in lines:
                # fix light intensity
                if self.cfg.fix_light_intensity:
                    m = re.match(r'\s*Type=Directional.*Intensity=\(([0-9.]+)\).*', line)
                    if m:
                        try:
                            intensity = float(m.group(1))
                            if intensity > 1.0:
                                intensity = 0.9
                                line = re.sub(r'Intensity=\([^\)]*\)',
                                              r'Intensity=(%f)' % intensity,
                                              line, flags=re.IGNORECASE)
                        except ValueError:
                            logging.exception("%s: couldn't parse light intensity: %s", source_file, m.group(1))

                fout.write(line)
Ejemplo n.º 17
0
    def convert_veh(self, source_file, target_file, mod_name):
        with rfactortools.open_read(source_file) as fin:
            lines = fin.readlines()

        if self.cfg.unique_team_names:
            team_suffix = " %s" % mod_name
        else:
            team_suffix = ""

        with open(target_file, "wt", newline='\r\n', encoding="latin-1", errors="replace") as fout:
            for line in lines:
                # reiza5 (Mini Challenge) is needed for the cars to
                # show up in the car list
                if self.cfg.clear_classes:
                    line = re.sub(r'^Classes=".*',
                                  r'Classes="%s"' % self.cfg.reiza_class,
                                  line, flags=re.IGNORECASE)
                elif self.cfg.reiza_class:
                    line = re.sub(r'^Classes="',
                                  r'Classes="%s,' % self.cfg.reiza_class,
                                  line, flags=re.IGNORECASE)

                # Adding a suffix to Team is needed as conflicts in
                # Team names lead to cars getting sorted into the
                # wrong hierachy (e.g. a F1 car would show up in the
                # wrong year of F1, as multiple F1 years share the
                # same team names)
                line = re.sub(r'^Team="([^"]*)"',
                              r'Team="\1%s"' % team_suffix,
                              line, flags=re.IGNORECASE)

                if self.cfg.vehicle_category:
                    line = re.sub(r'^Category="([^"]*)"',
                                  r'Category="%s, \1"' % self.cfg.vehicle_category,
                                  line, flags=re.IGNORECASE)

                fout.write(line)
Ejemplo n.º 18
0
def process_scnfile(filename, parser):
    with rfactortools.open_read(filename) as fin:
        for orig_line in fin.read().splitlines():
            line = orig_line

            m = comment_regex.match(line)
            if m:
                comment = m.group(2)
                line = m.group(1)
            else:
                comment = None

            m = keyvalue_regex.match(line)
            m_sec_start = section_start_regex.match(line)
            m_sec_stop = section_end_regex.match(line)
            if m:
                key, value = m.group(1), m.group(2)
                parser.on_key_value(key, value.strip(), comment, orig_line)
            elif m_sec_start:
                parser.on_section_start(comment, orig_line)
            elif m_sec_stop:
                parser.on_section_end(comment, orig_line)
            else:
                parser.on_unknown(orig_line)
Ejemplo n.º 19
0
def process_scnfile(filename, parser):
    with rfactortools.open_read(filename) as fin:
        for orig_line in fin.read().splitlines():
            line = orig_line

            m = comment_regex.match(line)
            if m:
                comment = m.group(2)
                line = m.group(1)
            else:
                comment = None

            m = keyvalue_regex.match(line)
            m_sec_start = section_start_regex.match(line)
            m_sec_stop = section_end_regex.match(line)
            if m:
                key, value = m.group(1), m.group(2)
                parser.on_key_value(key, value.strip(), comment, orig_line)
            elif m_sec_start:
                parser.on_section_start(comment, orig_line)
            elif m_sec_stop:
                parser.on_section_end(comment, orig_line)
            else:
                parser.on_unknown(orig_line)