예제 #1
0
 def renderAtom(self, atom, basedir, skip_alpha=False):
     if 'icon' not in atom.properties:
         logging.critical('UNKNOWN ICON IN ATOM #{0} ({1})'.format(atom.ID, atom.path))
         logging.info(atom.MapSerialize())
         logging.info(atom.MapSerialize(Atom.FLAG_INHERITED_PROPERTIES))
         return None
     # else:
     #    logging.info('Icon found for #{}.'.format(atom.ID))
     
     dmi_file = atom.properties['icon'].value
     
     if dmi_file is None:
         return None
     
     # Grab default icon_state ('') if we can't find the one defined.
     state = atom.getProperty('icon_state', '')
     
     direction = SOUTH
     if 'dir' in atom.properties:
         try:
             direction = int(atom.properties['dir'].value)
         except ValueError:
             logging.critical('FAILED TO READ dir = ' + repr(atom.properties['dir'].value))
             return None
     
     icon_key = '{0}|{1}|{2}'.format(dmi_file, state, direction)
     frame = None
     pixel_x = 0
     pixel_y = 0
     if icon_key in _icons:
         frame, pixel_x, pixel_y = _icons[icon_key]
     else:
         dmi_path = os.path.join(basedir, dmi_file)
         dmi = None
         if dmi_path in _dmis:
             dmi = _dmis[dmi_path]
         else:
             try:
                 dmi = DMI(dmi_path)
                 dmi.loadAll()
                 _dmis[dmi_path] = dmi
             except Exception as e:
                 print(str(e))
                 for prop in ['icon', 'icon_state', 'dir']:
                     print('\t{0}'.format(atom.dumpPropInfo(prop)))
                 pass
         if dmi.img is None:
             logging.warning('Unable to open {0}!'.format(dmi_path))
             return None
         
         if dmi.img.mode not in ('RGBA', 'P'):
             logging.warn('{} is mode {}!'.format(dmi_file, dmi.img.mode))
             
         if direction not in IMAGE_INDICES:
             logging.warn('Unrecognized direction {} on atom {}!'.format(direction, str(atom)))
             direction = SOUTH  # DreamMaker property editor shows dir = 2.  WTF?
             
         frame = dmi.getFrame(state, direction, 0)
         if frame == None:
             # Get the error/default state.
             frame = dmi.getFrame("", direction, 0)
         
         if frame == None:
             return None
         
         if frame.mode != 'RGBA':
             frame = frame.convert("RGBA")
             
         pixel_x = 0
         if 'pixel_x' in atom.properties:
             pixel_x = int(atom.properties['pixel_x'].value)
             
         pixel_y = 0
         if 'pixel_y' in atom.properties:
             pixel_y = int(atom.properties['pixel_y'].value)
         
         _icons[icon_key] = (frame, pixel_x, pixel_y)
             
     # Handle BYOND alpha and coloring
     c_frame = frame
     alpha = int(atom.getProperty('alpha', 255))
     if skip_alpha:
         alpha = 255
     color = atom.getProperty('color', '#FFFFFF')
     if alpha != 255 or color != '#FFFFFF':
         c_frame = tint_image(frame, BYOND2RGBA(color, alpha))
     return c_frame
