Advertisement
CAT_SUS

FF.lua

Aug 12th, 2023 (edited)
5,541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. local FileSave = {}
  2. local MainInfo = {}
  3. local HttpsService = game:GetService('HttpService')
  4.  
  5. function FileSave:SetupData(info)
  6.     MainInfo = info
  7. end
  8.  
  9. function FileSave:CreateFile(__Name__)
  10.     local jsonName = "data_location.txt"
  11.     if not isfolder(__Name__) then
  12.         makefolder(__Name__)
  13.     end
  14.  
  15.     wait()
  16.  
  17.     if isfolder(__Name__) then
  18.         local path = tostring(__Name__).."/"..tostring(jsonName)
  19.  
  20.         if isfile(path) then
  21.             delfile(path)
  22.         end
  23.  
  24.         writefile(path,tostring(HttpsService:JSONEncode(MainInfo)))
  25.     end
  26. end
  27.  
  28. function FileSave:LoadFile(__name__)
  29.     local jsonName = "data_location.txt"
  30.     local Path = tostring(__name__).."/"..tostring(jsonName)
  31.     if isfile(Path) then
  32.         local stringF = readfile(Path)
  33.         if stringF then
  34.             local Ecode = HttpsService:JSONDecode(stringF)
  35.             return Ecode
  36.         end
  37.     end
  38.     return nil
  39. end
  40.  
  41.  
  42. local function ImageMain(__Name__,Url,imgname,filetype)
  43.     filetype = filetype or "jpg"
  44.     filetype = filetype:upper()
  45.     imgname = imgname or "Image_"..tostring(__Name__)
  46.     imgname = imgname..tostring('.')..tostring(filetype)
  47.  
  48.     local ImgPath = tostring(__Name__)..tostring("/")..tostring(imgname)
  49.  
  50.     if not isfile(ImgPath) then
  51.         writefile(ImgPath,game:HttpGet(tostring(Url)))
  52.     end
  53.  
  54.     if isfile(ImgPath) then
  55.         local asset = getcustomasset(ImgPath)
  56.         return asset
  57.     end
  58.  
  59.     return nil
  60. end
  61.  
  62. function FileSave:CheckFile(__name__)
  63.     local jsonName = "data_location.txt"
  64.     local Path = tostring(__name__).."/"..tostring(jsonName)
  65.     if isfolder(__name__) then
  66.         if isfile(Path) then
  67.             return true
  68.         end
  69.     end
  70.     return false
  71. end
  72.  
  73. function FileSave:LoadImageFromUrl(__Name__,Url,imgname,filetype)
  74.     local screened = Instance.new('ScreenGui',game:FindFirstChild('CoreGui')) screened.Enabled = true
  75.     local Png = Instance.new('ImageLabel',screened) Png.Size = UDim2.new(0.1,0,0,0.1) Png.Name = "png"
  76.     local Jpg = Instance.new('ImageLabel',screened) Jpg.Size = UDim2.new(0.1,0,0,0.1) Jpg.Name = "jpg"
  77.     local Jpeg = Instance.new('ImageLabel',screened) Jpeg.Size = UDim2.new(0.1,0,0,0.1) Jpeg.Name = "jpeg"
  78.  
  79.     local FolderForImage = "ImageCollection"
  80.     local ImC = __Name__..tostring('/')..tostring(FolderForImage)
  81.  
  82.     makefolder(ImC)
  83.  
  84.     repeat task.wait()
  85.  
  86.         local PngId = ImageMain(ImC,Url,imgname,'PNG')
  87.         local JpgId = ImageMain(ImC,Url,imgname,'JPG')
  88.         local JpegId = ImageMain(ImC,Url,imgname,'JPEG')
  89.  
  90.         Png.Image = PngId
  91.         Jpg.Image = JpgId
  92.         Jpeg.Image = JpegId
  93.  
  94.     until Png.IsLoaded or Jpg.IsLoaded or Jpeg.IsLoaded
  95.     local a = {Png,Jpg,Jpeg}
  96.     local main
  97.  
  98.     for _,v in ipairs(a) do
  99.         if v.IsLoaded then
  100.             main = v
  101.             break
  102.         end
  103.     end
  104.  
  105.     if main then
  106.         coroutine.wrap(function()
  107.             wait(0.5)
  108.             screened:Destroy()
  109.         end)()
  110.         return main.Image
  111.     end
  112. end
  113.  
  114. return FileSave
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement