mirror of
https://github.com/CompeyDev/lune-packaging.git
synced 2025-01-10 04:39:08 +00:00
Minor fixes for remodel migration module
This commit is contained in:
parent
83303cf5e6
commit
f1c62245da
2 changed files with 25 additions and 15 deletions
|
@ -1,10 +1,12 @@
|
||||||
|
--!strict
|
||||||
|
|
||||||
local fs = require("@lune/fs")
|
local fs = require("@lune/fs")
|
||||||
local net = require("@lune/net")
|
local net = require("@lune/net")
|
||||||
local serde = require("@lune/serde")
|
local serde = require("@lune/serde")
|
||||||
local process = require("@lune/process")
|
local process = require("@lune/process")
|
||||||
local roblox = require("@lune/roblox")
|
local roblox = require("@lune/roblox")
|
||||||
|
|
||||||
export type LuneDataModel = roblox.Instance
|
export type LuneDataModel = roblox.DataModel
|
||||||
export type LuneInstance = roblox.Instance
|
export type LuneInstance = roblox.Instance
|
||||||
|
|
||||||
local function getAuthCookieWithFallbacks()
|
local function getAuthCookieWithFallbacks()
|
||||||
|
@ -194,9 +196,9 @@ function remodel.readModelFile(filePath: string)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
Reads a place asset from Roblox.com, equivalent to `remodel.readPlaceFile`.
|
Reads a place asset from Roblox, equivalent to `remodel.readPlaceFile`.
|
||||||
|
|
||||||
This method requires web authentication!
|
***NOTE:** This function requires authentication using a ROBLOSECURITY cookie!*
|
||||||
]=]
|
]=]
|
||||||
function remodel.readPlaceAsset(assetId: number)
|
function remodel.readPlaceAsset(assetId: number)
|
||||||
local contents = downloadAssetId(assetId)
|
local contents = downloadAssetId(assetId)
|
||||||
|
@ -205,9 +207,9 @@ function remodel.readPlaceAsset(assetId: number)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
Reads a model asset from Roblox.com, equivalent to `remodel.readModelFile`.
|
Reads a model asset from Roblox, equivalent to `remodel.readModelFile`.
|
||||||
|
|
||||||
This method requires web authentication!
|
***NOTE:** This function requires authentication using a ROBLOSECURITY cookie!*
|
||||||
]=]
|
]=]
|
||||||
function remodel.readModelAsset(assetId: number)
|
function remodel.readModelAsset(assetId: number)
|
||||||
local contents = downloadAssetId(assetId)
|
local contents = downloadAssetId(assetId)
|
||||||
|
@ -222,7 +224,9 @@ end
|
||||||
Models should be saved with `writeModelFile` instead.
|
Models should be saved with `writeModelFile` instead.
|
||||||
]=]
|
]=]
|
||||||
function remodel.writePlaceFile(filePath: string, dataModel: LuneDataModel)
|
function remodel.writePlaceFile(filePath: string, dataModel: LuneDataModel)
|
||||||
|
local asBinary = string.sub(filePath, -6) == ".rbxl"
|
||||||
local asXml = string.sub(filePath, -6) == ".rbxlx"
|
local asXml = string.sub(filePath, -6) == ".rbxlx"
|
||||||
|
assert(asBinary or asXml, "File path must have .rbxl or .rbxlx extension")
|
||||||
local placeFile = roblox.serializePlace(dataModel, asXml)
|
local placeFile = roblox.serializePlace(dataModel, asXml)
|
||||||
fs.writeFile(filePath, placeFile)
|
fs.writeFile(filePath, placeFile)
|
||||||
end
|
end
|
||||||
|
@ -234,18 +238,20 @@ end
|
||||||
Places should be saved with `writePlaceFile` instead.
|
Places should be saved with `writePlaceFile` instead.
|
||||||
]=]
|
]=]
|
||||||
function remodel.writeModelFile(filePath: string, instance: LuneInstance)
|
function remodel.writeModelFile(filePath: string, instance: LuneInstance)
|
||||||
|
local asBinary = string.sub(filePath, -6) == ".rbxm"
|
||||||
local asXml = string.sub(filePath, -6) == ".rbxmx"
|
local asXml = string.sub(filePath, -6) == ".rbxmx"
|
||||||
|
assert(asBinary or asXml, "File path must have .rbxm or .rbxmx extension")
|
||||||
local placeFile = roblox.serializeModel({ instance }, asXml)
|
local placeFile = roblox.serializeModel({ instance }, asXml)
|
||||||
fs.writeFile(filePath, placeFile)
|
fs.writeFile(filePath, placeFile)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
Uploads the given `DataModel` instance to Roblox.com, overwriting an existing place.
|
Uploads the given `DataModel` instance to Roblox, overwriting an existing place.
|
||||||
|
|
||||||
If the instance is not a `DataModel`, this function will throw.
|
If the instance is not a `DataModel`, this function will throw.
|
||||||
Models should be uploaded with `writeExistingModelAsset` instead.
|
Models should be uploaded with `writeExistingModelAsset` instead.
|
||||||
|
|
||||||
This method requires web authentication!
|
***NOTE:** This function requires authentication using a ROBLOSECURITY cookie!*
|
||||||
]=]
|
]=]
|
||||||
function remodel.writeExistingPlaceAsset(dataModel: LuneDataModel, assetId: number)
|
function remodel.writeExistingPlaceAsset(dataModel: LuneDataModel, assetId: number)
|
||||||
local placeFile = roblox.serializePlace(dataModel)
|
local placeFile = roblox.serializePlace(dataModel)
|
||||||
|
@ -253,12 +259,12 @@ function remodel.writeExistingPlaceAsset(dataModel: LuneDataModel, assetId: numb
|
||||||
end
|
end
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
Uploads the given instance to Roblox.com, overwriting an existing model.
|
Uploads the given instance to Roblox, overwriting an existing model.
|
||||||
|
|
||||||
If the instance is a `DataModel`, this function will throw.
|
If the instance is a `DataModel`, this function will throw.
|
||||||
Places should be uploaded with `writeExistingPlaceAsset` instead.
|
Places should be uploaded with `writeExistingPlaceAsset` instead.
|
||||||
|
|
||||||
This method requires web authentication!
|
***NOTE:** This function requires authentication using a ROBLOSECURITY cookie!*
|
||||||
]=]
|
]=]
|
||||||
function remodel.writeExistingModelAsset(instance: LuneInstance, assetId: number)
|
function remodel.writeExistingModelAsset(instance: LuneInstance, assetId: number)
|
||||||
local modelFile = roblox.serializeModel({ instance })
|
local modelFile = roblox.serializeModel({ instance })
|
||||||
|
|
|
@ -2,7 +2,8 @@ type InstanceProperties = {
|
||||||
Parent: Instance?,
|
Parent: Instance?,
|
||||||
ClassName: string,
|
ClassName: string,
|
||||||
Name: string,
|
Name: string,
|
||||||
[string]: any,
|
-- FIXME: This breaks intellisense, but we need some way to access instance properties...
|
||||||
|
-- [string]: any,
|
||||||
}
|
}
|
||||||
|
|
||||||
type InstanceMetatable = {
|
type InstanceMetatable = {
|
||||||
|
@ -40,14 +41,17 @@ export type Instance = typeof(setmetatable(
|
||||||
(nil :: any) :: { __index: InstanceMetatable }
|
(nil :: any) :: { __index: InstanceMetatable }
|
||||||
))
|
))
|
||||||
|
|
||||||
type DataModelMetatable = {
|
export type DataModelProperties = {}
|
||||||
|
export type DataModelMetatable = {
|
||||||
GetService: (self: DataModel, name: string) -> Instance,
|
GetService: (self: DataModel, name: string) -> Instance,
|
||||||
FindService: (self: DataModel, name: string) -> Instance?,
|
FindService: (self: DataModel, name: string) -> Instance?,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DataModel = typeof(setmetatable(
|
export type DataModel =
|
||||||
(nil :: any) :: InstanceProperties,
|
Instance
|
||||||
(nil :: any) :: { __index: InstanceMetatable & DataModelMetatable }
|
& typeof(setmetatable(
|
||||||
|
(nil :: any) :: DataModelProperties,
|
||||||
|
(nil :: any) :: { __index: DataModelMetatable }
|
||||||
))
|
))
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
|
|
Loading…
Reference in a new issue