Skip to content

Commit

Permalink
Implemented karta notes; karta geometry; npc namegen; folder descript…
Browse files Browse the repository at this point in the history
…ions and images for styr, kortisto and evne; persist dialog state action in tale; general bugfixes
  • Loading branch information
Steffen Nörtershäuser committed Mar 25, 2018
1 parent 84bcf7c commit 5685305
Show file tree
Hide file tree
Showing 115 changed files with 30,969 additions and 81 deletions.
1 change: 1 addition & 0 deletions Controllers/Api/AikaApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ private async Task AdjustKartaMapMarkersForDeletedChapter(string projectId, int
anyChange = AdjustMapMarkerListForDeletedChapter(curMap.KirjaPageMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters) || anyChange;
anyChange = AdjustMapMarkerListForDeletedChapter(curMap.QuestMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters) || anyChange;
anyChange = AdjustMapMarkerListForDeletedChapter(curMap.MapChangeMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters) || anyChange;
anyChange = AdjustMapMarkerListForDeletedChapter(curMap.NoteMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters) || anyChange;

if(anyChange)
{
Expand Down
63 changes: 62 additions & 1 deletion Controllers/Api/FlexFieldBaseApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class FolderRequest
/// </summary>
public string Name { get; set; }

/// <summary>
/// Description
/// </summary>
public string Description { get; set; }

/// <summary>
/// Parent Folder Id
/// </summary>
Expand Down Expand Up @@ -291,7 +296,8 @@ public async Task<IActionResult> CreateFolder([FromBody]FolderRequest folder)
FlexFieldFolder newFolder = new FlexFieldFolder {
ProjectId = project.Id,
ParentFolderId = folder.ParentId,
Name = folder.Name
Name = folder.Name,
Description = folder.Description
};
newFolder = await _folderDbAccess.CreateFolder(newFolder);
await _timelineService.AddTimelineEntry(FolderCreatedEvent, folder.Name);
Expand Down Expand Up @@ -324,6 +330,8 @@ public async Task<IActionResult> DeleteFolder(string id)
await _folderDbAccess.DeleteFolder(folder);
_logger.LogInformation("Folder was deleted.");

_imageAccess.CheckAndDeleteUnusedImage(folder.ImageFile);

await _timelineService.AddTimelineEntry(FolderDeletedEvent, folder.Name);
return Ok(id);
}
Expand Down Expand Up @@ -356,6 +364,7 @@ public async Task<IActionResult> UpdateFolder(string id, [FromBody]FolderRequest
{
FlexFieldFolder loadedFolder = await _folderDbAccess.GetFolderById(id);
loadedFolder.Name = folder.Name;
loadedFolder.Description = folder.Description;

await _folderDbAccess.UpdateFolder(loadedFolder);
_logger.LogInformation("Folder was updated.");
Expand All @@ -364,6 +373,58 @@ public async Task<IActionResult> UpdateFolder(string id, [FromBody]FolderRequest
return Ok(id);
}


/// <summary>
/// Uploads an image to a flex field folder
/// </summary>
/// <param name="id">Id of the flex field folder</param>
/// <returns>Image Name</returns>
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> UploadFolderImage(string id)
{
// Validate Date
string validateResult = this.ValidateImageUploadData();
if(validateResult != null)
{
return StatusCode((int)HttpStatusCode.BadRequest, _localizer[validateResult]);
}

IFormFile uploadFile = Request.Form.Files[0];
FlexFieldFolder targetFolder = await _folderDbAccess.GetFolderById(id);
if(targetFolder == null)
{
return StatusCode((int)HttpStatusCode.BadRequest, _localizer["CouldNotUploadImage"]);
}

// Save Image
string objectImageFile = string.Empty;
try
{
using(Stream imageStream = _imageAccess.CreateFlexFieldObjectImage(uploadFile.FileName, out objectImageFile))
{
uploadFile.CopyTo(imageStream);
}

string oldImageFile = targetFolder.ImageFile;
targetFolder.ImageFile = objectImageFile;

await _folderDbAccess.UpdateFolder(targetFolder);

if(!string.IsNullOrEmpty(oldImageFile))
{
_imageAccess.CheckAndDeleteUnusedImage(oldImageFile);
}
}
catch(Exception ex)
{
_logger.LogError(ex, "Could not upload image");
return StatusCode((int)HttpStatusCode.InternalServerError, _localizer["CouldNotUploadImage"]);
}

return Ok(objectImageFile);
}


/// <summary>
/// Returns a flex field template by its id
Expand Down
7 changes: 7 additions & 0 deletions Controllers/Api/ImplementationStatusApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ public async Task<IActionResult> FlagMarkerAsImplemented(string mapId, string ma
await _markerSnapshotDbAccess.SaveQuestMarkerSnapshot(marker);
await _mapDbAccess.UpdateMap(map);
}
else if(markerType == MarkerType.Note && map.NoteMarker != null)
{
NoteMapMarker marker = map.NoteMarker.First(m => m.Id == markerId);
marker.IsImplemented = true;
await _markerSnapshotDbAccess.SaveNoteMarkerSnapshot(marker);
await _mapDbAccess.UpdateMap(map);
}

// Add Timeline entry
await _timelineService.AddTimelineEntry(TimelineEvent.ImplementedMarker, mapId, markerId, markerType.ToString(), map.Name);
Expand Down
51 changes: 51 additions & 0 deletions Controllers/Api/KartaApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public class SaveMarkerRequest
/// Map Change marker
/// </summary>
public MapChangeMapMarker MapChangeMarker { get; set; }

/// <summary>
/// Note marker
/// </summary>
public NoteMapMarker NoteMarker { get; set; }
};

/// <summary>
Expand Down Expand Up @@ -407,6 +412,11 @@ public async Task<IActionResult> UpdateMap(string id, string name)
ScaleMapMarker(curMarker, scaleX, scaleY);
}

foreach(MapMarker curMarker in map.NoteMarker)
{
ScaleMapMarker(curMarker, scaleX, scaleY);
}

try
{
await _mapDbAccess.UpdateMap(map);
Expand Down Expand Up @@ -447,6 +457,18 @@ private void ScaleMapMarker(MapMarker marker, float scaleX, float scaleY)
curCoords.X *= scaleX;
curCoords.Y *= scaleY;
}

if(marker.Geometry != null)
{
foreach(MarkerGeometry curGeom in marker.Geometry)
{
foreach(MarkerGeometryPosition curPos in curGeom.Positions)
{
curPos.X *= scaleX;
curPos.Y *= scaleY;
}
}
}
}


