Ejemplo n.º 1
0
	def __init__(self, name, imgfp):
		self.name = name
		self.entries = []
		self.img = Img(imgfp)
		self.roll = ''
		self._emap = {}
		self.append(Entry(0,0,"{}", None)) # index 0 is a hash map to quickly access entries by values)
Ejemplo n.º 2
0
	def portrait(self):
		portrait = self.assets.get('portrait', None)
		if portrait is None:
			if self.icon:
				fp = self.icon.fp.replace('.png', '_p.png')
				if os.path.exists(fp):
					portrait = Img(fp)
					self.assets['portrait'] = portrait
		return portrait
Ejemplo n.º 3
0
	def assets(self):
		if self._assets is None:
			self._assets = {}
			# try to fetch an appropriate image from the imglib directory
			# using a stupid heuristic: the image / token.name match ratio
			# compute the diff ratio for the given name compared to the token name
			ratio = lambda name: difflib.SequenceMatcher(None, name.lower(), self.name.lower()).ratio()
			# morph "/abc/def/anyfile.png" into "anyfile"
			short_name = lambda full_path: os.path.splitext(os.path.basename(full_path))[0]
			bratio=0
			if self.pngs:
				# generate the diff ratios
				ratios = ((f, ratio(short_name(f))) for f in self.pngs)
				# pickup the best match, it's a tuple (fpath, ratio)
				bfpath, bratio = max(itertools.chain(ratios, [('', 0)]), key = lambda i: i[1])
				log.debug("Best match from the img lib is %s(%s)" % (bfpath, bratio))
			# in delivery mode, do not add the tome of beast art, per author request
			if bratio > 0.8 and (self.js.get("ref", "")!="Tome of Beast" or not args.delivery):
				self._assets['null'] = Img(bfpath)
			else:
				self._assets['null'] = Img(imglib+'/dft.png')
		return self._assets
Ejemplo n.º 4
0
	def icon(self):
		img = self.assets.get("icon", None)
		# try to fetch an appropriate image from the imglib directory
		# using a stupid heuristic: the image / token.name match ratio
		if img is None:
			# compute the diff ratio for the given name compared to the token name
			ratio = lambda name: difflib.SequenceMatcher(None, name.lower(), self.matchImg.lower()).ratio()
			# morph "/abc/def/anyfile.png" into "anyfile"
			short_name = lambda full_path: os.path.splitext(os.path.basename(full_path))[0]
			# list of all img files
			files = itertools.chain(*(glob.glob(os.path.join(os.path.expanduser(imglib), '*.png')) for imglib in imglibs))
			bratio=0
			if files:
				# generate the diff ratios
				ratios = ((f, ratio(short_name(f))) for f in files)
				# pickup the best match, it's a tuple (fpath, ratio)
				bfpath, bratio = max(itertools.chain(ratios, [('', 0)]), key = lambda i: i[1])
				log.debug("%s: Best match from the img lib is %s(%s)" % (self.name, bfpath, bratio))
			if bratio > 0.8:
				self.assets['icon'] = Img(bfpath)
			else:
				self.assets['icon'] = Img(os.path.join('imglib', 'dft.png'))
		return self.assets.get('icon', None)
Ejemplo n.º 5
0
	def __init__(self, name):
		LibToken.__init__(self, name)
		# don't put portrait and handouts in sels.assets, when building campaign file
		# we need to differentiate img assets, from portrait and handouts...
		self._assets = {}
		self._assets['null'] = Img(imglib+'/../GUI_Icons_png/transparent/location_t.png')
		self._assets['chest'] = Img(imglib+'/../GUI_Icons_png/transparent/chest_t.png')
		self._assets['gold'] = Img(imglib+'/../GUI_Icons_png/transparent/gold_t.png')
		self._assets['quest_c'] = Img(imglib+'/../GUI_Icons_png/transparent/quest_complete_t.png')
		self._assets['quest'] = Img(imglib+'/../GUI_Icons_png/transparent/quest_t.png')
		self._assets['magnifier'] = Img(imglib+'/../GUI_Icons_png/transparent/magnifier_t.png')
		for num in range(1,9):
			fpath = os.path.join(imglib,'%sb.png'%num)
			if os.path.exists(fpath): self._assets['rn_b_%02d'%num] = Img(fpath)
			fpath = os.path.join(imglib,'%sg.png'%num)
			if os.path.exists(fpath): self._assets['rn_g_%02d'%num] = Img(fpath)
		for num in range(21):
			fpath = os.path.join(imglib,'Room Numbers/%02d.png'%num)
			if os.path.exists(fpath): self._assets['rn_%02d'%num] = Img(fpath)

		# resize all assets to a reasonable size
		for asset in self.assets.values():
			asset.resize(100,100)
Ejemplo n.º 6
0
	def __init__(self, _min, _max, value, imfp):
		self.min = _min
		self.max = _max
		self.value = value
		self.img = Img(imfp) if imfp else None
Ejemplo n.º 7
0
	def addImage(self, name, fp):
		if not os.path.exists(fp): raise ValueError('image %s does not exists')
		if name in self.assets: raise ValueError('Asset %s already exists')
		self.assets[name] = Img(fp)
Ejemplo n.º 8
0
	def portrait(self, fp):
		self.assets['portrait'] = Img(fp)
Ejemplo n.º 9
0
	def icon(self, fp): self.assets['icon'] = Img(fp)

	@property