migrating session/map it to guid.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-16 16:51:07 +01:00
parent 155cb4ea9a
commit 195533bce0
17 changed files with 672 additions and 82 deletions

View File

@ -7,7 +7,7 @@ namespace Sledgemapper.Api.Commands
{
public double Timestamp { get; private set; }
public string SessionName { get; private set; }
public string Campaign { get; private set; }
public Guid Campaign { get; private set; }
public string UserId { get; private set; }
public BaseCommand(string sessionName, string userId)
@ -18,6 +18,14 @@ namespace Sledgemapper.Api.Commands
}
public BaseCommand(string campaign, string sessionName, string userId)
{
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
SessionName = sessionName;
Campaign = new Guid(campaign);
UserId = userId;
}
public BaseCommand(Guid campaign, string sessionName, string userId)
{
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
SessionName = sessionName;

View File

@ -0,0 +1,19 @@
using System;
using MediatR;
namespace Sledgemapper.Api.Commands
{
public class NewCampaignCommand : IRequest<bool>
{
public double Timestamp { get; private set; }
public string CampaignName { get; private set; }
public string UserId { get; private set; }
public NewCampaignCommand(string campaingName, string userId)
{
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
CampaignName = campaingName;
UserId = userId;
}
}
}

View File

@ -1,4 +1,5 @@
using Sledgemapper.Shared.Entities;
using System;
namespace Sledgemapper.Api.Commands
{
@ -6,7 +7,7 @@ namespace Sledgemapper.Api.Commands
{
public Overlay Overlay { get; private set; }
public NewOverlayCommand(string campaignId, string mapId, Overlay overlay, string userId) : base(campaignId, mapId, userId)
public NewOverlayCommand(Guid campaignId, string mapId, Overlay overlay, string userId) : base(campaignId, mapId, userId)
{
Overlay = overlay;
}

View File

@ -1,6 +1,3 @@
using System;
using MediatR;
namespace Sledgemapper.Api.Commands
{
public class NewSessionCommand : BaseCommand<bool>
@ -10,17 +7,4 @@ namespace Sledgemapper.Api.Commands
}
}
public class NewCampaignCommand : IRequest<bool>
{
public double Timestamp { get; private set; }
public string CampaignName { get; private set; }
public string UserId { get; private set; }
public NewCampaignCommand(string campaingName, string userId)
{
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
CampaignName = campaingName;
UserId = userId;
}
}
}

View File

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Sledgemapper.Api.Commands;
using Sledgemapper.Shared.Entities;
using System;
using System.Linq;
using System.Threading.Tasks;
@ -38,7 +39,7 @@ namespace Sledgemapper.Api.Controllers
}
[HttpPost("overlay")]
public async Task Post(string campaign, string mapName, [FromBody] Overlay overlay)
public async Task Post(Guid campaign, string mapName, [FromBody] Overlay overlay)
{
await _mediator.Send(new NewOverlayCommand(campaign, mapName, overlay, UserId));
}

View File

@ -1,3 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models
@ -12,7 +13,7 @@ namespace Sledgemapper.Api.Models
public string UserId{get;set;}
[Required]
public int SessionId { get; set; }
public Guid SessionId { get; set; }
[Required]
[MaxLength(1)]

View File

