Skip to content

Commit

Permalink
Release 0.17 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
kekchpek authored Dec 2, 2024
2 parents 0d97a13 + 98d3e28 commit 14ab6da
Show file tree
Hide file tree
Showing 21 changed files with 219 additions and 43 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- 'master'
- 'develop'
- 'release/*'
- 'feature/*'
- 'fix/*'

jobs:
build:
Expand Down Expand Up @@ -36,6 +38,15 @@ jobs:
then
git remote set-url origin https://$RUNNER_USERNAME:$PAT_TOKEN@${REPO_URL:6}
CURRENT_TAG_VERSION=$(python3 getVersion.py ./VERSION $UMVVM_BUILD_DATA_PATH/buildVersionV1.txt)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ $CURRENT_BRANCH == feature* || $CURRENT_BRANCH == fix* ]];
then
CURRENT_TAG_VERSION=$CURRENT_TAG_VERSION-raw
fi
if [[ $CURRENT_BRANCH == develop ]];
then
CURRENT_TAG_VERSION=$CURRENT_TAG_VERSION-dev
fi
git tag $CURRENT_TAG_VERSION
git push origin --tags
fi
Expand Down
29 changes: 18 additions & 11 deletions MvvmUnityProj/CCG/Assets/Code/Core/CoreInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CCG.Core.Camera;
using CCG.Core.CustomViewManager;
using CCG.Core.Installers;
using CCG.Core.Screen;
using CCG.Models.Hand.Model;
Expand All @@ -21,7 +22,9 @@
using SurvivedWarrior.MVVM.Models.Time;
using UnityEngine;
using UnityMVVM.DI;
using UnityMVVM.ViewManager;
using UnityMVVM.ViewModelCore;
using UnityMVVM.ViewModelCore.PrefabsProvider;
using Zenject;

namespace CCG.Core
Expand All @@ -30,26 +33,30 @@ public class CoreInstaller : Installer
{
public override void InstallBindings()
{
Container.InstallPoolableView<MainScreenView, IMainScreenViewModel, MainScreenViewModel>(ViewNames.MainScreen,
() => Resources.Load<GameObject>("Prefabs/Views/MainScreenView"));
Container.InstallView<MainScreen3dView, IViewModel, ViewModel>(ViewNames.MainScreen3d,
() => Resources.Load<GameObject>("Prefabs/Views/MainScreen3dView"));

Container.Decorate<IViewManager>().With<LogViewManagerDecorator>();

Container.Bind<IViewsPrefabsProvider>().To<ResourcesPrefabProvider>().AsSingle();
Container.ProvideAccessForViewModelLayer<IViewsPrefabsProvider>();

Container.InstallPoolableView<MainScreenView, IMainScreenViewModel, MainScreenViewModel>(ViewNames.MainScreen);
Container.InstallView<MainScreen3dView, IViewModel, ViewModel>(ViewNames.MainScreen3d);
Container.InstallView<StatsChangerView, IStatsChangerViewModel, StatsChangerViewModel>();
Container.InstallView<PlayButtonView, IPlayButtonViewModel, PlayButtonViewModel>();
Container.InstallView<HandControllerView, IHandControllerViewModel, HandControllerViewModel>(ViewNames.HandController,
() => Resources.Load<GameObject>("Prefabs/Views/HandController"));
_ => Resources.Load<GameObject>("Prefabs/Views/HandController"));
Container.InstallPoolableView<CardView, ICardViewModel, CardViewModel>(ViewNames.Card,
() => Resources.Load<GameObject>("Prefabs/Views/CardView"));
_ => Resources.Load<GameObject>("Prefabs/Views/CardView"));
Container.InstallView<MainMenuView3d, IMainMenuViewModel3d, MainMenuViewModel3d>(ViewNames.MainMenu3d,
() => Resources.Load<GameObject>("Prefabs/Views/MainMenu3d/MainMenu3dScene"));
_ => Resources.Load<GameObject>("Prefabs/Views/MainMenu3d/MainMenu3dScene"));
Container.InstallView<MainMenuViewUi, IMainMenuViewModelUi, MainMenuViewModelUi>(ViewNames.MainMenuUi,
() => Resources.Load<GameObject>("Prefabs/Views/MainMenuUi/MainMenuUi"));
_ => Resources.Load<GameObject>("Prefabs/Views/MainMenuUi/MainMenuUi"));
Container.InstallView<LoadingPopupView, IViewModel, ViewModel>(ViewNames.LoadingPopup,
() => Resources.Load<GameObject>("Prefabs/Views/LoadingPopup"));
_ => Resources.Load<GameObject>("Prefabs/Views/LoadingPopup"));
Container.InstallView<CoolPopupView, ICoolPopupViewModel, CoolPopupViewModel>(ViewNames.CoolPopup,
() => Resources.Load<GameObject>("Prefabs/Views/CoolPopup/CoolPopup"));
_ => Resources.Load<GameObject>("Prefabs/Views/CoolPopup/CoolPopup"));
Container.InstallView<CoolPopupView, ICoolPopupViewModel, CoolPopupViewModel>(ViewNames.SameCoolPopupButWithOtherName,
() => Resources.Load<GameObject>("Prefabs/Views/CoolPopup/CoolPopup"));
_ => Resources.Load<GameObject>("Prefabs/Views/CoolPopup/CoolPopup"));
Container.InstallView<TimeCounterView, ITimeCounterViewModel, TimeCounterViewModel>();

Container.Install<ImageSystemInstaller>();
Expand Down
3 changes: 3 additions & 0 deletions MvvmUnityProj/CCG/Assets/Code/Core/CustomViewManager.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using AsyncReactAwait.Bindable;
using AsyncReactAwait.Promises;
using UnityEngine;
using UnityMVVM.ViewManager;
using UnityMVVM.ViewManager.ViewLayer;
using UnityMVVM.ViewModelCore;

namespace CCG.Core.CustomViewManager
{
public class LogViewManagerDecorator : IViewManager
{

public event Action<(string layerId, string viewName, IPayload viewPayload)> ViewOpened
{
add => _viewManager.ViewOpened += value;
remove => _viewManager.ViewOpened -= value;
}

public event Action<(string layerId, string viewName)> ViewClosedImplicitly
{
add => _viewManager.ViewClosedImplicitly += value;
remove => _viewManager.ViewClosedImplicitly -= value;
}

private readonly IViewManager _viewManager;

public IBindable<string> HighestBusyLayer => _viewManager.HighestBusyLayer;

public LogViewManagerDecorator(IViewManager viewManager)
{
_viewManager = viewManager;
}

public IReadOnlyList<string> GetLayerIds() => _viewManager.GetLayerIds();

public IViewModel Create(IViewModel parent, string viewName, Transform container, IPayload payload = null)
{
Debug.Log("View was created!");
return _viewManager.Create(parent, viewName, container, payload);
}

public IPromise<IViewModel> Open(string viewLayerId, string viewName, IPayload payload = null)
{
Debug.Log("View was opened!");
return _viewManager.Open(viewLayerId, viewName, payload);
}

public IPromise OpenExact(string viewLayerId, string viewName, IPayload payload = null)
{
Debug.Log("View was opened on exact layer!");
return _viewManager.OpenExact(viewLayerId, viewName, payload);
}

public IPromise CloseExact(string viewLayerId)
{
Debug.Log("View was closed on exact layer!");
return _viewManager.CloseExact(viewLayerId);
}

public IPromise Close(string viewLayerId)
{
Debug.Log("View was closed!");
return _viewManager.Close(viewLayerId);
}

public string GetViewName(string viewLayerId)
{
Debug.Log("View name was got!");
return _viewManager.GetViewName(viewLayerId);
}

public IViewLayer GetLayer(string viewLayerId)
{
Debug.Log("Layer was got!");
return _viewManager.GetLayer(viewLayerId);
}

public IViewModel GetView(string viewLayerId)
{
Debug.Log("View was got!");
return _viewManager.GetView(viewLayerId);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions MvvmUnityProj/CCG/Assets/Code/Core/GameInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEngine;
using UnityMVVM.DI;
using UnityMVVM.DI.Config;
using Zenject;

namespace CCG.Core
Expand Down
13 changes: 13 additions & 0 deletions MvvmUnityProj/CCG/Assets/Code/Core/ResourcesPrefabProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using UnityEngine;
using UnityMVVM.ViewModelCore.PrefabsProvider;

namespace CCG.Core
{
public class ResourcesPrefabProvider : IViewsPrefabsProvider
{
public GameObject GetViewPrefab(string viewName)
{
return Resources.Load<GameObject>($"Prefabs/Views/{viewName}View");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified MvvmUnityProj/CCG/Assets/Packages/com.kekchpek.umvvm/UnityMVVM.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.kekchpek.umvvm",
"displayName": "UnityMvvm",
"version": "0.16.1",
"version": "0.17.0",
"description": "The MVVM pattern core implemented for Unity3d",
"unity": "2022.3",
"documentationUrl": "https://github.com/kekchpek/UnityMVVM",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void InstallBindings()
},
new MvvmContainerConfiguration
{
ViewFactory = new TestViewFactory()
viewFactory = new TestViewFactory()
});
Container.Install<CoreInstaller>();

Expand Down
Binary file modified MvvmUnityProj/QuickStartUnityMVVM/Assets/Libs/UnityMVVM.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.16.0
0.17.0
2 changes: 1 addition & 1 deletion src/UnityMVVM/DI/Config/MvvmContainerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public struct MvvmContainerConfiguration
/// <summary>
/// The view factory to use for views creation and initialization.
/// </summary>
public IViewFactory? ViewFactory;
public IViewFactory? viewFactory;
}
}
42 changes: 23 additions & 19 deletions src/UnityMVVM/DI/DiContainerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using UnityMVVM.DI.Environment;
using UnityMVVM.DI.Mapper;
using UnityMVVM.Pool;
using UnityMVVM.ViewModelCore.PrefabsProvider;

// ReSharper disable MemberCanBePrivate.Global

Expand Down Expand Up @@ -73,13 +74,13 @@ public static void UseAsMvvmContainer(
container.Bind<IViewsModelsContainerAdapter>().FromInstance(viewModelsContainerAdapter);
container.FastBind<IViewManager, ViewManagerImpl>();

if (config.ViewFactory == null)
if (config.viewFactory == null)
{
viewModelsContainer.Bind<IViewFactory>().To<ViewFactory>().AsSingle();
}
else
{
viewModelsContainer.Bind<IViewFactory>().FromInstance(config.ViewFactory);
viewModelsContainer.Bind<IViewFactory>().FromInstance(config.viewFactory);
}

viewModelsContainer.Bind<IViewToViewModelMapper>().FromInstance(mapper);
Expand All @@ -100,47 +101,49 @@ public static void InstallView<TView, TViewModel, TViewModelImpl>(this DiContain
where TViewModel : class, IViewModel
where TViewModelImpl : class, TViewModel
{
container.InstallView<TView, TViewModel, TViewModelImpl>(viewName, () => viewPrefab);
container.InstallView<TView, TViewModel, TViewModelImpl>(viewName, _ => viewPrefab);
}

/// <summary>
/// Installs <see cref="IViewModelsFactory"/> for specified View-ViewModel pair.
/// </summary>
/// <param name="container">MVVM container to configure.</param>
/// <param name="viewName">View identificator for opening.</param>
/// <param name="viewPrefabGetter">The method to obtain view prefab. View should contains <typeparamref name="TView"/> component inside.</param>
/// <param name="viewPrefabGetter">
/// The method to obtain view prefab by its bound name. View should contains <typeparamref name="TView"/> component inside.
/// There should be default viewPrefabProvider specified in config on UseAsMvvmContainer call if this
/// parameter is set to null.
/// </param>
/// <typeparam name="TView">The type of a view</typeparam>
/// <typeparam name="TViewModel">The type of a view model.</typeparam>
/// <typeparam name="TViewModelImpl">The type, that implements a view model.</typeparam>
public static void InstallView<TView, TViewModel, TViewModelImpl>(this DiContainer container, string viewName, Func<GameObject> viewPrefabGetter)
public static void InstallView<TView, TViewModel, TViewModelImpl>(this DiContainer container, string viewName, Func<string, GameObject>? viewPrefabGetter = null)
where TView : ViewBehaviour<TViewModel>
where TViewModel : class, IViewModel
where TViewModelImpl : class, TViewModel
{
if (viewPrefabGetter == null) throw new ArgumentNullException(nameof(viewPrefabGetter));
InstallViewInternal<TView, TViewModel, TViewModelImpl>(container, viewName, viewPrefabGetter, null);
InstallViewInternal<TView, TViewModel, TViewModelImpl>(container, viewName, null, viewPrefabGetter);
}

/// <inheritdoc cref="InstallView{TView,TViewModel,TViewModelImpl}(Zenject.DiContainer,string,Func{UnityEngine.GameObject})"/>
/// <inheritdoc cref="InstallView{TView,TViewModel,TViewModelImpl}(Zenject.DiContainer,string,Func{string, UnityEngine.GameObject})"/>
/// <param name="viewPool">The pool for views. Uses default <see cref="ViewPool{T}"/> object if null specified.</param>
public static void InstallPoolableView
<TView, TViewModel, TViewModelImpl>
#pragma warning disable CS1573
(this DiContainer container,
string viewName,
Func<GameObject> viewPrefabGetter,
Func<string, GameObject>? viewPrefabGetter = null,
#pragma warning restore CS1573
IViewPool? viewPool = null)
where TView : ViewBehaviour<TViewModel>, IPoolableView
where TViewModel : class, IViewModel
where TViewModelImpl : class, TViewModel
{
if (viewPrefabGetter == null) throw new ArgumentNullException(nameof(viewPrefabGetter));
InstallViewInternal<TView, TViewModel, TViewModelImpl>(
container,
viewName,
viewPrefabGetter,
viewPool ?? new ViewPool<TView>());
viewPool ?? new ViewPool<TView>(),
viewPrefabGetter);
}

/// <inheritdoc cref="InstallView{TView,TViewModel,TViewModelImpl}(Zenject.DiContainer,string,UnityEngine.GameObject)"/>
Expand All @@ -160,31 +163,32 @@ public static void InstallPoolableView
InstallViewInternal<TView, TViewModel, TViewModelImpl>(
container,
viewName,
() => viewPrefab,
viewPool ?? new ViewPool<TView>());
viewPool ?? new ViewPool<TView>(),
_ => viewPrefab);
}

private static void InstallViewInternal<TView, TViewModel, TViewModelImpl>(
DiContainer container, string viewName,
Func<GameObject> viewPrefabGetter, IViewPool? viewPool)
DiContainer container, string viewName, IViewPool? viewPool,
Func<string, GameObject>? viewPrefabGetter = null)
where TView : ViewBehaviour<TViewModel>
where TViewModel : class, IViewModel
where TViewModelImpl : class, TViewModel
{
if (!ContainerEnvironments.TryGetValue(container, out var env))
{
throw new InvalidOperationException($"Provided container does not contain container for the view-model layer. " +
$"Use {nameof(UseAsMvvmContainer)} method to configure container.");
$"Use {nameof(UseAsMvvmContainer)} method to configure the container.");
}
var viewModelsContainer = env.ViewsModelsContainerAdapter;
var extraArgs = new List<TypeValuePair>();
viewModelsContainer.Container
.Bind<IViewModelsFactory>()
.WithId(viewName)
.To<ViewModelsFactory<TView>>()
.AsTransient()
.WithArgumentsExplicit(new []
{
new TypeValuePair(typeof(Func<GameObject>), viewPrefabGetter),
new TypeValuePair(typeof(Func<string, GameObject>), viewPrefabGetter),
new TypeValuePair(typeof(IViewPool), viewPool),
});
env.Mapper.Map<TView, TViewModelImpl>();
Expand Down Expand Up @@ -358,7 +362,7 @@ public static void FastBind<TImpl>(this DiContainer container, IReadOnlyCollecti
commonAccessInterfaces = modelAccessInterfaces;
}
env.ViewsModelsContainerAdapter.Container.Bind(commonAccessInterfaces)
.FromMethod<TImpl>(_ => (TImpl)container.Resolve(modelAccessInterfaces.First())).AsSingle();
.FromMethodUntyped(_ => container.Resolve(modelAccessInterfaces.First())).AsSingle();
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/UnityMVVM/DI/Environment/ContainerEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using UnityEngine;
using UnityMVVM.DI.Mapper;