예제 #2
0
    def RenderToMapTile(self, passnum, basedir, renderflags, **kwargs):
        img = Image.new('RGBA', (96, 96))
        self.offset = (32, 32)
        foundAPixelOffset = False
        render_types = kwargs.get('render_types', ())
        skip_alpha = kwargs.get('skip_alpha', False)
        # for atom in sorted(self.GetAtoms(), reverse=True):
        for atom in self.SortAtoms():
            if len(render_types) > 0:
                found = False
                for path in render_types:
                    if atom.path.startswith(path):
                        found = True
                if not found:
                    continue

            aid = atom.ID
            # Ignore /areas.  They look like ass.
            if atom.path.startswith('/area'):
                if not (renderflags & MapRenderFlags.RENDER_AREAS):
                    continue
            
            # We're going to turn space black for smaller images.
            if atom.path == '/turf/space':
                if not (renderflags & MapRenderFlags.RENDER_STARS):
                    continue
                
            if 'icon' not in atom.properties:
                logging.critical('UNKNOWN ICON IN {0} (atom #{1})'.format(self.origID, aid))
                logging.info(atom.MapSerialize())
                logging.info(atom.MapSerialize(Atom.FLAG_INHERITED_PROPERTIES))
                continue
            
            dmi_file = atom.properties['icon'].value
            
            if 'icon_state' not in atom.properties:
                # Grab default icon_state ('') if we can't find the one defined.
                atom.properties['icon_state'] = BYONDString("")
            
            state = atom.properties['icon_state'].value
            
            direction = SOUTH
            if 'dir' in atom.properties:
                try:
                    direction = int(atom.properties['dir'].value)
                except ValueError:
                    logging.critical('FAILED TO READ dir = ' + repr(atom.properties['dir'].value))
                    continue
            
            icon_key = '{0}|{1}|{2}'.format(dmi_file, state, direction)
            frame = None
            pixel_x = 0
            pixel_y = 0
            if icon_key in _icons:
                frame, pixel_x, pixel_y = _icons[icon_key]
            else:
                dmi_path = os.path.join(basedir, dmi_file)
                dmi = None
                if dmi_path in _dmis:
                    dmi = _dmis[dmi_path]
                else:
                    try:
                        dmi = DMI(dmi_path)
                        dmi.loadAll()
                        _dmis[dmi_path] = dmi
                    except Exception as e:
                        print(str(e))
                        for prop in ['icon', 'icon_state', 'dir']:
                            print('\t{0}'.format(atom.dumpPropInfo(prop)))
                        pass
                if dmi.img is None:
                    logging.warning('Unable to open {0}!'.format(dmi_path))
                    continue
                
                if dmi.img.mode not in ('RGBA', 'P'):
                    logging.warn('{} is mode {}!'.format(dmi_file, dmi.img.mode))
                    
                if direction not in IMAGE_INDICES:
                    logging.warn('Unrecognized direction {} on atom {} in tile {}!'.format(direction, atom.MapSerialize(), self.origID))
                    direction = SOUTH  # DreamMaker property editor shows dir = 2.  WTF?
                    
                frame = dmi.getFrame(state, direction, 0)
                if frame == None:
                    # Get the error/default state.
                    frame = dmi.getFrame("", direction, 0)
                
                if frame == None:
                    continue
                
                if frame.mode != 'RGBA':
                    frame = frame.convert("RGBA")
                    
                pixel_x = 0
                if 'pixel_x' in atom.properties:
                    pixel_x = int(atom.properties['pixel_x'].value)
                    
                pixel_y = 0
                if 'pixel_y' in atom.properties:
                    pixel_y = int(atom.properties['pixel_y'].value)
                
                _icons[icon_key] = (frame, pixel_x, pixel_y)
                    
            # Handle BYOND alpha and coloring
            c_frame = frame
            alpha = int(atom.getProperty('alpha', 255))
            if skip_alpha:
                alpha = 255
            color = atom.getProperty('color', '#FFFFFF')
            if alpha != 255 or color != '#FFFFFF':
                c_frame = tint_image(frame, BYOND2RGBA(color, alpha))
            img.paste(c_frame, (32 + pixel_x, 32 - pixel_y), c_frame)  # Add to the top of the stack.
            if pixel_x != 0 or pixel_y != 0:
                if passnum == 0: return  # Wait for next pass
                foundAPixelOffset = True
        
        if passnum == 1 and not foundAPixelOffset:
            return None
        if not self.areaSelected:
            # Fade out unselected tiles.
            bands = list(img.split())
            # Excluding alpha band
            for i in range(3):
                bands[i] = bands[i].point(lambda x: x * 0.4)
            img = Image.merge(img.mode, bands)
        
        return img
