Example #1
0
def sound(name, root=None):
    oname = name
    name, ext = os.path.splitext(name)

    for ext in muz.main.frontend.supportedSoundFormats:
        try:
            return vfs.locate("sfx/%s.%s" % (name, ext), root=root)
        except Exception:
            log.debug("loading sound %s from sfx/%s.%s failed", name, name, ext, exc_info=True)

    return vfs.locate("sfx/%s", oname, root=root)
Example #2
0
def music(name, root=None):
    oname = name
    name, ext = os.path.splitext(name)

    if muz.main.frontend is not None:
        for ext in muz.main.frontend.supportedMusicFormats:
            try:
                return vfs.locate("%s.%s" % (name, ext), root=root).preferAlternative()
            except Exception:
                log.debug("loading music %s from %s.%s failed", name, name, ext, exc_info=True)

    return vfs.locate(oname, root=root).preferAlternative()
Example #3
0
def sound(name, root=None):
    oname = name
    name, ext = os.path.splitext(name)

    for ext in muz.main.frontend.supportedSoundFormats:
        try:
            return vfs.locate("sfx/%s.%s" % (name, ext), root=root)
        except Exception:
            log.debug("loading sound %s from sfx/%s.%s failed",
                      name,
                      name,
                      ext,
                      exc_info=True)

    return vfs.locate("sfx/%s", oname, root=root)
Example #4
0
    def __init__(self, mapname, numbands, msrclist, meta=None):
        if isinstance(msrclist, str) or isinstance(msrclist, unicode):
            msrclist = [msrclist]

        musfile = None
        for musicsource in msrclist:
            try:
                musfile = vfs.locate(musicsource).open()
            except Exception:
                log.warning("couldn't load music source %s", repr(musicsource))
        assert musfile is not None

        self._beatmap = Beatmap(mapname,
                                numbands,
                                music=os.path.split(musfile.name)[-1],
                                musicFile=musfile,
                                meta=meta)
        self.pos = 0
        self.tactLength = 1000.0
        self.bands = []
        self.curNotes = set()
        self.groups = {}
        self.wrapped = Wrapper(self)

        self.refRebuildNeeded = False
Example #5
0
def music(name, root=None):
    oname = name
    name, ext = os.path.splitext(name)

    if muz.main.frontend is not None:
        for ext in muz.main.frontend.supportedMusicFormats:
            try:
                return vfs.locate("%s.%s" % (name, ext),
                                  root=root).preferAlternative()
            except Exception:
                log.debug("loading music %s from %s.%s failed",
                          name,
                          name,
                          ext,
                          exc_info=True)

    return vfs.locate(oname, root=root).preferAlternative()
Example #6
0
def load(name, bare=False, options=None):
    name = str(name)
    node = None
    wantext = None

    if "." in name:
        a = name.split(".")
        if " " not in a[-1] and "/" not in a[-1]:
            wantext = a[-1]
            name = ".".join(a[:-1])

    log.info("attempting to load beatmap %s", repr(name))

    for ext, importer in muz.beatmap.formats.importersByInferExt.items():
        if wantext is not None and ext != wantext:
            continue

        found = False
        paths = []

        if name.startswith(vfs.VPATH_SEP) or name.startswith(os.path.sep):
            paths.append("%s.%s" % (name, ext))
        else:
            for location in importer.locations:
                paths.append("%s/%s.%s" % (location, name, ext))

        for path in paths:
            try:
                node = vfs.locate(path)
            except Exception:
                log.debug("couldn't load beatmap %s with the %s importer",
                          repr(path),
                          repr(importer.__name__),
                          exc_info=True)
            else:
                log.info("loading beatmap %s (%s) with the %s importer",
                         repr(name), repr(path), repr(importer.__name__))
                found = True
                break

        if found:
            break

    if node is None:
        raise RuntimeError("No importer available for beatmap %s" % name)

    bm = importer.read(node.open(), node.name, bare=bare, options=options)
    if bm.vfsNode is None:
        bm.vfsNode = node

    if not bm.name:
        bm.name = name

    return bm
Example #7
0
def load(name, bare=False, options=None):
    name = str(name)
    node = None
    wantext = None

    if "." in name:
        a = name.split(".")
        if " " not in a[-1] and "/" not in a[-1]:
            wantext = a[-1]
            name = ".".join(a[:-1])

    log.info("attempting to load beatmap %s", repr(name))

    for ext, importer in muz.beatmap.formats.importersByInferExt.items():
        if wantext is not None and ext != wantext:
            continue

        found = False
        paths = []

        if name.startswith(vfs.VPATH_SEP) or name.startswith(os.path.sep):
            paths.append("%s.%s" % (name, ext))
        else:
            for location in importer.locations:
                paths.append("%s/%s.%s"  % (location, name, ext))

        for path in paths:
            try:
                node = vfs.locate(path)
            except Exception:
                log.debug("couldn't load beatmap %s with the %s importer", repr(path), repr(importer.__name__), exc_info=True)
            else:
                log.info("loading beatmap %s (%s) with the %s importer", repr(name), repr(path), repr(importer.__name__))
                found = True
                break

        if found:
            break

    if node is None:
        raise RuntimeError("No importer available for beatmap %s" % name)

    bm = importer.read(node.open(), node.name, bare=bare, options=options)
    if bm.vfsNode is None:
        bm.vfsNode = node

    if not bm.name:
        bm.name = name

    return bm
