コード例 #1
0
ファイル: extract.py プロジェクト: CoRD-Dev/bpm-ancient
def _convert_emote(name, suffix, raw_emote):
    css = raw_emote.css.copy()

    for (prop, expected_value) in [("display", "block"), ("float", "left")]:
        if prop not in css:
            print("WARNING: %r is missing %r property" % (bplib.combine_name_pair(name, suffix), prop))
        else:
            if css[prop] != expected_value:
                print("WARNING: %r has unexpected value %r for property %r (expected %r)" % (
                    bplib.combine_name_pair(name, suffix), css[prop], prop, expected_value))

            del css[prop]

    width = bplib.css.as_size(css.pop("width"))
    height = bplib.css.as_size(css.pop("height"))
    size = (width, height)
    image_url = bplib.css.as_url(css.pop("background-image"))

    if "background-position" in css:
        offset = bplib.css.as_position(css.pop("background-position"), width, height)
    else:
        offset = (0, 0)

    for p in ("background-repeat", "clear"):
        # Commonly added useless properties that we want to ignore
        if p in css:
            del css[p]

    for p in css:
        print("WARNING: emote %r has unknown extra property %r (%r)" % (bplib.combine_name_pair(name, suffix), p, css[p]))

    return bplib.objects.NormalEmote(name, suffix, css, image_url, size, offset)
コード例 #2
0
ファイル: extract.py プロジェクト: nano23823/bpm
def _convert_emote(name, suffix, block):
    css = block.css.copy()

    for (prop, expected_value) in [("float", "left")]:
        if prop not in css:
            print("WARNING: %r is missing %r property" %
                  (bplib.combine_name_pair(name, suffix), prop))
        else:
            if css[prop] != expected_value:
                print(
                    "WARNING: %r has unexpected value %r for property %r (expected %r)"
                    % (bplib.combine_name_pair(
                        name, suffix), css[prop], prop, expected_value))

            del css[prop]

    width = bplib.css.as_size(css.pop("width"))
    height = bplib.css.as_size(css.pop("height"))
    size = (width, height)

    # TODO: Handle this better. I think CSS dictates that the last one present
    # wins out, but we don't have that information.
    images = []
    if "background-image" in css:
        images.append(bplib.css.as_url(css.pop("background-image")))
    if "background" in css:
        # Ignore all but the url() bit we're looking for. Properly parsing the
        # entire declaration would be a fair bit of work.
        parts = css.pop("background").split()
        for p in parts:
            if p.startswith("url("):
                images.append(bplib.css.as_url(p))
                break
    if len(images) != 1:
        print(
            "WARNING: %r has multiple background images: using first of (%r)" %
            (bplib.combine_name_pair(name, suffix), images))
    image_url = images[0]

    if "background-position" in css:
        offset = bplib.css.as_position(css.pop("background-position"), width,
                                       height)
    else:
        offset = (0, 0)

    for p in ("background-repeat", "clear", "display"):
        # Commonly added useless properties that we want to ignore
        if p in css:
            del css[p]

    for p in css:
        if p not in IGNORED_PROPERTIES:
            print("WARNING: emote %r has unknown extra property %r (%r)" %
                  (bplib.combine_name_pair(name, suffix), p, css[p]))

    return bplib.objects.NormalVariant(name, suffix, image_url, size, offset,
                                       css)
コード例 #3
0
ファイル: extract.py プロジェクト: killjoy1221/bpm
def _convert_emote(name, suffix, block):
    css = block.css.copy()

    for (prop, expected_value) in [("float", "left")]:
        if prop not in css:
            print("WARNING: %r is missing %r property" % (bplib.combine_name_pair(name, suffix), prop))
        else:
            if css[prop] != expected_value:
                print("WARNING: %r has unexpected value %r for property %r (expected %r)" % (
                    bplib.combine_name_pair(name, suffix), css[prop], prop, expected_value))

            del css[prop]

    width = bplib.css.as_size(css.pop("width"))
    height = bplib.css.as_size(css.pop("height"))
    size = (width, height)

    # TODO: Handle this better. I think CSS dictates that the last one present
    # wins out, but we don't have that information.
    images = []
    if "background-image" in css:
        images.append(bplib.css.as_url(css.pop("background-image")))
    if "background" in css:
        # Ignore all but the url() bit we're looking for. Properly parsing the
        # entire declaration would be a fair bit of work.
        parts = css.pop("background").split()
        for p in parts:
            if p.startswith("url("):
                images.append(bplib.css.as_url(p))
                break
    if len(images) != 1:
        print("WARNING: %r has multiple background images: using first of (%r)" % (bplib.combine_name_pair(name, suffix), images))
    image_url = images[0]

    if "background-position" in css:
        offset = bplib.css.as_position(css.pop("background-position"), width, height)
    else:
        offset = (0, 0)

    for p in ("background-repeat", "clear", "display"):
        # Commonly added useless properties that we want to ignore
        if p in css:
            del css[p]

    for p in css:
        if p not in IGNORED_PROPERTIES:
            print("WARNING: emote %r has unknown extra property %r (%r)" % (bplib.combine_name_pair(name, suffix), p, css[p]))

    return bplib.objects.NormalVariant(name, suffix, image_url, size, offset, css)
