sorcery  Artifact [32e08434b2]

Artifact 32e08434b27256a798716bdcac5f58d92e749f3a044b5f1a776bb5454e75155f:

  • File lib/image.lua — part of check-in [147592b8e9] at 2020-10-26 03:58:08 on branch trunk — add over-time spellcasting abstraction to enable metamagic and in particular disjunction, add more animations and sound effects, add excavation spell, possibly some others, forget when the last commit was, edit a bunch of magitech to make it subject to the disjunction mechanism (throw up a disjunction aura and waltz right through those force fields bby, wheee), also illumination spells, tweak runeforge and rune frequence to better the balance and also limit player frustration, move some math functions into their own library category, various tweaks and bugfixes, probably other shit i don't remember (user: lexi, size: 1570) [annotate] [blame] [check-ins using]

local image
image = sorcery.lib.class {

	__concat   = function(self,with) return self:blit(with) end;
	__tostring = function(self)      return self:render()   end;

	construct = function(file) return {
		string = file;
		atop = {};
		fx = {};

		render = function(self)
			local str = ''
			for _,i in pairs(self.atop) do
				str = '(' .. i:render() .. ')^' .. str
			end
			local bracket = false
			if str ~= '' then str = str .. '(' bracket = true end
			str = str .. self.string
			for _,e in pairs(self.fx) do
				str = str .. '^[' .. e
				-- be sure to escape ones that take arguments
				-- correctly!
			end
			if bracket then str = str .. ')' end
			return str
		end;

		blit = function(self, img)
			if img then return image.change(self, {
				atop = sorcery.lib.tbl.append(self.atop, {img})
			}) else return self end
		end;

		multiply = function(self, color)
			return image.change(self, {
				fx = sorcery.lib.tbl.append(self.fx, {'multiply:' .. tostring(color)})
			})
		end;

		colorize = function(self, color, ratio)
			return image.change(self, {
				fx = sorcery.lib.tbl.append(self.fx, {'colorize:' .. tostring(color) .. ':' .. ratio})
			})
		end;

		fade = function(self, fac)
			return image.change(self, {
				fx = sorcery.lib.tbl.append(self.fx, {'opacity:' .. (255 - 255*fac)})
			})
		end;

		transform = function(self, kind)
			return image.change(self, {
				fx = sorcery.lib.tbl.append(self.fx, {'transform' .. tostring(kind)})
			})
		end;

		glow = function(self,color) return self:blit(self:multiply(color)) end;
	} end;
}
return image