Example #8
0
    def __init__(self, mapname, numbands, msrclist, meta=None):
        if isinstance(msrclist, str) or isinstance(msrclist, unicode):
            msrclist = [msrclist]

        musfile = None
        for musicsource in msrclist:
            try:
                musfile = vfs.locate(musicsource).open()
            except Exception:
                log.warning("couldn't load music source %s", repr(musicsource))
        assert musfile is not None

        self.beatmap = Beatmap(mapname, numbands, music=os.path.split(musfile.name)[-1], musicFile=musfile, meta=meta)
        self.pos = 0
        self.tactLength = 1000.0
        self.bands = []
Example #9
0
def handleGeneralArgs(parser, argv, namespace):
    global globalArgs, userdir, basedir

    g = parser.add_argument_group(title="general options")
    g.add_argument('--basedir', action='store', default=basedir,
                   help="set the location of base game assets (default: %(default)s)")
    
    g.add_argument('--userdir', action="store", default=userdir,
                   help="set the location of user-supplied game data (e.g. beatmaps) (default: %(default)s)")

    g.add_argument('--no-vfs', action='store_true', default=False,
                   help="do not initialize the virtual filesystem")

    g.add_argument('-d', '--dir', metavar='DIR', dest='extradirs', action='append', default=[],
                   help="add a directory to search for game data in (including beatmaps), can be specified multiple times")

    g.add_argument('-p', '--pack', metavar='PACK', dest='extrapacks', action='append', default=[],
                   help="add a pack to search for game data in (including beatmaps), can be specified multiple times")

    g.add_argument('-c', '--config', action="store", type=argparse.FileType('r'), default=None,
                   help="load an alternative configuration file (default: $userdir/config.json)")
    
    g.add_argument('-l', '--list-beatmaps', dest="listbeatmaps", action="count", default=False,
                   help="list all beatmaps found in the virtual filesystem, specify twice to also list their 'nicer' names parsed from metadata (slow)")

    g.add_argument('-L', '--list-vfs', dest="listvfspath", metavar="PATH", action="store", nargs='?', const='', default=None,
                   help="list the contents of a path in the virtual filesystem and exit")

    g.add_argument('--log-level', dest="loglevel", metavar="LEVEL", choices=["critical", "error", "warning", "info", "debug"], default=None,
                   help="set the output verbosity level, overrides the config setting (default: warning)")

    g.add_argument('--frontend', choices=tuple(muz.frontend.iter()), default="pygame",
                   help="set the subsystem used to render and display the game, handle input, play audio, etc. (default: %(default)s)")

    g.add_argument('-v', '--version', action="version", version="%s %s" % (NAME, VERSION),
                   help="print the game version and exit")

    g.add_argument('-h', '--help', action='store_true', #action="help",
                   help="print this rather unhelpful (I'm sorry) help message and exit")

    n, a = parser.parse_known_args(argv, namespace=namespace)

    globalArgs = n
    basedir = os.path.abspath(n.basedir)
    userdir = os.path.abspath(n.userdir)

    if globalArgs.loglevel is not None:
        muz.log.setLevel(muz.util.logLevelByName(globalArgs.loglevel))

    if n.listvfspath is not None:
        init()

        l = vfs.locate(n.listvfspath)
        for key in sorted(l.keys()):
            print("%s%s" % (key, vfs.VPATH_SEP if l[key].isDir else ""))

        exit(0)

    if n.listbeatmaps:
        init()
        def getname(s):
            if n.listbeatmaps < 2:
                return s

            try:
                b = muz.beatmap.load(s, bare=True)
            except Exception as e:
                log.exception("failed to load beatmap %s: %s", s, e)
                return s
            else:
                return "%s: %s" %(s, b.name)

        for s in sorted(filter(None, (muz.beatmap.nameFromPath(path+obj) for path, obj, _ in vfs.root.walk()))):
            print(getname(s))

        exit(0)

    return (n, a)
Example #10
0
def font(name, root=None):
    return vfs.locate("fonts/%s.otf" % name, root=root)
Example #11
0
File: assets.py Project: nystep/muz
def font(name, root=None):
    return vfs.locate("fonts/%s.otf" % name, root=root)
Example #12
0
File: assets.py Project: nystep/muz
def sound(name, root=None):
    return vfs.locate("sfx/%s.ogg" % name, root=root)