using System;
using System.Collections.Generic;
using Ubisoft.Hotel.Package.Editor;
namespace Ubisoft.Hotel.PackageManager.Editor
{
internal class BuildArguments
{
internal enum EVersion
{
None,
BumpPatch // Bump patch and version code. Game version format: major.minor.patch
};
//
/// Pararameter responsible for modifying game version
///
internal EVersion Version { get; set; }
///
/// Platform to build for. Useful to override BuildTarget as platform, typically for platforms like Amazon
/// that don't have their own Unity BuildTarget.
///
internal EPlatform Platform { get; set; }
internal Dictionary Pairs { get; set; }
internal BuildArguments(EVersion version, EPlatform platform)
{
Version = version;
Platform = platform;
Pairs = new Dictionary();
}
}
///
/// Class responsible for processing the arguments that are passed in when building an app, typically by the cicd
///
internal class BuildArgumentsProcessor
{
private const char PARAM_SEPARATOR = ':';
private const string PARAM_KEY_VERSION = "version";
private const string PARAM_KEY_PLATFORM = "platform";
private static readonly List PARAM_KEYS = new List()
{
PARAM_KEY_VERSION,
PARAM_KEY_PLATFORM
};
private static readonly string[] EVersionKeysArray = Enum.GetNames(typeof(BuildArguments.EVersion));
private static readonly List EVersionKeys = new List(EVersionKeysArray);
public static void ProcessArguments(string[] arguments, BuildSettings buildSettings, BuildArguments buildArguments)
{
string argumentsAsString = (arguments == null) ? null : string.Join(", ", arguments);
PackageManager.Log($"BuildPlayer arguments: {Debug.FormatTextInUserContext(argumentsAsString)}");
if (arguments != null)
{
// Loop through all arguments to find the Hotel ones, which need to be passed to AppSpaceBuildSuiteProvider
string[] tokens;
int count = arguments.Length;
for (int i = 0; i < count; ++i)
{
// Hotel arguments follow the format: :
tokens = arguments[i].Split(PARAM_SEPARATOR);
if (tokens.Length == 2)
{
// Token is passed in to AppSpaceBuildSuiteProvider only if it's not a builder parameter
if (!ProcessParam(buildArguments, tokens[0], tokens[1], buildSettings))
{
buildArguments.Pairs.Add(tokens[0], tokens[1]);
}
}
}
}
}
private static bool ProcessParam(BuildArguments buildArguments, string key, string value, BuildSettings buildSettings)
{
bool returnValue = false;
if (buildSettings != null)
{
returnValue = buildSettings.ProcessBuildParams(key, value);
}
if (!returnValue)
{
returnValue = PARAM_KEYS.Contains(key);
if (returnValue)
{
switch (key)
{
case PARAM_KEY_VERSION:
buildArguments.Version = KeyToEVersion(value);
break;
case PARAM_KEY_PLATFORM:
buildArguments.Platform = PlatformUtils.KeyToEPlatform(value);
break;
}
}
}
return returnValue;
}
private static BuildArguments.EVersion KeyToEVersion(string key)
{
int index = EVersionKeys.IndexOf(key);
return (index == -1) ? BuildArguments.EVersion.None : (BuildArguments.EVersion)index;
}
}
}