Last active
January 5, 2020 08:14
-
-
Save NobleDraconian/5242fa0aebd9c5e4e01f9d169403a814 to your computer and use it in GitHub Desktop.
Using remodel to add assets to game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Example asset list | |
return{ | |
AssetGroups = { | |
["UIs"] = { | |
"UIs", | |
"ReplicatedFirst.Assets.UIs" | |
}, | |
["Market Assets"] = { | |
"Market_Assets", | |
"ServerStorage.Assets.Market_Assets" | |
}, | |
["Boss Maps"] = { | |
"Maps/Boss_Maps", | |
"ServerStorage.Maps.Boss_Maps" | |
} | |
}, | |
Assets = { | |
["Map Spawn"] = { | |
"MapSpawn.rbxmx", | |
"Workspace" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
where /q rojo | |
if %ERRORLEVEL% neq 0 ( | |
echo Rojo does not appear to be installed on your system or is not on your system path. | |
echo In order to compile the game, you will need rojo 0.5.3 or above installed. | |
exit /b | |
) else ( | |
pushd %~dp0 | |
<nul set/p=Compiling game with | |
rojo --version | |
rojo build ..\ --output ..\CurrentBuild.rbxlx | |
echo Game compiled. | |
popd | |
) | |
where /q remodel | |
if %ERRORLEVEL% neq 0 ( | |
echo Remodel does not appear to be installed on your system or is not on your system path. | |
echo In order to compile the game, you will need remodel 0.6.0 or above installed. | |
) else ( | |
pushd %~dp0 | |
<nul set/p=Compiling game assets with | |
remodel --version | |
remodel .\CompileAssets.lua | |
echo Assets compiled. | |
popd | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Temporary script that uses remodel to place assets (such as maps and UIs) into the game, since | |
rojo does not support refs yet. This should be removed when rojo 0.6.0 is released, which adds | |
support for refs. | |
--]] | |
------------- | |
-- Defines -- | |
------------- | |
local AssetList = require('AssetList') | |
local ASSET_PATH = "../Assets/" | |
local BUILD_FILE = "../CurrentBuild.rbxlx" | |
local DEBUG_MODE = false | |
local Debug_TabLevel = 0 | |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
-- Helper functions | |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
function splitstring(inputstr, sep) | |
if sep == nil then | |
sep = "%s" | |
end | |
local t={} | |
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | |
table.insert(t, str) | |
end | |
return t | |
end | |
local function GetInstanceFromDatamodel(Datamodel,StringPath) | |
local CurrentObjectReference = Datamodel | |
for _, ObjectName in pairs(splitstring(StringPath,".")) do | |
if CurrentObjectReference:FindFirstChild(ObjectName) ~= nil then | |
CurrentObjectReference = CurrentObjectReference[ObjectName] | |
else | |
error(ObjectName.." was not found.") | |
return nil | |
end | |
end | |
return CurrentObjectReference | |
end | |
local function CompileDirectory(Directory,Datamodel,TargetPath) | |
local DirectoryNameChunks; | |
local DirectoryName; | |
local CurrentTabLevel = 0 | |
if DEBUG_MODE and Debug_TabLevel > 0 then | |
DirectoryNameChunks = splitstring(Directory,"/") | |
DirectoryName = DirectoryNameChunks[#DirectoryNameChunks] | |
CurrentTabLevel = Debug_TabLevel | |
print(string.rep(" ",Debug_TabLevel).."Compiling contents of directory '"..DirectoryName.."' into "..TargetPath.."...") | |
end | |
local AssetFiles = remodel.readDir(Directory) | |
for _,AssetFileName in pairs(AssetFiles) do | |
if DEBUG_MODE then | |
print(string.rep(" ",Debug_TabLevel).."Compiling '"..AssetFileName.."'...") | |
end | |
local TargetInstance = GetInstanceFromDatamodel(Datamodel,TargetPath) | |
local Success,Asset = pcall(function() | |
return remodel.readModelFile(Directory.."/"..AssetFileName)[1] | |
end) | |
if Success then | |
Asset.Parent = TargetInstance | |
else -- Subdirectory found, iterate through it and compile its assets | |
local Folder = Instance.new('Folder') | |
Folder.Name = AssetFileName | |
Folder.Parent = TargetInstance | |
Debug_TabLevel = Debug_TabLevel + 1 | |
CompileDirectory(Directory.."/"..AssetFileName,Datamodel,TargetPath.."."..Folder.Name) | |
Debug_TabLevel = Debug_TabLevel - 1 | |
end | |
end | |
if DEBUG_MODE then | |
if CurrentTabLevel == 0 then | |
Debug_TabLevel = 0 | |
end | |
end | |
end | |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
-- Compiling assets | |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
local Datamodel = remodel.readPlaceFile(BUILD_FILE) | |
for AssetGroupName,AssetGroupPaths in pairs(AssetList.AssetGroups) do | |
if DEBUG_MODE then | |
print("\nCompiling asset group '"..AssetGroupName.."' from "..ASSET_PATH..AssetGroupPaths[1].." into "..AssetGroupPaths[2].."...") | |
end | |
CompileDirectory(ASSET_PATH..AssetGroupPaths[1],Datamodel,AssetGroupPaths[2]) | |
end | |
if DEBUG_MODE then | |
print("\nCompiling ungrouped assets...") | |
end | |
for AssetName,AssetPaths in pairs(AssetList.Assets) do | |
if DEBUG_MODE then | |
print("Compiling '"..AssetName.."' from "..ASSET_PATH..AssetPaths[1].." into "..AssetPaths[2].."...") | |
end | |
local TargetInstance = GetInstanceFromDatamodel(Datamodel,AssetPaths[2]) | |
local Asset = remodel.readModelFile(ASSET_PATH..AssetPaths[1])[1] | |
Asset.Parent = TargetInstance | |
end | |
remodel.writePlaceFile(Datamodel,BUILD_FILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment