Skip to content

Commit

Permalink
Updated Formats to class system
Browse files Browse the repository at this point in the history
Removed old Integrator
Removed UTLib
Added Server Installation menu
  • Loading branch information
alecxvs committed Jan 25, 2014
1 parent da536b3 commit d29134d
Show file tree
Hide file tree
Showing 18 changed files with 661 additions and 385 deletions.
2 changes: 2 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
syntax: glob
utchat/utchat.conf
8 changes: 2 additions & 6 deletions utchat/client/chathandlers/colorconstants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
--Purpose: Parse color constants and apply them to text
--================================================================================--


local loaded = false
Events:Subscribe("UTChatLoaded", function( )
if loaded then return end
loaded = true
UTL["UTChat"]:RegisterChatHandler(function( utxt )
Events:Subscribe("ModulesLoad", function( )
UTChat.RegisterChatHandler(function( utxt )
assert((class_info(utxt).name):lower() == "utext", "UTChat Tag Parser failed: Expecting UText object, got "..type(utxt)..": "..(class_info(pColor).name):lower())
::redo::
local startindex, color = utxt.text:match("()%(([%a%s]+)%).+")
Expand Down
20 changes: 20 additions & 0 deletions utchat/client/format.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--Generic Format--
--[[
- type = <string>
- startpos = <number>
- endpos = <number>
]]--

class 'Format'

-- Shadow Effect Init
function Format:__init( startpos, endpos )
self.startpos = startpos
self.endpos = endpos
self.type = class_info(self).name:lower()
end

-- Shadow Effect Render
function Format:Render( block )
error("Render function not implemented")
end
29 changes: 9 additions & 20 deletions utchat/client/formats/color.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ Color Effect
- type = "Color"
- startpos = <number>
- endpos = <number>
- renderfunc = UTLib.Color.Render
*Custom Parameter*
* color = args[1-4]
Overloads:
Color instance (Color)
Conforms to constructors of the Color class, see the JC2-MP Wiki for details:
http://wiki.jc-mp.com/Lua/Shared/Color/Constructor
]]--
local loaded = false
Events:Subscribe( "UTLibLoaded", function()
if loaded then return end
loaded = true
UTLib.Color = {}
Events:Subscribe( "ModulesLoad", function()

--Color Effect Init
UTLib.Color.Init = function( startpos, endpos, params )
class 'utColor'

function utColor:__init( startpos, endpos, params )
Format.__init(self, startpos, endpos)
local pColor = {}
if params then
if params.n == 1 then
Expand All @@ -31,28 +29,19 @@ Events:Subscribe( "UTLibLoaded", function()
error( "UTLib: Error in Color effect: This effect requires parameters, see documentation" )
end

local ueColor = {}

if (class_info(pColor).name):lower() == "color" then
ueColor.color = Copy(pColor)
self.color = Copy(pColor)
else
error( [[UTLib: Error in Color effect: Does not match overloads.
Expected: Color (Color)
Got: ]]..type(pColor) )
end

ueColor.type = "color"
ueColor.startpos = startpos
ueColor.endpos = endpos
ueColor.renderfunc = UTLib.Color.Render
return ueColor
end

--Color Effect Render
UTLib.Color.Render = function( block, effect )
block.color = Copy(effect.color)
function utColor:Render( block )
block.color = Copy(self.color)
end

UText.RegisterFormat( "color", UTLib.Color.Init )
UText.RegisterFormat( "colour", UTLib.Color.Init )
UText.RegisterFormat( utColor, "color", "colour" )
end)
130 changes: 62 additions & 68 deletions utchat/client/formats/fade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Fade Effect
- type = "Fade"
- startpos = <number>
- endpos = <number>
- renderfunc = UTLib.Fade.Render
*Custom Parameter*
* Fade = args[1-6]
StartTime = number (From the creation of the UText)
Expand All @@ -17,16 +16,12 @@ Fade Effect
RepeatDelay = number
Rewind = boolean (rewind the animation after playing)
]]--
local loaded = false
Events:Subscribe( "UTLibLoaded", function()
if loaded then return end
loaded = true
UTLib.Fade = {}
Events:Subscribe( "ModulesLoad", function()
class 'Fade'

-- Fade Effect Init
UTLib.Fade.Init =
function( startpos, endpos, params )
local ueFade = {}
function Fade:__init( startpos, endpos, params )
Format.__init(self, startpos, endpos)
local StartTime, Duration, StartAlpha, EndAlpha, Func, Extra = table.unpack(params)
assert(StartTime and Duration and StartAlpha and EndAlpha,"UTLib: Error in Fade effect: Parameters incomplete (Start Time, Duration, StartAlpha, EndAlpha)")
if Func then
Expand All @@ -41,93 +36,92 @@ Events:Subscribe( "UTLibLoaded", function()
Extra = {}
end


ueFade.type = "Fade"
ueFade.startpos = startpos
ueFade.endpos = endpos
ueFade.renderfunc = UTLib.Fade.Render

ueFade.StartTime = StartTime
ueFade.Duration = Duration
ueFade.StartAlpha = StartAlpha
ueFade.EndAlpha = EndAlpha
ueFade.Func = Func or Easing.linear
ueFade.RepeatDelay = Extra.RepeatDelay or 0
ueFade.Rewind = Extra.Rewind
ueFade.AccessParent = Extra.Override
ueFade.Terminate = Extra.Terminate
self.StartTime = StartTime
self.Duration = Duration
self.StartAlpha = StartAlpha
self.EndAlpha = EndAlpha
self.Func = Func or Easing.linear
self.RepeatDelay = Extra.RepeatDelay or 0
self.Rewind = Extra.Rewind
self.AccessParent = Extra.Override
self.Terminate = Extra.Terminate

if Extra.Repeat == true or Extra.Repeat == 1 then
ueFade.Repetitions = 0
ueFade.Repeat = true
self.Repetitions = 0
self.Repeat = true
elseif Extra.Repeat and Extra.Repeat > 1 then
ueFade.Repetitions = Extra.Repeat
ueFade.Repeat = true
self.Repetitions = Extra.Repeat
self.Repeat = true
else
ueFade.Repetitions = 1
ueFade.Repeat = false
self.Repetitions = 1
self.Repeat = false
end


UTLib.TypeCheck({StartTime,Duration,StartAlpha,EndAlpha,ueFade.Repetitions,ueFade.RepeatDelay}, "number", "In Fade format initialization")
return ueFade
if not (type(StartTime) == "number" and
type(Duration) == "number" and
type(StartAlpha) == "number" and
type(EndAlpha) == "number" and
type(self.Repetitions) == "number" and
type(self.RepeatDelay) == "number") then
error("Fade format expected numeric parameters") end
return self
end

-- Fade Effect Render
UTLib.Fade.Render =
function( block, effect )
function Fade:Render( block )
local timeElapsed, timeEnd
if os.clock() == effect.osclock then goto nocalc else effect.osclock = os.clock() end
if effect.StartAlpha > effect.EndAlpha then
effect.rewinding = true
effect.Rewind = true
local s = effect.StartAlpha
effect.StartAlpha = effect.EndAlpha
effect.EndAlpha = s
if os.clock() == self.osclock then goto nocalc else self.osclock = os.clock() end
if self.StartAlpha > self.EndAlpha then
self.rewinding = true
self.Rewind = true
local s = self.StartAlpha
self.StartAlpha = self.EndAlpha
self.EndAlpha = s
end

if not effect.init then
effect.StartTime = os.clock() + effect.StartTime
effect.init = true
if not self.init then
self.StartTime = os.clock() + self.StartTime
self.init = true
end
timeEnd = effect.StartTime + effect.Duration
timeEnd = self.StartTime + self.Duration

if effect.rewinding then
timeElapsed = (os.clock() - (os.clock() - effect.StartTime)*2) - (effect.StartTime - effect.Duration)
if self.rewinding then
timeElapsed = (os.clock() - (os.clock() - self.StartTime)*2) - (self.StartTime - self.Duration)
else
timeElapsed = os.clock() - effect.StartTime
timeElapsed = os.clock() - self.StartTime
end

if effect.StartTime <= os.clock() and os.clock() <= timeEnd then
effect.alpha = effect.Func(timeElapsed, effect.StartAlpha, effect.EndAlpha, effect.Duration)
elseif effect.StartTime > os.clock() then
effect.alpha = effect.StartAlpha
if self.StartTime <= os.clock() and os.clock() <= timeEnd then
self.alpha = self.Func(timeElapsed, self.StartAlpha, self.EndAlpha, self.Duration)
elseif self.StartTime > os.clock() then
self.alpha = self.StartAlpha
end
if os.clock() >= timeEnd then
if not effect.Rewind or effect.Rewind and effect.rewinding then
if effect.Repetitions > 0 then
effect.Repetitions = effect.Repetitions - 1
effect.Repeat = effect.Repetitions > 0
if not self.Rewind or self.Rewind and self.rewinding then
if self.Repetitions > 0 then
self.Repetitions = self.Repetitions - 1
self.Repeat = self.Repetitions > 0
end
if effect.Repeat then
effect.StartTime = timeEnd + effect.RepeatDelay
effect.rewinding = false
if self.Repeat then
self.StartTime = timeEnd + self.RepeatDelay
self.rewinding = false
end
effect.alpha = effect.Rewind and effect.StartAlpha or effect.EndAlpha
if effect.Terminate then effect = nil return end
self.alpha = self.Rewind and self.StartAlpha or self.EndAlpha
if self.Terminate then self = nil return end
else
effect.rewinding = true
effect.StartTime = timeEnd
effect.alpha = effect.EndAlpha
self.rewinding = true
self.StartTime = timeEnd
self.alpha = self.EndAlpha
end
end
::nocalc::
if effect.AccessParent then
block.parent.alpha = effect.alpha
if self.AccessParent then
block.parent.alpha = self.alpha
else
block.color.a = effect.alpha
block.color.a = self.alpha
end
end

UText.RegisterFormat( "fade", UTLib.Fade.Init )
UText.RegisterFormat( Fade, "fade" )
end)
Loading

0 comments on commit d29134d

Please sign in to comment.