Expand Down Expand Up @@ -643,6 +665,29 @@ public IActionResult GetNewMapMarkerId()
map.MapChangeMarker.Add(markerRequest.MapChangeMarker);
}
}
else if(markerRequest.NoteMarker != null)
{
if(map.NoteMarker == null)
{
map.NoteMarker = new List<NoteMapMarker>();
}

markerId = markerRequest.NoteMarker.Id;
markerType = MarkerType.Note.ToString();

NoteMapMarker existingMarker = map.NoteMarker.FirstOrDefault(m => m.Id == markerRequest.NoteMarker.Id);
if(existingMarker != null)
{
CopyBaseMarkerAttributes(existingMarker, markerRequest.NoteMarker);
existingMarker.Name = markerRequest.NoteMarker.Name;
existingMarker.Description = markerRequest.NoteMarker.Description;
existingMarker.IsImplemented = false;
}
else
{
map.NoteMarker.Add(markerRequest.NoteMarker);
}
}
await _mapDbAccess.UpdateMap(map);

string localizedMarkerType = _localizer["MarkerType" + markerType].Value;
Expand Down Expand Up @@ -695,6 +740,11 @@ public IActionResult GetNewMapMarkerId()
DeleteMarkerFromList(map.MapChangeMarker, markerId);
await _markerImplementationSnapshotDbAccess.DeleteMapChangeMarkerSnapshot(markerId);
}
else if(markerType == MarkerType.Note)
{
DeleteMarkerFromList(map.NoteMarker, markerId);
await _markerImplementationSnapshotDbAccess.DeleteNoteMarkerSnapshot(markerId);
}
await _mapDbAccess.UpdateMap(map);

string localizedMarkerType = _localizer["MarkerType" + markerType.ToString()].Value;
Expand Down Expand Up @@ -729,6 +779,7 @@ private void CopyBaseMarkerAttributes(MapMarker targetMarker, MapMarker sourceMa
targetMarker.AddedInChapter = sourceMarker.AddedInChapter;
targetMarker.ChapterPixelCoords = sourceMarker.ChapterPixelCoords;
targetMarker.DeletedInChapter = sourceMarker.DeletedInChapter;
targetMarker.Geometry = sourceMarker.Geometry;
}


Expand Down
2 changes: 2 additions & 0 deletions Controllers/Api/KortistoApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ protected override async Task<KortistoNpc> RunAdditionalUpdates(KortistoNpc flex
loadedFlexFieldObject.IsPlayerNpc = flexFieldObject.IsPlayerNpc;
}

loadedFlexFieldObject.NameGenTemplate = flexFieldObject.NameGenTemplate;