예제 #3
0
    def renderAtom(self, atom, basedir, skip_alpha=False):
        if 'icon' not in atom.properties:
            logging.critical('UNKNOWN ICON IN ATOM #{0} ({1})'.format(
                atom.ID, atom.path))
            logging.info(atom.MapSerialize())
            logging.info(atom.MapSerialize(Atom.FLAG_INHERITED_PROPERTIES))
            return None
        # else:
        #    logging.info('Icon found for #{}.'.format(atom.ID))

        dmi_file = atom.properties['icon'].value

        if dmi_file is None:
            return None

        # Grab default icon_state ('') if we can't find the one defined.
        state = atom.getProperty('icon_state', '')

        direction = SOUTH
        if 'dir' in atom.properties:
            try:
                direction = int(atom.properties['dir'].value)
            except ValueError:
                logging.critical('FAILED TO READ dir = ' +
                                 repr(atom.properties['dir'].value))
                return None

        icon_key = '{0}|{1}|{2}'.format(dmi_file, state, direction)
        frame = None
        pixel_x = 0
        pixel_y = 0
        if icon_key in _icons:
            frame, pixel_x, pixel_y = _icons[icon_key]
        else:
            dmi_path = os.path.join(basedir, dmi_file)
            dmi = None
            if dmi_path in _dmis:
                dmi = _dmis[dmi_path]
            else:
                try:
                    dmi = DMI(dmi_path)
                    dmi.loadAll()
                    _dmis[dmi_path] = dmi
                except Exception as e:
                    print(str(e))
                    for prop in ['icon', 'icon_state', 'dir']:
                        print('\t{0}'.format(atom.dumpPropInfo(prop)))
                    pass
            if dmi.img is None:
                logging.warning('Unable to open {0}!'.format(dmi_path))
                return None

            if dmi.img.mode not in ('RGBA', 'P'):
                logging.warn('{} is mode {}!'.format(dmi_file, dmi.img.mode))

            if direction not in IMAGE_INDICES:
                logging.warn('Unrecognized direction {} on atom {}!'.format(
                    direction, str(atom)))
                direction = SOUTH  # DreamMaker property editor shows dir = 2.  WTF?

            frame = dmi.getFrame(state, direction, 0)
            if frame == None:
                # Get the error/default state.
                frame = dmi.getFrame("", direction, 0)

            if frame == None:
                return None

            if frame.mode != 'RGBA':
                frame = frame.convert("RGBA")

            pixel_x = 0
            if 'pixel_x' in atom.properties:
                pixel_x = int(atom.properties['pixel_x'].value)

            pixel_y = 0
            if 'pixel_y' in atom.properties:
                pixel_y = int(atom.properties['pixel_y'].value)

            _icons[icon_key] = (frame, pixel_x, pixel_y)

        # Handle BYOND alpha and coloring
        c_frame = frame
        alpha = int(atom.getProperty('alpha', 255))
        if skip_alpha:
            alpha = 255
        color = atom.getProperty('color', '#FFFFFF')
        if alpha != 255 or color != '#FFFFFF':
            c_frame = tint_image(frame, BYOND2RGBA(color, alpha))
        return c_frame
예제 #4
0
    def RenderToMapTile(self, passnum, basedir, renderflags, **kwargs):
        img = Image.new('RGBA', (96, 96))
        self.offset = (32, 32)
        foundAPixelOffset = False
        render_types = kwargs.get('render_types', ())
        skip_alpha = kwargs.get('skip_alpha', False)
        # for atom in sorted(self.GetAtoms(), reverse=True):
        for atom in self.SortAtoms():
            if len(render_types) > 0:
                found = False
                for path in render_types:
                    if atom.path.startswith(path):
                        found = True
                if not found:
                    continue

            aid = atom.ID
            # Ignore /areas.  They look like ass.
            if atom.path.startswith('/area'):
                if not (renderflags & MapRenderFlags.RENDER_AREAS):
                    continue

            # We're going to turn space black for smaller images.
            if atom.path == '/turf/space':
                if not (renderflags & MapRenderFlags.RENDER_STARS):
                    continue

            if 'icon' not in atom.properties:
                logging.critical('UNKNOWN ICON IN {0} (atom #{1})'.format(
                    self.origID, aid))
                logging.info(atom.MapSerialize())
                logging.info(atom.MapSerialize(Atom.FLAG_INHERITED_PROPERTIES))
                continue

            dmi_file = atom.properties['icon'].value

            if 'icon_state' not in atom.properties:
                # Grab default icon_state ('') if we can't find the one defined.
                atom.properties['icon_state'] = BYONDString("")

            state = atom.properties['icon_state'].value

            direction = SOUTH
            if 'dir' in atom.properties:
                try:
                    direction = int(atom.properties['dir'].value)
                except ValueError:
                    logging.critical('FAILED TO READ dir = ' +
                                     repr(atom.properties['dir'].value))
                    continue

            icon_key = '{0}|{1}|{2}'.format(dmi_file, state, direction)
            frame = None
            pixel_x = 0
            pixel_y = 0
            if icon_key in _icons:
                frame, pixel_x, pixel_y = _icons[icon_key]
            else:
                dmi_path = os.path.join(basedir, dmi_file)
                dmi = None
                if dmi_path in _dmis:
                    dmi = _dmis[dmi_path]
                else:
                    try:
                        dmi = DMI(dmi_path)
                        dmi.loadAll()
                        _dmis[dmi_path] = dmi
                    except Exception as e:
                        print(str(e))
                        for prop in ['icon', 'icon_state', 'dir']:
                            print('\t{0}'.format(atom.dumpPropInfo(prop)))
                        pass
                if dmi.img is None:
                    logging.warning('Unable to open {0}!'.format(dmi_path))
                    continue

                if dmi.img.mode not in ('RGBA', 'P'):
                    logging.warn('{} is mode {}!'.format(
                        dmi_file, dmi.img.mode))

                if direction not in IMAGE_INDICES:
                    logging.warn(
                        'Unrecognized direction {} on atom {} in tile {}!'.
                        format(direction, atom.MapSerialize(), self.origID))
                    direction = SOUTH  # DreamMaker property editor shows dir = 2.  WTF?

                frame = dmi.getFrame(state, direction, 0)
                if frame == None:
                    # Get the error/default state.
                    frame = dmi.getFrame("", direction, 0)

                if frame == None:
                    continue

                if frame.mode != 'RGBA':
                    frame = frame.convert("RGBA")

                pixel_x = 0
                if 'pixel_x' in atom.properties:
                    pixel_x = int(atom.properties['pixel_x'].value)

                pixel_y = 0
                if 'pixel_y' in atom.properties:
                    pixel_y = int(atom.properties['pixel_y'].value)

                _icons[icon_key] = (frame, pixel_x, pixel_y)

            # Handle BYOND alpha and coloring
            c_frame = frame
            alpha = int(atom.getProperty('alpha', 255))
            if skip_alpha:
                alpha = 255
            color = atom.getProperty('color', '#FFFFFF')
            if alpha != 255 or color != '#FFFFFF':
                c_frame = tint_image(frame, BYOND2RGBA(color, alpha))
            img.paste(c_frame, (32 + pixel_x, 32 - pixel_y),
                      c_frame)  # Add to the top of the stack.
            if pixel_x != 0 or pixel_y != 0:
                if passnum == 0: return  # Wait for next pass
                foundAPixelOffset = True

        if passnum == 1 and not foundAPixelOffset:
            return None
        if not self.areaSelected:
            # Fade out unselected tiles.
            bands = list(img.split())
            # Excluding alpha band
            for i in range(3):
                bands[i] = bands[i].point(lambda x: x * 0.4)
            img = Image.merge(img.mode, bands)

        return img
