using System.Linq; using UnityEngine; namespace Unity.Play.Publisher.Editor { /// /// Represents an event ("action") that can be dispatched when something happens. /// Base class for all actions. /// public class PublisherAction { } /// /// Represents the event sent to start the publishing process /// /// /// Dispatch this action to start the publishing process /// public class PublishStartAction : PublisherAction { /// /// Title of the build /// public string title; /// /// Path where the build is located /// public string buildPath; } /// /// Represents the event sent at the end of the build process /// /// /// Dispatch this action when the build process ends /// public class BuildFinishAction : PublisherAction { /// /// Output directory of the build /// public string outputDir; /// /// GUID of the build /// public string buildGUID; } /// /// Represents the event sent at the end of the zipping process /// /// /// Dispatch this action when the zipping process ends /// public class ZipPathChangeAction : PublisherAction { /// /// Path of the zipped build /// public string zipPath; } /// /// Represents the event sent to start the upload process /// /// /// Dispatch this action to start the upload process /// public class UploadStartAction : PublisherAction { /// /// GUID of the build /// public string buildGUID; } /// /// Represents the event sent to query progress data about the upload process /// /// /// Dispatch this action to query progress data about the upload process /// public class UploadProgressAction : PublisherAction { /// /// The progress made until now /// public int progress; } /// /// Represents the event sent to query progress data /// /// /// Dispatch this action to query progress data /// public class QueryProgressAction : PublisherAction { /// /// A key that identifies the action /// public string key; } /// /// Represents the event sent to query progress response data /// /// /// Dispatch this action to query progress response data /// public class QueryProgressResponseAction : PublisherAction { /// /// The response /// public GetProgressResponse response; } /// /// Represents the event sent to change the title of the build /// /// /// Dispatch this action to change the title of the build /// public class TitleChangeAction : PublisherAction { /// /// The new title /// public string title; } /// /// Represents the event sent to destroy the state of the application and reset it /// /// /// Dispatch this action to destroy the state of the application and reset it /// public class DestroyAction : PublisherAction { } /// /// Represents the event sent when an error occurs /// /// /// Dispatch this action when an error occurs /// public class OnErrorAction : PublisherAction { /// /// The error message /// public string errorMsg; } /// /// Represents the event sent to stop the upload process /// /// /// Dispatch this action to stop the upload process /// public class StopUploadAction : PublisherAction { } /// /// Represents the event sent when the user is not logged in /// /// /// Dispatch this action when the user is not logged in /// public class NotLoginAction : PublisherAction { } /// /// Represents the event sent when the user logs in /// /// /// Dispatch this action when the user logs in /// public class LoginAction : PublisherAction { } /// /// Updates the state of the application when an action is dispatched /// public class PublisherReducer { /// /// Processes the state of the app according to an action /// /// old state /// dispatched action /// Returns an updated AppState public static AppState Reducer(AppState old, object action) { switch (action) { case BuildFinishAction build: return old.CopyWith( buildOutputDir: build.outputDir, buildGUID: build.buildGUID ); case ZipPathChangeAction zip: return old.CopyWith( zipPath: zip.zipPath, step: PublisherState.Zip ); case UploadStartAction upload: AnalyticsHelper.UploadStarted(); return old.CopyWith(step: PublisherState.Upload); case QueryProgressAction query: return old.CopyWith( step: PublisherState.Process, key: query.key ); case UploadProgressAction upload: PublisherWindow.FindInstance()?.OnUploadProgress(upload.progress); return old; case QueryProgressResponseAction queryResponse: PublisherState? step = null; if (queryResponse.response.progress == 100) { step = PublisherState.Idle; } PublisherWindow.FindInstance()?.OnProcessingProgress(queryResponse.response.progress); return old.CopyWith(url: queryResponse.response.url, step: step); case TitleChangeAction titleChangeAction: return old.CopyWith(title: titleChangeAction.title); case DestroyAction destroyAction: return new AppState(buildOutputDir: old.buildOutputDir, buildGUID: old.buildGUID); case OnErrorAction errorAction: return old.CopyWith(errorMsg: errorAction.errorMsg); case StopUploadAction stopUploadAction: return new AppState(buildOutputDir: old.buildOutputDir, buildGUID: old.buildGUID); case NotLoginAction login: return old.CopyWith(step: PublisherState.Login); case LoginAction login: return old.CopyWith(step: PublisherState.Idle); } return old; } } }