@@ -27,19 +27,34 @@ public partial class GameDatabaseContext // Levels
2727 . Include ( s => s . Level . Publisher )
2828 . Include ( s => s . Level . Publisher ! . Statistics ) ;
2929
30- public bool AddLevel ( GameLevel level )
30+ public GameLevel AddLevel ( ISerializedPublishLevel createInfo , TokenGame game , GameUser publisher )
3131 {
32- if ( level . Title is { Length : > UgcLimits . TitleLimit } )
33- level . Title = level . Title [ ..UgcLimits . TitleLimit ] ;
34-
35- if ( level . Description is { Length : > UgcLimits . DescriptionLimit } )
36- level . Description = level . Description [ ..UgcLimits . DescriptionLimit ] ;
37-
38- if ( level . Publisher == null ) throw new InvalidOperationException ( "Cannot create a level without a publisher" ) ;
39-
4032 DateTimeOffset timestamp = this . _time . Now ;
41- level . PublishDate = timestamp ;
42- level . UpdateDate = timestamp ;
33+
34+ GameLevel level = new ( )
35+ {
36+ Title = createInfo . Title ,
37+ Description = createInfo . Description ,
38+ IconHash = createInfo . IconHash ,
39+ LocationX = createInfo . Location . X ,
40+ LocationY = createInfo . Location . Y ,
41+ RootResource = createInfo . RootResource ,
42+ IsLocked = createInfo . IsLocked ,
43+ IsCopyable = createInfo . IsCopyable == 1 ,
44+ IsSubLevel = createInfo . IsSubLevel ,
45+ MinPlayers = createInfo . MinPlayers ,
46+ MaxPlayers = createInfo . MaxPlayers ,
47+ LevelType = GameLevelTypeExtensions . FromGameString ( createInfo . LevelType ) ,
48+ RequiresMoveController = createInfo . RequiresMoveController ,
49+ IsAdventure = createInfo . IsAdventure ,
50+ EnforceMinMaxPlayers = createInfo . EnforceMinMaxPlayers ,
51+ SameScreenGame = createInfo . SameScreenGame ,
52+ BackgroundGuid = createInfo . BackgroundGuid ,
53+ Publisher = publisher ,
54+ GameVersion = game ,
55+ PublishDate = timestamp ,
56+ UpdateDate = timestamp ,
57+ } ;
4358
4459 this . ApplyLevelMetadataFromAttributes ( level ) ;
4560 this . GameLevels . Add ( level ) ;
@@ -62,7 +77,7 @@ public bool AddLevel(GameLevel level)
6277 } ) ;
6378 }
6479
65- return true ;
80+ return level ;
6681 }
6782
6883 public GameLevel GetStoryLevelById ( int id )
@@ -156,55 +171,38 @@ public void UpdateLevelLocations(IEnumerable<ISerializedEditLevelLocation> locat
156171 this . AddErrorNotification ( "Level updates failed" , $ "Failed to update { failedUpdates } out of { locations . Count ( ) } level locations.", updatingUser ) ;
157172 }
158173 }
159-
160- public GameLevel ? UpdateLevel ( GameLevel newLevel , GameUser author )
161- {
162- if ( newLevel . Title is { Length : > UgcLimits . TitleLimit } )
163- newLevel . Title = newLevel . Title [ ..UgcLimits . TitleLimit ] ;
164174
165- if ( newLevel . Description is { Length : > UgcLimits . DescriptionLimit } )
166- newLevel . Description = newLevel . Description [ ..UgcLimits . DescriptionLimit ] ;
167-
168- // Verify if this level is able to be republished
169- GameLevel ? oldLevel = this . GetLevelById ( newLevel . LevelId ) ;
170- if ( oldLevel == null ) return null ;
171-
172- Debug . Assert ( oldLevel . Publisher != null ) ;
173- if ( oldLevel . Publisher . UserId != author . UserId ) return null ;
174-
175- // All checks passed, let's start by retaining some information from the old level
176- newLevel . Publisher = author ;
177- newLevel . PublishDate = oldLevel . PublishDate ;
178- newLevel . DateTeamPicked = oldLevel . DateTeamPicked ;
179- newLevel . IsReUpload = oldLevel . IsReUpload ;
180- newLevel . OriginalPublisher = oldLevel . OriginalPublisher ;
181-
182- // If the actual contents of the level haven't changed, extract some extra information
183- if ( oldLevel . RootResource == newLevel . RootResource )
184- {
185- newLevel . GameVersion = oldLevel . GameVersion ;
186- newLevel . UpdateDate = oldLevel . UpdateDate ;
187- }
188- // If we're changing the actual level, update other things
189- else
190- {
191- newLevel . UpdateDate = this . _time . Now ; // Set the last modified date
192- }
193-
194- // Now newLevel is set up to replace oldLevel.
195- // If information is lost here, then that's probably a bug.
196- // Update the level's properties in the database
197- PropertyInfo [ ] userProps = typeof ( GameLevel ) . GetProperties ( ) ;
198- foreach ( PropertyInfo prop in userProps )
175+ public GameLevel UpdateLevel ( ISerializedPublishLevel updateInfo , GameLevel level , TokenGame game = TokenGame . LittleBigPlanet1 )
176+ {
177+ level . Title = updateInfo . Title ;
178+ level . Description = updateInfo . Description ;
179+ level . IconHash = updateInfo . IconHash ;
180+ level . LocationX = updateInfo . Location . X ;
181+ level . LocationY = updateInfo . Location . Y ;
182+ level . IsLocked = updateInfo . IsLocked ;
183+ level . IsCopyable = updateInfo . IsCopyable == 1 ;
184+ level . IsSubLevel = updateInfo . IsSubLevel ;
185+ level . MinPlayers = updateInfo . MinPlayers ;
186+ level . MaxPlayers = updateInfo . MaxPlayers ;
187+ level . LevelType = GameLevelTypeExtensions . FromGameString ( updateInfo . LevelType ) ;
188+ level . RequiresMoveController = updateInfo . RequiresMoveController ;
189+ level . IsAdventure = updateInfo . IsAdventure ;
190+ level . EnforceMinMaxPlayers = updateInfo . EnforceMinMaxPlayers ;
191+ level . SameScreenGame = updateInfo . SameScreenGame ;
192+ level . BackgroundGuid = updateInfo . BackgroundGuid ;
193+
194+ // If we're changing the actual contents of the level, update the game version and update date aswell
195+ if ( updateInfo . RootResource != level . RootResource )
199196 {
200- if ( ! prop . CanWrite || ! prop . CanRead ) continue ;
201- prop . SetValue ( oldLevel , prop . GetValue ( newLevel ) ) ;
197+ level . UpdateDate = this . _time . Now ;
198+ level . GameVersion = game ;
199+ level . RootResource = updateInfo . RootResource ;
202200 }
203201
204- this . ApplyLevelMetadataFromAttributes ( newLevel ) ;
205- this . CreateRevisionForLevel ( newLevel , author ) ;
202+ this . ApplyLevelMetadataFromAttributes ( level ) ;
203+ this . CreateRevisionForLevel ( level , level . Publisher ) ;
206204 this . SaveChanges ( ) ;
207- return oldLevel ;
205+ return level ;
208206 }
209207
210208 public GameLevel ? UpdateLevel ( IApiEditLevelRequest body , GameLevel level , GameUser ? updatingUser )
0 commit comments