if(User.IsInRole(RoleNames.Styr))
{
loadedFlexFieldObject.Inventory = flexFieldObject.Inventory;
Expand Down
10 changes: 10 additions & 0 deletions Data/FlexFieldDatabase/FlexFieldFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ public class FlexFieldFolder
/// Name of the folder
/// </summary>
public string Name { get; set; }

/// <summary>
/// Description of the folder
/// </summary>
public string Description { get; set; }

/// <summary>
/// Image File
/// </summary>
public string ImageFile { get; set; }
}
}
5 changes: 3 additions & 2 deletions Data/FlexFieldDatabase/FlexFieldFolderBaseMongoDbAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ public async Task<int> GetChildFolderCount(string folderId)
}

/// <summary>
/// Updates a folder
/// Updates a folder
/// </summary>
/// <param name="folder">Folder</param>
/// <returns>Task</returns>
public async Task UpdateFolder(FlexFieldFolder folder)
{
await _FolderCollection.UpdateOneAsync(Builders<FlexFieldFolder>.Filter.Eq(f => f.Id, folder.Id), Builders<FlexFieldFolder>.Update.Set(p => p.Name, folder.Name));
await _FolderCollection.UpdateOneAsync(Builders<FlexFieldFolder>.Filter.Eq(f => f.Id, folder.Id),
Builders<FlexFieldFolder>.Update.Set(p => p.Name, folder.Name).Set(p => p.Description, folder.Description).Set(p => p.ImageFile, folder.ImageFile));
}

/// <summary>
Expand Down
21 changes: 21 additions & 0 deletions Data/Karta/IKartaMarkerImplementationSnapshotDbAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public interface IKartaMarkerImplementationSnapshotDbAccess
/// <returns>Marker snapshot</returns>
Task<QuestMapMarker> GetQuestMarkerSnapshotById(string id);

/// <summary>
/// Returns an implementation snapshot of a Note Marker
/// </summary>
/// <param name="id">Id of the marker</param>
/// <returns>Marker snapshot</returns>
Task<NoteMapMarker> GetNoteMarkerSnapshotById(string id);


/// <summary>
/// Saves a npc marker snapshot
Expand Down Expand Up @@ -67,6 +74,13 @@ public interface IKartaMarkerImplementationSnapshotDbAccess
/// <returns>Task</returns>
Task SaveQuestMarkerSnapshot(QuestMapMarker snapshot);

/// <summary>
/// Saves a note marker snapshot
/// </summary>
/// <param name="snapshot">Snapshot to save</param>
/// <returns>Task</returns>
Task SaveNoteMarkerSnapshot(NoteMapMarker snapshot);


/// <summary>
/// Deletes a npc marker snapshot
Expand Down Expand Up @@ -95,5 +109,12 @@ public interface IKartaMarkerImplementationSnapshotDbAccess
/// <param name="id">Id of the snapshot</param>
/// <returns>Task</returns>
Task DeleteQuestMarkerSnapshot(string id);

/// <summary>
/// Deletes a note marker
/// </summary>
/// <param name="id">Id of the snapshot</param>
/// <returns>Task</returns>
Task DeleteNoteMarkerSnapshot(string id);
}
}
5 changes: 5 additions & 0 deletions Data/Karta/KartaMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public class KartaMap : IHasModifiedData
/// </summary>
public List<MapChangeMapMarker> MapChangeMarker { get; set; }

/// <summary>
/// Note Marker
/// </summary>
public List<NoteMapMarker> NoteMarker { get; set; }


/// <summary>
/// Last modify Date
Expand Down
6 changes: 6 additions & 0 deletions Data/Karta/KartaMapMongoDbAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public async Task<KartaMap> CreateMap(KartaMap map)
map.MapChangeMarker = new List<MapChangeMapMarker>();
}

if(map.NoteMarker == null)
{
map.NoteMarker = new List<NoteMapMarker>();
}

await _MapCollection.InsertOneAsync(map);

return map;
Expand Down Expand Up @@ -164,6 +169,7 @@ private async Task<List<MarkerImplementationQueryResultObject>> GetNotImplemente
result.AddRange(ExtractNotImplementedMarkers(curMap, curMap.ItemMarker, MarkerType.Item));
result.AddRange(ExtractNotImplementedMarkers(curMap, curMap.MapChangeMarker, MarkerType.MapChange));
result.AddRange(ExtractNotImplementedMarkers(curMap, curMap.QuestMarker, MarkerType.Quest));
result.AddRange(ExtractNotImplementedMarkers(curMap, curMap.NoteMarker, MarkerType.Note));
}

return result;
Expand Down
Loading

0 comments on commit 5685305

Please sign in to comment.