Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor00f committed Jan 29, 2025
1 parent b7c4104 commit 8e2bbff
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 18 deletions.
64 changes: 58 additions & 6 deletions src/giflib.lua
Original file line number Diff line number Diff line change
@@ -1,36 +1,74 @@
local ContentProvider = game:GetService("ContentProvider")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local algorithm = require(ReplicatedStorage.Packages.stdlib).algorithm

local giflib = {}

export type GifImage = {
Image: Content,
Image: string,
Time: number
}

export type Gif = {
--[[
Список кадров в гифке
]]
Images:
{
GifImage
},

ImageLabel: ImageLabel,
Frame: number,

--[[
Анимация сейчас запущенна
]]
AnimationRunning: boolean,

--[[
Гифка зацикленна
]]
LoopAnimation: boolean,

StartAnimation: (self: Gif)->any,
StopAnimation: (self: Gif)->any,
ResetAnimation: (self: Gif)->any
ResetAnimation: (self: Gif)->any,
Destroy: (self: Gif)->any,

--[[
Показывает что анимация завершилась
]]
Complited: RBXScriptSignal,
ComplitedEvent: BindableEvent
}

function _Destroy(self: Gif)
self.ComplitedEvent:Destroy()
end

function _Preload(self: Gif)
ContentProvider:PreloadAsync(algorithm.copy_by_prop(self.Images, "Image"))
end

function _StartAnimation(self: Gif)
task.spawn(function()
self.AnimationRunning = true

while not self.AnimationRunning do
self.ImageLabel.ImageContent = self.Images[self.Frame].Image
self.Frame += 1
self.ImageLabel.Image = self.Images[self.Frame].Image

if #self.Images == self.Frame then
break
else
self.Frame += 1
end

task.wait(self.Images[self.Frame].Time)
end

self.ComplitedEvent:Fire()
end)
end

Expand All @@ -42,18 +80,32 @@ function _ResetAnimation(self: Gif)
self.Frame = 1
end

function giflib.newGif(imageLabel: ImageLabel, images: {GifImage}): Gif
function giflib.newGif(imageLabel: ImageLabel, images: {GifImage}, loopAnimation: boolean?): Gif

local _ComplitedEvent = Instance.new("BindableEvent")

local self: Gif = {
ImageLabel = imageLabel,
Images = images,
Frame = 1,
AnimationRunning = false,
Complited = _ComplitedEvent.Event,
ComplitedEvent = _ComplitedEvent,
LoopAnimation = loopAnimation or false,
Destroy = _Destroy,
StartAnimation = _StartAnimation,
StopAnimation = _StopAnimation,
ResetAnimation = _ResetAnimation
ResetAnimation = _ResetAnimation,
}

self.Complited:Connect(function()
if self.LoopAnimation then
self:ResetAnimation()
else
self:StopAnimation()
end
end)

return self
end

Expand Down
17 changes: 10 additions & 7 deletions tests.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
"$className": "DataModel",
"ReplicatedStorage": {
"$className": "ReplicatedStorage",
"Packages": {
"$path": "Packages"
"shared": {
"$path": "src"
},
"DevPackages": {
"$path": "DevPackages"
"Packages": {
"$path": "Packages"
}
},
"Workspace": {
"$className": "Workspace",
"$path": "tests"
"StarterPlayer": {
"$className": "StarterPlayer",
"StarterPlayerScripts": {
"$className": "StarterPlayerScripts",
"$path": "tests"
}
}
}
}
18 changes: 18 additions & 0 deletions tests/test.client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local giflib = require(ReplicatedStorage.shared.giflib)


local imgLabel = Instance.new("ImageLabel")

local mygif = giflib.newGif(
imgLabel,
{
{Image = "img1", Time = 0.08},
{Image = "img2", Time = 0.08},
{Image = "img3", Time = 0.08}

}
)

mygif:StartAnimation()
11 changes: 6 additions & 5 deletions wally.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "egor00f/egor00f"
name = "egor00f/giflib"

description = "Library for creating gifs"

version = "0.1.0"
version = "0.1.1"

registry = "https://github.com/UpliftGames/wally-index"

Expand All @@ -16,15 +16,16 @@ repository = "https://github.com/Ukuroks-games/giflib"

authors = ["Egor00f <velikiydolbayeb@gmail.com>"]

exclude = ["packageName.rbxl"]
exclude = ["*"]

include = ["src", "src/**", "wally.toml", "README.md", "init.lua"]

private = false

[dependencies]

stdlib = "egor00f/stdlib@0.1.5"

[server-dependencies]


[dev-dependencies]

0 comments on commit 8e2bbff

Please sign in to comment.