예제 #5
0
basedir = 'floor_quads'
if os.path.isdir('floor_quads'):
    shutil.rmtree(basedir)
os.makedirs('floor_quads')
for icon_state in extract:
    if icon_state not in floors.states:
        print('Can\'t find state {0}!'.format(icon_state))
        continue
    for d in range(floors.states[icon_state].dirs):
        dirf = 0
        dirn = 'SOUTH'
        if floors.states[icon_state].dirs > 1:
            dirf = directions.IMAGE_INDICES[d]
            dirn = directions.getNameFromDir(dirf)
        print('{0} {1} {2}'.format(icon_state, dirn, floors.states[icon_state].dirs))
        img = floors.getFrame(icon_state, dirf, 0)
        for i in range(len(quadDefs)):
            quad = img.crop(quadDefs[i])
            if isKnownQuad(i, quad, icon_state):
                print('  Skipping quad #{}'.format(i + 1))
                continue
            color = icon_state
            if color.endswith('full'):
                color = color[:-4]
            qpath = os.path.join(basedir, str(i))
            qfile = os.path.join(qpath, '{0}.png'.format(color))
            if not os.path.isdir(qpath):
                os.makedirs(qpath)
            quad.save(qfile, 'PNG')
            knownQuads[i][color] = quad
예제 #6
0
if os.path.isdir('floor_quads'):
    shutil.rmtree(basedir)
os.makedirs('floor_quads')
for icon_state in extract:
    if icon_state not in floors.states:
        print('Can\'t find state {0}!'.format(icon_state))
        continue
    for d in range(floors.states[icon_state].dirs):
        dirf = 0
        dirn = 'SOUTH'
        if floors.states[icon_state].dirs > 1:
            dirf = directions.IMAGE_INDICES[d]
            dirn = directions.getNameFromDir(dirf)
        print('{0} {1} {2}'.format(icon_state, dirn,
                                   floors.states[icon_state].dirs))
        img = floors.getFrame(icon_state, dirf, 0)
        for i in range(len(quadDefs)):
            quad = img.crop(quadDefs[i])
            if isKnownQuad(i, quad, icon_state):
                print('  Skipping quad #{}'.format(i + 1))
                continue
            color = icon_state
            if color.endswith('full'):
                color = color[:-4]
            qpath = os.path.join(basedir, str(i))
            qfile = os.path.join(qpath, '{0}.png'.format(color))
            if not os.path.isdir(qpath):
                os.makedirs(qpath)
            quad.save(qfile, 'PNG')
            knownQuads[i][color] = quad