local o=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local T=o:WaitForChild("\099\111\109\109\111\110")local m=o:WaitForChild("\108\105\098")local M=script.Parent.Parent local N=T:WaitForChild("\117\116\105\108")local y=require(N:WaitForChild("\098\101\097\117\116\105\102\121\078\117\109\098\101\114"))local k=require(N:WaitForChild("\103\101\116\084\101\120\116\083\105\122\101"))local f=require(M:WaitForChild("\083\104\097\100\111\119\101\100\084\101\120\116\076\097\098\101\108"))local P=require(m:WaitForChild("\082\111\097\099\116"))local V=require(m:WaitForChild("\079\116\116\101\114"))local B=P.Component:extend("\083\116\097\116\067\111\117\110\116\101\114")function B.init(o)o:setState({iconRotation=0,scale=1;yOffset=0,xOffset=0})end function B.didMount(o)o.springus=V.createGroupMotor({rotation=0;scale=1,yOffset=0,xOffset=0})o.springus:onStep(function(T)o:setState({iconRotation=T.rotation;scale=T.scale;yOffset=T.yOffset,xOffset=T.xOffset})end)end function B.sproing(o)o.springus:stop()o.springus.__states.rotation.velocity=math.random(600,700)*(math.random(0,1)*2-1)o.springus.__states.scale.velocity=5 o.springus.__states.yOffset.velocity=math.random(-300,-100)o.springus.__states.xOffset.velocity=math.random(50,200)*(math.random(0,1)*2-1)o.springus:setGoal({rotation=V.spring(0,{dampingRatio=.1,frequency=4});scale=V.spring(1,{dampingRatio=.15;frequency=4});yOffset=V.spring(0,{dampingRatio=.15,frequency=3});xOffset=V.spring(0,{dampingRatio=.15,frequency=3})})o.springus:start()end function B.didUpdate(m,o,T)if m.props.value~=o.value then m:sproing()end end function B.render(o)local T=o.props T.iconImage=T.iconImage or"\114\098\120\097\115\115\101\116\105\100\058\047\047"T.statName=T.statName or"\085\078\068\069\070\073\078\069\068"T.fontSize=T.fontSize or 36 T.value=T.value or"\085\078\068\069\070\073\078\069\068"T.font=T.font or Enum.Font.GothamBlack T.Size=T.Size or UDim2.new(0,400,0,64)T.Position=T.Position or UDim2.new(0,0,.5,0)local m=k(T.statName,T.font,T.fontSize)local M=k(T.value,T.font,T.fontSize)local N={layout=P.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{SortOrder=Enum.SortOrder.LayoutOrder,FillDirection=Enum.FillDirection.Horizontal,VerticalAlignment=Enum.VerticalAlignment.Center,Padding=UDim.new(0,8)});nameLabel=f({Text=T.statName,BackgroundTransparency=1;Font=T.font,TextSize=T.fontSize,TextColor3=Color3.fromRGB(255,255,255);TextStrokeTransparency=0,Size=UDim2.new(T.Size.X.Scale,m.X,T.Size.Y.Scale,T.Size.Y.Offset);LayoutOrder=1,TextYAlignment=Enum.TextYAlignment.Center});valueLabel=f({BackgroundTransparency=1,Text=y(T.value,true);Font=T.font,TextSize=T.fontSize+(o.state.scale-1)*25;TextColor3=Color3.fromRGB(255,255,255),TextStrokeTransparency=0,TextXAlignment=Enum.TextXAlignment.Left,TextYAlignment=Enum.TextYAlignment.Center;Size=UDim2.new(T.Size.X.Scale,M.X,T.Size.Y.Scale,T.Size.Y.Offset);LayoutOrder=2})}if T.iconImage then N.iconFrame=P.createElement("\070\114\097\109\101",{BackgroundTransparency=1,Size=UDim2.new(T.Size.X.Scale,T.Size.Y.Offset,T.Size.Y.Scale,T.Size.Y.Offset),LayoutOrder=0},{icon=P.createElement("\073\109\097\103\101\076\097\098\101\108",{Name="\105\099\111\110\076\097\098\101\108";BackgroundTransparency=1;Image=T.iconImage;Rotation=o.state.iconRotation;AnchorPoint=Vector2.new(.5,.5),Size=UDim2.new(o.state.scale,0,o.state.scale,0);Position=UDim2.new(.5,o.state.xOffset,.5,o.state.yOffset)})})end return P.createElement("\070\114\097\109\101",{Name="\099\111\117\110\116\101\114\070\114\097\109\101",AnchorPoint=Vector2.new(0,.5);Size=T.Size;Position=T.Position;BackgroundTransparency=1;LayoutOrder=o.props.layoutOrder or 1},N)end return B
-- dont look im indecent!

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local common = ReplicatedStorage:WaitForChild("common")
local lib = ReplicatedStorage:WaitForChild("lib")

local component = script.Parent.Parent
local util = common:WaitForChild("util")

local beautifyNumber = require(util:WaitForChild("beautifyNumber"))
local getTextSize = require(util:WaitForChild("getTextSize"))

