mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-06-04 15:12:28 +00:00
Levels save into database
This commit is contained in:
parent
15f974fba1
commit
e554ee04c7
5 changed files with 94 additions and 4 deletions
36
DatabaseMigrations/2.sql
Normal file
36
DatabaseMigrations/2.sql
Normal file
|
@ -0,0 +1,36 @@
|
|||
create table Slots
|
||||
(
|
||||
SlotId int,
|
||||
CreatorId int not null,
|
||||
Name text not null,
|
||||
Description text not null,
|
||||
IconHash text not null,
|
||||
RootLevel text not null,
|
||||
Resource text not null,
|
||||
LocationId int not null,
|
||||
InitiallyLocked bool default false not null,
|
||||
SubLevel bool default false null,
|
||||
Lbp1Only bool default false not null,
|
||||
Shareable int default 0 not null,
|
||||
AuthorLabels text not null,
|
||||
BackgroundHash text not null,
|
||||
MinimumPlayers int default 1 not null,
|
||||
MaximumPlayers int default 4 not null,
|
||||
MoveRequired bool default false null
|
||||
);
|
||||
|
||||
create unique index Slots_SlotId_uindex
|
||||
on Slots (SlotId);
|
||||
|
||||
alter table Slots
|
||||
add constraint Slots_pk
|
||||
primary key (SlotId);
|
||||
|
||||
alter table Slots
|
||||
modify SlotId int auto_increment;
|
||||
|
||||
alter table Slots
|
||||
alter column CreatorId set default -1;
|
||||
|
||||
alter table Slots
|
||||
modify CreatorId int not null after LocationId;
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ProjectLighthouse.Serialization;
|
||||
using ProjectLighthouse.Types;
|
||||
|
||||
|
@ -11,17 +13,44 @@ namespace ProjectLighthouse.Controllers {
|
|||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class PublishController : ControllerBase {
|
||||
/// <summary>
|
||||
/// Endpoint the game uses to verify that the level is compatible (?)
|
||||
/// </summary>
|
||||
[HttpPost("startPublish")]
|
||||
public async Task<IActionResult> StartPublish() {
|
||||
Slot slot = await this.GetSlotFromBody();
|
||||
|
||||
if(slot == null) return this.BadRequest(); // if the level cant be parsed then it obviously cant be uploaded
|
||||
|
||||
return this.Ok(LbpSerializer.TaggedStringElement("slot", "", "type", "user"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Endpoint actually used to publish a level
|
||||
/// </summary>
|
||||
[HttpPost("publish")]
|
||||
public async Task<IActionResult> Publish() {
|
||||
await using Database database = new();
|
||||
|
||||
User user = await database.Users.FirstOrDefaultAsync(u => u.Username == "jvyden");
|
||||
Slot slot = await this.GetSlotFromBody();
|
||||
|
||||
//TODO: parse location in body
|
||||
Location l = new() {
|
||||
X = 0,
|
||||
Y = 0
|
||||
};
|
||||
database.Locations.Add(l);
|
||||
await database.SaveChangesAsync();
|
||||
slot.LocationId = l.Id;
|
||||
slot.CreatorId = user.UserId;
|
||||
|
||||
database.Slots.Add(slot);
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
Request.Body.Position = 0;
|
||||
string bodyString = await new StreamReader(Request.Body).ReadToEndAsync();
|
||||
return this.Ok(LbpSerializer.TaggedStringElement("slot", bodyString, "type", "user"));
|
||||
return this.Ok(bodyString);
|
||||
}
|
||||
|
||||
public async Task<Slot> GetSlotFromBody() {
|
||||
|
|
|
@ -33,5 +33,6 @@ namespace ProjectLighthouse {
|
|||
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Location> Locations { get; set; }
|
||||
public DbSet<Slot> Slots { get; set; }
|
||||
}
|
||||
}
|
|
@ -25,7 +25,8 @@ namespace ProjectLighthouse.Types {
|
|||
try {
|
||||
return new Database().Database.CanConnect();
|
||||
}
|
||||
catch {
|
||||
catch(Exception e) {
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace ProjectLighthouse.Types {
|
||||
|
@ -11,6 +13,11 @@ namespace ProjectLighthouse.Types {
|
|||
[NotMapped]
|
||||
public string Type { get; set; }
|
||||
|
||||
[Key]
|
||||
[XmlIgnore]
|
||||
public int SlotId { get; set; }
|
||||
|
||||
|
||||
[XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
|
@ -26,8 +33,25 @@ namespace ProjectLighthouse.Types {
|
|||
[XmlElement("resource")]
|
||||
public string Resource { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public int LocationId { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public int CreatorId { get; set; }
|
||||
|
||||
private Location location;
|
||||
|
||||
/// <summary>
|
||||
/// The location of the level on the creator's earth
|
||||
/// </summary>
|
||||
[XmlElement("location")]
|
||||
public Location Location { get; set; }
|
||||
public Location Location {
|
||||
get {
|
||||
if(location != null) return this.location;
|
||||
|
||||
return location = new Database().Locations.First(l => l.Id == LocationId);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlElement("initiallyLocked")]
|
||||
public bool InitiallyLocked { get; set; }
|
||||
|
@ -55,6 +79,5 @@ namespace ProjectLighthouse.Types {
|
|||
|
||||
[XmlElement("moveRequired")]
|
||||
public bool MoveRequired { get; set; }
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue