Added landingview promo articles
parent
e1fd118ade
commit
7dbdf8aa22
|
@ -0,0 +1,31 @@
|
|||
using Tiger.Communication.Messages.Interfaces;
|
||||
using Tiger.Communication.Messages.Outgoing.Landingview;
|
||||
using Tiger.Communication.Messages.Types;
|
||||
using Tiger.Game.LandingView;
|
||||
using Tiger.Networking.Game.Sessions;
|
||||
|
||||
namespace Tiger.Communication.Messages.Incoming.Landingview;
|
||||
|
||||
public class GetPromoArticlesMessageEvent : IMessageEvent
|
||||
{
|
||||
private readonly IGameSessionManager _gameSessionManager;
|
||||
private readonly ILandingViewManager _landingViewManager;
|
||||
|
||||
public GetPromoArticlesMessageEvent(IGameSessionManager gameSessionManager, ILandingViewManager landingViewManager)
|
||||
{
|
||||
_gameSessionManager = gameSessionManager;
|
||||
_landingViewManager = landingViewManager;
|
||||
}
|
||||
|
||||
public IncomingHeaders Header => IncomingHeaders.GetPromoArticlesEvent;
|
||||
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
||||
{
|
||||
if (gameSession.Habbo == null)
|
||||
{
|
||||
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
||||
return;
|
||||
}
|
||||
|
||||
await gameSession.SendComposerAsync(new PromoArticlesComposer(_landingViewManager.PromoArticles));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
using Tiger.Communication.Messages.Interfaces;
|
||||
using Tiger.Communication.Messages.Types;
|
||||
using Tiger.Game.LandingView;
|
||||
|
||||
namespace Tiger.Communication.Messages.Outgoing.Landingview;
|
||||
|
||||
public class PromoArticlesComposer : IMessageComposer
|
||||
{
|
||||
private readonly ICollection<PromoArticle> _promoArticles;
|
||||
|
||||
public PromoArticlesComposer(ICollection<PromoArticle> promoArticles)
|
||||
{
|
||||
_promoArticles = promoArticles;
|
||||
}
|
||||
|
||||
public OutgoingHeaders Header => OutgoingHeaders.PromoArticlesMessageComposer;
|
||||
public void Compose(ServerMessage message)
|
||||
{
|
||||
message.AppendInt32(_promoArticles.Count);
|
||||
|
||||
foreach (var promoArticle in _promoArticles)
|
||||
{
|
||||
message.AppendInt32(promoArticle.Id);
|
||||
message.AppendString(promoArticle.Title);
|
||||
message.AppendString(promoArticle.BodyText);
|
||||
message.AppendString(promoArticle.ButtonText);
|
||||
message.AppendInt32((int)promoArticle.LinkType);
|
||||
message.AppendString(promoArticle.LinkContent);
|
||||
message.AppendString(promoArticle.ImageUrl);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace Tiger.Game.LandingView;
|
||||
|
||||
public interface ILandingViewManager
|
||||
{
|
||||
ICollection<PromoArticle> PromoArticles { get; }
|
||||
Task LoadPromoArticlesAsync();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Tiger.Storage;
|
||||
|
||||
namespace Tiger.Game.LandingView;
|
||||
|
||||
public class LandingViewManager : ILandingViewManager
|
||||
{
|
||||
private readonly IRepository<PromoArticle> _promoArticleRepository;
|
||||
private readonly ILogger<ILandingViewManager> _logger;
|
||||
|
||||
public LandingViewManager(IRepository<PromoArticle> promoArticleRepository, ILogger<ILandingViewManager> logger)
|
||||
{
|
||||
_promoArticleRepository = promoArticleRepository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public ICollection<PromoArticle> PromoArticles { get; private set; } = new List<PromoArticle>();
|
||||
|
||||
public async Task LoadPromoArticlesAsync()
|
||||
{
|
||||
PromoArticles = (await _promoArticleRepository.FindByAsync()).ToList();
|
||||
|
||||
_logger.LogInformation("Loaded {Count} promo articles", PromoArticles.Count);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
namespace Tiger.Game.LandingView;
|
||||
|
||||
public class PromoArticle
|
||||
{
|
||||
public virtual int Id { get; set; }
|
||||
public virtual string Title { get; set; } = null!;
|
||||
public virtual string BodyText { get; set; } = null!;
|
||||
public virtual string ButtonText { get; set; } = null!;
|
||||
public virtual PromoArticleLinkType LinkType { get; set; }
|
||||
public virtual string LinkContent { get; set; } = null!;
|
||||
public virtual string ImageUrl { get; set; } = null!;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
namespace Tiger.Game.LandingView;
|
||||
|
||||
public enum PromoArticleLinkType
|
||||
{
|
||||
LinkTypeUrl = 0,
|
||||
LinkTypeInternal = 1,
|
||||
LinkTypeNoLink = 2
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using FluentNHibernate.Mapping;
|
||||
|
||||
namespace Tiger.Game.LandingView;
|
||||
|
||||
public class PromoArticleMap : ClassMap<PromoArticle>
|
||||
{
|
||||
public PromoArticleMap()
|
||||
{
|
||||
Table("landing_promo_articles");
|
||||
Id(pa => pa.Id).Column("id").GeneratedBy.Identity();
|
||||
Map(pa => pa.Title).Column("title").Not.Nullable();
|
||||
Map(pa => pa.BodyText).Column("body_text").Not.Nullable();
|
||||
Map(pa => pa.ButtonText).Column("button_text").Not.Nullable();
|
||||
Map(pa => pa.LinkType).CustomType<int>().Column("link_type").Not.Nullable();
|
||||
Map(pa => pa.LinkContent).Column("link_content").Not.Nullable();
|
||||
Map(pa => pa.ImageUrl).Column("image_url").Not.Nullable();
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ using Tiger.Communication.Messages;
|
|||
using Tiger.Game.Catalogue;
|
||||
using Tiger.Game.Figuredata;
|
||||
using Tiger.Game.Habbos;
|
||||
using Tiger.Game.LandingView;
|
||||
using Tiger.Game.Settings;
|
||||
using Tiger.Networking.Game;
|
||||
using Tiger.Networking.Game.Sessions;
|
||||
|
@ -37,6 +38,7 @@ collection.AddScoped(typeof(IRepository<>), typeof(Repository<>));
|
|||
collection.AddSingleton<ISettingManager, SettingManager>();
|
||||
collection.AddSingleton<ICatalogueManager, CatalogueManager>();
|
||||
collection.AddSingleton<IFigureDataManager, FiguredataManager>();
|
||||
collection.AddSingleton<ILandingViewManager, LandingViewManager>();
|
||||
collection.RegisterMessageEvents();
|
||||
|
||||
var provider = collection.BuildServiceProvider();
|
||||
|
@ -44,6 +46,7 @@ var provider = collection.BuildServiceProvider();
|
|||
await provider.GetRequiredService<ISettingManager>().ReloadSettingsAsync();
|
||||
await provider.GetRequiredService<ICatalogueManager>().LoadPagesAsync();
|
||||
provider.GetRequiredService<IFigureDataManager>();
|
||||
await provider.GetRequiredService<ILandingViewManager>().LoadPromoArticlesAsync();
|
||||
|
||||
provider.GetRequiredService<IWebSocketServer>().Start($"http://{configuration["Network:Game:Ip"]}:{configuration["Network:Game:Port"]}/");
|
||||
|
||||
|
|
Loading…
Reference in New Issue