コード例 #4
0
ファイル: extract.py プロジェクト: thejbw/bpm-master
def combine_emote_blocks(emote_blocks):
    # Combines properties in partial emotes, producing a single emote map.
    emotes = {}
    for block in emote_blocks:
        if block.name not in emotes:
            # Newly seen emote
            emotes[block.name] = (block.ignore, {block.suffix: block})
        else:
            ignore, variants = emotes[block.name]

            if ignore ^ block.ignore:
                print("WARNING: Emote %s split across PONYSCRIPT-IGNORE block" % (block.name))
            ignore |= block.ignore

            if block.suffix not in variants:
                # New suffix for an existing emote
                variants[block.suffix] = block
            else:
                # Existing emote. Check for property overwrites
                base = variants[block.suffix]
                for (prop, value) in block.css.items():
                    if prop in base.css and bplib.css.prop(base.css[prop]) != bplib.css.prop(value):
                        print("WARNING: emote %r redefined property %r from base (from %r to %r)" % (
                            bplib.combine_name_pair(block.name, block.suffix), prop,
                            base.css[prop], block.css[prop]))
                base.css.update(block.css)

            # Update ignore
            emotes[block.name] = (ignore, variants)
    return emotes
コード例 #5
0
ファイル: extract.py プロジェクト: nano23823/bpm
def combine_emote_blocks(emote_blocks):
    # Combines properties in partial emotes, producing a single emote map.
    emotes = {}
    for block in emote_blocks:
        if block.name not in emotes:
            # Newly seen emote
            emotes[block.name] = (block.ignore, {block.suffix: block})
        else:
            ignore, variants = emotes[block.name]

            if ignore ^ block.ignore:
                print(
                    "WARNING: Emote %s split across PONYSCRIPT-IGNORE block" %
                    (block.name))
            ignore |= block.ignore

            if block.suffix not in variants:
                # New suffix for an existing emote
                variants[block.suffix] = block
            else:
                # Existing emote. Check for property overwrites
                base = variants[block.suffix]
                for (prop, value) in block.css.items():
                    if prop in base.css and bplib.css.prop(
                            base.css[prop]) != bplib.css.prop(value):
                        base_important = "!important" in base.css[prop]
                        block_important = "!important" in value

                        if base_important and not block_important:
                            print(
                                "WARNING: emote %r redefined property %r from base value %r to %r, keeping base"
                                % (bplib.combine_name_pair(
                                    block.name, block.suffix), prop,
                                   base.css[prop], value))
                        else:
                            print(
                                "WARNING: emote %r redefined property %r from base value %r to %r, using new value"
                                % (bplib.combine_name_pair(
                                    block.name, block.suffix), prop,
                                   base.css[prop], value))
                            base.css[prop] = value
                    else:
                        base.css[prop] = value

            # Update ignore
            emotes[block.name] = (ignore, variants)
    return emotes
コード例 #6
0
ファイル: extract.py プロジェクト: CoRD-Dev/bpm-ancient
def combine_partial_emotes(partial_emotes):
    # Combines properties in partial emotes, producing a single emote map.
    emotes = {}
    for partial in partial_emotes:
        if partial.name not in emotes:
            # Newly seen emote
            emotes[partial.name] = bplib.objects.Emote(partial.name, {partial.suffix: partial}, {})
        elif partial.suffix not in emotes[partial.name]:
            # New suffix for an existing emote
            emotes[partial.name][partial.suffix] = partial
        else:
            # Existing emote. Check for property overwrites
            base = emotes[partial.name][partial.suffix]
            for (prop, value) in partial.css.items():
                if prop in base.css and bplib.css.prop(base.css[prop]) != bplib.css.prop(value):
                    print("WARNING: emote %r redefined property %r from base (from %r to %r)" % (
                        bplib.combine_name_pair(partial.name, partial.suffix), prop,
                        base.css[prop], partial.css[prop]))
            base.css.update(partial.css)
    return emotes
コード例 #7
0
ファイル: objects.py プロジェクト: thejbw/bpm-master
 def selector(self):
     name = self.name[1:].replace("!", "_excl_").replace(":", "_colon_").replace("#", "_hash_").replace("/", "_slash_")
     return ".bpmote-" + bplib.combine_name_pair(name, self.suffix).lower()
コード例 #8
0
ファイル: objects.py プロジェクト: nano23823/bpm
 def selector(self):
     name = self.name[1:].replace("!", "_excl_").replace(
         ":", "_colon_").replace("#", "_hash_").replace("/", "_slash_")
     return ".bpmote-" + bplib.combine_name_pair(name, self.suffix).lower()