Skip to content

Commit

Permalink
some small fixes
Browse files Browse the repository at this point in the history
+ fix Destroy func if animation stiil running
+ add Destroying Event
+ add tests.json
+ update Readme
  • Loading branch information
Egor00f committed Feb 14, 2025
1 parent fa22f35 commit 4f68437
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 14 deletions.
78 changes: 78 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"tasks": [
{
"type": "shell",
"label": "Build tests",
"detail": "Build tests place",
"command": "rojo build tests.project.json --output tests.rbxl && exit",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"Install depends"
]
},
{
"type": "shell",
"label": "Generate sourcemap for tests",
"detail": "Generate sourcemap for tests",
"command": "rojo sourcemap tests.project.json --output sourcemap.json && exit",
"group": {
"kind": "none"
},
"dependsOn": [
"Install depends"
]
},
{
"type": "shell",
"label": "Install programms",
"detail": "Install programms using aftman",
"command": "aftman install && exit",
"group": {
"kind": "none"
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Install depends",
"detail": "Install all project depends",
"command": "wally install && exit",
"group": {
"kind": "none"
},
"problemMatcher": [],
},
{
"type": "shell",
"label": "Update depends",
"detail": "Update all project depends",
"command": "wally update && exit",
"group": {
"kind": "none"
},
"problemMatcher": [],
},
{
"type": "shell",
"label": "publish",
"detail": "publish it as wally package",
"command": "wally publish && exit",
"group": {
"kind": "none"
},
"problemMatcher": []
},
],
"options": {
"shell": {
"executable": "cmd",
"args": [
"/k"
]
}
},
"version": "2.0.0"
}
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
# Giflib

library for creating gifs
Small library for creating gifs in roblox



## Functions

`newGif` - gif constructor.

`newImage` - gif image constructor

`StartAnimation` - start gif animation

`StopAnimation` - stopping animation

`ResetAnimation` - Reset animation.

`Preload` - Preload images.

`AddImage` - Adding image existing gif

## Events

`Completed` - Fire on animation is ended. If animation is looped fires on every restarting

`Destroying` - Fire on destroying gif

## Example

Expand Down Expand Up @@ -35,4 +59,19 @@ local mygif = giflib.newGif(
)
mygif:StartAnimation()
wait(10)
mygif:StopAnimation()
wait(10)
mygif:StartAnimation() -- continue
wait(10)
mygif:Destroy()
```
50 changes: 38 additions & 12 deletions src/giflib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,45 @@ export type Gif = {
--[[
Destroy gif
]]
Destroy: (self: Gif)->any,
Destroy: (self: Gif)->nil,
--[[
Preload all images
]]
Preload: (self: Gif)->any,
Preload: (self: Gif)->nil,

--[[
Add image
]]
AddImage: (self: Gif, image: GifImage)->any,
AddImage: (self: Gif, image: GifImage)->nil,

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

Destroying: RBXScriptConnection,
DestroyingEvent: BindableEvent,

AnimationThread: thread
}

function giflib.Destroy(self: Gif)
self.ComplitedEvent:Destroy()

-- Если анимация всё ещё запущенна
if self.AnimationRunning then
task.cancel(self.AnimationThread)
end

self.DestroyingEvent:Fire()

for _, v in pairs(self.Images) do
if v then
v.Image:Destroy()
end
end

table.clear(self)
end

function giflib.Preload(self: Gif)
Expand All @@ -108,7 +127,7 @@ function giflib.StartAnimation(self: Gif)

self.AnimationRunning = true

task.spawn(function()
self.AnimationThread = task.spawn(function()
while self.AnimationRunning and #self.Images >= self.Frame do
local GifImage = self.Images[self.Frame]

Expand All @@ -126,7 +145,7 @@ function giflib.StartAnimation(self: Gif)

self.AnimationRunning = false

self.ComplitedEvent:Fire()
self.CompletedEvent:Fire()
end)
end

Expand Down Expand Up @@ -159,29 +178,36 @@ end
function giflib.newGif(Label: Frame, images: {GifImage}, loopAnimation: boolean?): Gif

local _ComplitedEvent = Instance.new("BindableEvent")
local _DestroyingEvent = Instance.new("BindableEvent")

local self: Gif = {
ImageLabel = Label,
Images = images,
Frame = 1,
AnimationRunning = false,
Complited = _ComplitedEvent.Event,
ComplitedEvent = _ComplitedEvent,
Completed = _ComplitedEvent.Event,
CompletedEvent = _ComplitedEvent,
Destroying = _DestroyingEvent.Event,
DestroyingEvent = _DestroyingEvent,
LoopAnimation = loopAnimation or false,
IsLoaded = false,
Destroy = giflib.Destroy,
StartAnimation = giflib.StartAnimation,
StopAnimation = giflib.StopAnimation,
ResetAnimation = giflib.ResetAnimation,
Preload = giflib.Preload,
AddImage = giflib.AddImage
AddImage = giflib.AddImage,
AnimationThread = nil,
__len = function(self: Gif)
return #self.Images
end
}

for _, v in pairs(self.Images) do
v.Image.Parent = Label
end

self.Complited:Connect(function()
self.Completed:Connect(function()
if self.LoopAnimation then
self:ResetAnimation()
else
Expand Down
16 changes: 16 additions & 0 deletions tests/test.client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,19 @@ local mygif = giflib.newGif(
)

mygif:StartAnimation()




wait(10)
mygif:StopAnimation()

wait(10)
mygif:StartAnimation() -- continue




wait(10)

mygif:Destroy()
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "egor00f/giflib"

description = "Library for creating gifs"

version = "0.1.2"
version = "0.1.3"

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

Expand Down

0 comments on commit 4f68437

Please sign in to comment.