namespace UnityMVVM.DI.Environment
Expand Down
2 changes: 2 additions & 0 deletions src/UnityMVVM/DI/Environment/IContainerEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using UnityEngine;
using UnityMVVM.DI.Mapper;

namespace UnityMVVM.DI.Environment
Expand Down
4 changes: 2 additions & 2 deletions src/UnityMVVM/ViewManager/ViewManagerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public IReadOnlyList<string> GetLayerIds()

public IViewModel Create(IViewModel parent, string viewName, Transform container, IPayload? payload = null)
{
return _viewsContainer.ResolveViewFactory(viewName).Create(parent.Layer, parent, container, payload);
return _viewsContainer.ResolveViewFactory(viewName).Create(parent.Layer, viewName, parent, container, payload);
}

/// <inheritdoc cref="IViewManager.Open(string, string, IPayload)"/>
Expand Down Expand Up @@ -188,7 +188,7 @@ public IViewModel Create(IViewModel parent, string viewName, Transform container

private IViewModel CreateViewOnLayer(string viewName, IViewLayer layer, IPayload? payload)
{
var viewModel = _viewsContainer.ResolveViewFactory(viewName).Create(layer, null, layer.Container, payload);
var viewModel = _viewsContainer.ResolveViewFactory(viewName).Create(layer, viewName, null, layer.Container, payload);
_createdViewsNames.Add(viewModel, viewName);
viewModel.Destroyed += OnViewModelDestroyed;
layer.Set(viewModel);
Expand Down
Loading

0 comments on commit 14ab6da

Please sign in to comment.