local ShadowedTextLabel = require(component:WaitForChild("ShadowedTextLabel"))

local Roact = require(lib:WaitForChild("Roact"))
local Otter = require(lib:WaitForChild("Otter"))

local StatCounter = Roact.Component:extend("StatCounter")

function StatCounter:init()
    self:setState({
        iconRotation = 0,
        scale = 1,
        yOffset = 0,
        xOffset = 0,
    })
end

function StatCounter:didMount()
    -- animator, find a way to factor this kinda thing into a wrapper component?
    self.springus = Otter.createGroupMotor({rotation = 0, scale = 1,yOffset = 0,xOffset = 0})
    self.springus:onStep(function(values)
        self:setState({
            iconRotation = values.rotation,
            scale = values.scale,
            yOffset = values.yOffset,
            xOffset = values.xOffset,
        })
    end)
end

function StatCounter:sproing()
    self.springus:stop()
    self.springus.__states.rotation.velocity = math.random(600,700) * (math.random(0,1)*2 - 1)
    self.springus.__states.scale.velocity = 5
    self.springus.__states.yOffset.velocity = math.random(-300,-100)
    self.springus.__states.xOffset.velocity = math.random(50,200) * (math.random(0,1)*2 - 1)
    self.springus:setGoal({
        rotation = Otter.spring(0, {dampingRatio = 0.1, frequency = 4}),
        scale = Otter.spring(1, {dampingRatio = 0.15, frequency = 4}),
        yOffset = Otter.spring(0, {dampingRatio = 0.15, frequency = 3}),
        xOffset = Otter.spring(0, {dampingRatio = 0.15, frequency = 3}),
    })
    self.springus:start()
end

function StatCounter:didUpdate(prevProps,prevState)
    if self.props.value ~= prevProps.value then
        self:sproing()
    end
end

function StatCounter:render()
    local props = self.props
    props.iconImage = props.iconImage or "rbxassetid://"
    props.statName = props.statName or "UNDEFINED"
    props.fontSize = props.fontSize or 36
    props.value = props.value or "UNDEFINED"
    props.font = props.font or Enum.Font.GothamBlack
    props.Size = props.Size or UDim2.new(0,400,0,64)
    props.Position = props.Position or UDim2.new(0,0,0.5,0)

    local statWidth = getTextSize(props.statName,props.font,props.fontSize)
    local valueWidth = getTextSize(props.value,props.font,props.fontSize)

    local children = {
        layout = Roact.createElement("UIListLayout",{
            SortOrder = Enum.SortOrder.LayoutOrder,
            FillDirection = Enum.FillDirection.Horizontal,
            VerticalAlignment = Enum.VerticalAlignment.Center,
            Padding = UDim.new(0,8),
        }),
        nameLabel = ShadowedTextLabel({
            Text = props.statName, -- :) <-- this is a smile, i hope it made you smile!
            BackgroundTransparency = 1,
            Font = props.font,
            TextSize = props.fontSize,
            TextColor3 = Color3.fromRGB(255,255,255),
            TextStrokeTransparency = 0,
            Size = UDim2.new(props.Size.X.Scale,statWidth.X,props.Size.Y.Scale,props.Size.Y.Offset),
            LayoutOrder = 1,
            TextYAlignment = Enum.TextYAlignment.Center,
        }),
        valueLabel = ShadowedTextLabel({
            BackgroundTransparency = 1,
            Text = beautifyNumber(props.value,true),
            Font = props.font,
            TextSize = props.fontSize + ((self.state.scale-1)*25),
            TextColor3 = Color3.fromRGB(255,255,255),
            TextStrokeTransparency = 0,
            TextXAlignment = Enum.TextXAlignment.Left,
            TextYAlignment = Enum.TextYAlignment.Center,
            Size = UDim2.new(props.Size.X.Scale,valueWidth.X,props.Size.Y.Scale,props.Size.Y.Offset),
            LayoutOrder = 2,
        }),
    }

    if props.iconImage then
        children.iconFrame = Roact.createElement("Frame", {
            BackgroundTransparency = 1,
            Size = UDim2.new(props.Size.X.Scale,props.Size.Y.Offset,props.Size.Y.Scale,props.Size.Y.Offset),
            LayoutOrder = 0,
        },{
            icon = Roact.createElement("ImageLabel", {
                Name = "iconLabel",
                BackgroundTransparency = 1,
                Image = props.iconImage,
                Rotation = self.state.iconRotation,
                AnchorPoint = Vector2.new(0.5,0.5),
                Size = UDim2.new(self.state.scale,0,self.state.scale,0),
                Position = UDim2.new(0.5,self.state.xOffset,0.5,self.state.yOffset),
            }),
        })
    end

    return Roact.createElement("Frame",{
        Name = "counterFrame",
        AnchorPoint = Vector2.new(0,0.5),
        Size = props.Size,
        Position = props.Position,
        BackgroundTransparency = 1,
        LayoutOrder = self.props.layoutOrder or 1,
    }, children)
end

return StatCounter