@ -8,7 +8,7 @@ namespace Sledgemapper.Api.Models
public class Session
{
[Key]
public int SessionId { get; set; }
public Guid SessionId { get; set; }
[Required]
public Guid CampaignId { get; set; }

View File

@ -1,3 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models
@ -8,7 +9,7 @@ namespace Sledgemapper.Api.Models
public int SessionUserId { get; set; }
[Required]
public int SessionId { get; set; }
public Guid SessionId { get; set; }
[Required]
public int UserId { get; set; }

View File

@ -1,3 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Sledgemapper.Api.Models
@ -9,8 +10,7 @@ namespace Sledgemapper.Api.Models
public int SnapshotId { get; set; }
[Required]
public int SessionId { get; set; }
public Guid SessionId { get; set; }
[Required]
public string Object { get; set; }

View File

@ -25,16 +25,17 @@ namespace Sledgemapper.Api.Handlers
var user = await _dbcontext.Users.FindAsync(command.UserId);
_dbcontext.Attach(user);
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == new Guid(command.Campaign) && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.Campaign && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
var maps = campaign.Maps.Any(s => s.SessionId == new Guid(command.SessionName));
var maps = campaign.Maps.Any(s => s.SessionId == int.Parse(command.SessionName));
if (!maps)
{
throw new Exception("Unauthorized");
}
var jsonString = JsonSerializer.Serialize(command.Overlay);
var session = _dbcontext.Sessions.First(m => m.SessionId == int.Parse(command.SessionName));
var session = _dbcontext.Sessions.First(m => m.SessionId == new Guid(command.SessionName));
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "N",

View File

@ -21,7 +21,7 @@ namespace Sledgemapper.Api.Handlers
public async Task<bool> Handle(NewSessionCommand notification, CancellationToken cancellationToken)
{
var campaign = _dbcontext.Campaigns.First(c => c.CampaignName == notification.Campaign && c.OwnerId == notification.UserId.ToString());
var campaign = _dbcontext.Campaigns.First(c => c.CampaignId == notification.Campaign && c.OwnerId == notification.UserId.ToString());
_dbcontext.Sessions.Add(new Session
{

View File

@ -126,7 +126,16 @@ namespace Sledgemapper.Api.Hubs
}
}
public async Task UpdatePosition(string sessionName, int sessionId, Tile tile)
//public async Task UpdatePosition(string sessionName, int sessionId, Tile tile)
//{
// //var userId = int.Parse(Context.User.Identity.Name);
// //var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == sessionId).OrderBy(m => m.UserId).ToList();
// //var user = _dbContext.Users.First(u => u.Id == Context.User.Identity.Name);
// //var player = new Player { UserId = userId, Initials = user.Initials, Position = tile, Color = UserColors[userId] };
// //await Clients.Group(sessionName).PlayerUpdate(player);
//}
public async Task UpdatePosition(string sessionName, Guid sessionId, Tile tile)
{
var userId = int.Parse(Context.User.Identity.Name);
var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == sessionId).OrderBy(m => m.UserId).ToList();

View File

@ -0,0 +1,508 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Sledgemapper.Api.Infrastructure.Data;
namespace Sledgemapper.Api.Migrations
{
[DbContext(typeof(SledgemapperDbContext))]
[Migration("20210916154553_SessionIdToGuid")]
partial class SessionIdToGuid
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.6");
modelBuilder.Entity("CampaignUser", b =>
{
b.Property<Guid>("CampaignsCampaignId")
.HasColumnType("TEXT");
b.Property<string>("InvitedUsersId")
.HasColumnType("TEXT");
b.HasKey("CampaignsCampaignId", "InvitedUsersId");
b.HasIndex("InvitedUsersId");
b.ToTable("CampaignUser");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("AccessFailedCount")
.HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("SecurityStamp")
.HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Campaign", b =>
{
b.Property<Guid>("CampaignId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CampaignName")
.HasColumnType("TEXT");
b.Property<string>("OwnerId")
.HasColumnType("TEXT");
b.HasKey("CampaignId");
b.HasIndex("OwnerId");
b.HasIndex("CampaignName", "OwnerId")
.IsUnique();
b.ToTable("Campaigns");
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Map", b =>
{
b.Property<int>("MapId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CampaignId")
.HasColumnType("INTEGER");
b.Property<string>("MapName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("MapId");
b.ToTable("Maps");
});
modelBuilder.Entity("Sledgemapper.Api.Models.MapLog", b =>
{
b.Property<int>("MapLogId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Object")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Operation")
.IsRequired()
.HasMaxLength(1)
.HasColumnType("TEXT");
b.Property<Guid>("SessionId")
.HasColumnType("TEXT");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("MapLogId");
b.ToTable("MapLogs");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Session", b =>
{
b.Property<Guid>("SessionId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("CampaignId")
.HasColumnType("TEXT");
b.Property<string>("OwnerUserId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SessionName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("SessionId");
b.HasIndex("CampaignId", "SessionName")
.IsUnique();
b.ToTable("Sessions");
});
modelBuilder.Entity("Sledgemapper.Api.Models.SessionUser", b =>
{
b.Property<int>("SessionUserId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<Guid>("SessionId")
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("SessionUserId");
b.ToTable("SessionUsers");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Snapshot", b =>
{
b.Property<int>("SnapshotId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Object")
.IsRequired()
.HasColumnType("TEXT");
b.Property<Guid>("SessionId")
.HasColumnType("TEXT");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
b.HasKey("SnapshotId");
b.ToTable("Snapshots");
});
modelBuilder.Entity("Sledgemapper.Api.Models.UserConnection", b =>
{
b.Property<int>("UserConnectionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ConnectionId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("UserConnectionId");
b.ToTable("UserConnections");
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("Initials")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<byte[]>("PasswordSalt")
.HasColumnType("BLOB");
b.ToTable("Users");
});
modelBuilder.Entity("CampaignUser", b =>
{
b.HasOne("Sledgemapper.Api.Core.Entities.Campaign", null)
.WithMany()
.HasForeignKey("CampaignsCampaignId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Sledgemapper.Entities.User", null)
.WithMany()
.HasForeignKey("InvitedUsersId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Campaign", b =>
{
b.HasOne("Sledgemapper.Entities.User", "Owner")
.WithMany()
.HasForeignKey("OwnerId");
b.Navigation("Owner");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Session", b =>
{
b.HasOne("Sledgemapper.Api.Core.Entities.Campaign", null)
.WithMany("Maps")
.HasForeignKey("CampaignId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithOne()
.HasForeignKey("Sledgemapper.Entities.User", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Campaign", b =>
{
b.Navigation("Maps");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,80 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Sledgemapper.Api.Migrations
{
public partial class SessionIdToGuid : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<Guid>(
name: "SessionId",
table: "Snapshots",
type: "TEXT",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER");
migrationBuilder.AlterColumn<Guid>(
name: "SessionId",
table: "SessionUsers",
type: "TEXT",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER");
migrationBuilder.AlterColumn<Guid>(
name: "SessionId",
table: "Sessions",
type: "TEXT",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER")
.OldAnnotation("Sqlite:Autoincrement", true);
migrationBuilder.AlterColumn<Guid>(
name: "SessionId",
table: "MapLogs",
type: "TEXT",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "SessionId",
table: "Snapshots",
type: "INTEGER",
nullable: false,
oldClrType: typeof(Guid),
oldType: "TEXT");
migrationBuilder.AlterColumn<int>(
name: "SessionId",
table: "SessionUsers",
type: "INTEGER",
nullable: false,
oldClrType: typeof(Guid),
oldType: "TEXT");
migrationBuilder.AlterColumn<int>(
name: "SessionId",
table: "Sessions",
type: "INTEGER",
nullable: false,
oldClrType: typeof(Guid),
oldType: "TEXT")
.Annotation("Sqlite:Autoincrement", true);
migrationBuilder.AlterColumn<int>(
name: "SessionId",
table: "MapLogs",
type: "INTEGER",
nullable: false,
oldClrType: typeof(Guid),
oldType: "TEXT");
}
}
}

View File

@ -283,8 +283,8 @@ namespace Sledgemapper.Api.Migrations
.HasMaxLength(1)
.HasColumnType("TEXT");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<Guid>("SessionId")
.HasColumnType("TEXT");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
@ -305,9 +305,9 @@ namespace Sledgemapper.Api.Migrations
modelBuilder.Entity("Sledgemapper.Api.Models.Session", b =>
{
b.Property<int>("SessionId")
b.Property<Guid>("SessionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
.HasColumnType("TEXT");
b.Property<Guid>("CampaignId")
.HasColumnType("TEXT");
@ -334,8 +334,8 @@ namespace Sledgemapper.Api.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<Guid>("SessionId")
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
@ -355,8 +355,8 @@ namespace Sledgemapper.Api.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<Guid>("SessionId")
.HasColumnType("TEXT");
b.Property<double>("Timestamp")
.HasColumnType("REAL");

View File

@ -48,7 +48,7 @@ public class Map:Session
public ConcurrentDictionary<Guid, Ping> Pings { get; set; }
public List<string> Colors { get; set; }
public string SessionName { get; set; }
public int SessionId { get; set; }
public Guid SessionId { get; set; }
public ConcurrentDictionary<string, Line> Lines { get; set; }
public ConcurrentDictionary<string, Room> Rooms { get; set; }

View File

@ -8,6 +8,26 @@ namespace Sledgemapper
{
private static readonly State instance = new State();
public Tile SelectedTile { get; set; }
public Tile HoveredTile { get; set; }
public Wall SelectedWall { get; set; }
public Overlay SelectedOverlay { get; set; }
public SnapPoint SelectedSnapPoint { get; set; }
public Note SelectedNote { get; set; }
public int TileSize { get; set; }
public string CurrentTileId { get; set; }
public string CurrentWallId { get; set; }
public string CurrentOverlayId { get; set; }
public SnapPoint LineStart { get; internal set; }
public float LineWidth { get; internal set; }
public Vector3 ViewportCenter { get; set; }
public InsertMode InsertMode { get; set; }
public bool ShowCellNumbers { get; set; }
public string CampaignName { get; set; }
public Guid CampaignId { get; internal set; }
public string MapName { get; internal set; }
public int MapId { get; internal set; }
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static State()
@ -37,47 +57,6 @@ namespace Sledgemapper
}
}
public Tile SelectedTile { get; set; }
public Tile HoveredTile { get; set; }
public Wall SelectedWall { get; set; }
public Overlay SelectedOverlay { get; set; }
public SnapPoint SelectedSnapPoint { get; set; }
public Note SelectedNote { get; set; }
public int TileSize { get; set; }
public string CurrentTileId { get; set; }
public string CurrentWallId { get; set; }
public string CurrentOverlayId { get; set; }
public SnapPoint LineStart { get; internal set; }
public float LineWidth { get; internal set; }
public InsertMode InsertMode;
public string CampaignName { get; set; }
public bool ShowCellNumbers { get; set; }
public Vector3 ViewportCenter { get; set; }
public string MapName { get; internal set; }
public Guid CampaignId { get; internal set; }
public int MapId { get; internal set; }
//public State()
//{
// CurrentTileId = "";
// CurrentWallId = "";
// CurrentOverlayId = "";
// SelectedTile = new() { X = 1, Y = 1 };
// HoveredTile = new() { X = 1, Y = 1 };
// SelectedWall = new() { X = 1, Y = 1 };
// SelectedOverlay = new() { X = 1, Y = 1 };
// SelectedNote = new() { X = 1, Y = 1 };
// TileSize = 30;
// LineWidth=1;
// ViewportCenter = new(0, 0, 0);
//}
public void SelectClosestWall(Point mousePosition)
{
var topLeft = new Point(HoveredTile.X * TileSize, HoveredTile.Y * TileSize);
@ -117,7 +96,6 @@ namespace Sledgemapper
return ((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y)) < d * d;
}
public void SelectClosestSnapPoint(Point mousePosition)
{
var distance = TileSize / 4;
@ -158,9 +136,8 @@ namespace Sledgemapper
{
SelectedSnapPoint = new SnapPoint { X = HoveredTile.X, Y = HoveredTile.Y+1, Index = 2 };
}
}
public void SelectOverlay(Point mousePosition)
{
SelectedOverlay.X = HoveredTile.X;