Skip to content

Commit

Permalink
Mod names can finally be edited
Browse files Browse the repository at this point in the history
  • Loading branch information
thommcgrath committed May 24, 2024
1 parent 5781ad2 commit 20bb1c1
Show file tree
Hide file tree
Showing 4 changed files with 802 additions and 5 deletions.
1 change: 1 addition & 0 deletions Project/Beacon.xojo_project
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ DesktopWindow=StatusContainer;Custom Controls/StatusContainer.xojo_window;&h0000
Interface=BlueprintConsumer;Modules/Beacon/BlueprintConsumer.xojo_code;&h000000005E5207FF;&h0000000055ADDFFF;false
Class=BlueprintMigrator;Modules/Beacon/BlueprintMigrator.xojo_code;&h00000000300977FF;&h0000000055ADDFFF;false
MultiImage=IconToolbarAddOutline;Icons/IconToolbarAddOutline.xojo_image;&h00000000134317FF;&h0000000007F977FF;false
DesktopWindow=ModSettingsDialog;Views/Main Window Components/Blueprints/ModSettingsDialog.xojo_window;&h000000000443A7FF;&h00000000472E07FF;false
AppMenuBar=MainMenuBar
MajorVersion=2
MinorVersion=1
Expand Down
57 changes: 57 additions & 0 deletions Project/Modules/Beacon/DataSource.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,63 @@ Implements NotificationKit.Receiver
End Sub
#tag EndMethod

#tag Method, Flags = &h0
Function EditContentPack(Pack As Beacon.ContentPack, NewName As String, NewMarketplace As String, NewMarketplaceId As String) As Boolean
Var Changed As Boolean

Self.BeginTransaction()

If Pack.Name.Compare(NewName, ComparisonOptions.CaseSensitive) <> 0 Then
Self.SQLExecute("UPDATE content_packs SET name = ?2 WHERE content_pack_id = ?1;", Pack.ContentPackId, NewName)
Changed = True
End If

Var OldContentPackId, NewContentPackId As String
If (NewMarketplace.IsEmpty Or NewMarketplaceId.IsEmpty) And (Pack.Marketplace.IsEmpty = False Or Pack.MarketplaceId.IsEmpty = False) Then
// Switch to random uuid
OldContentPackId = Pack.ContentPackId
NewContentPackId = Beacon.UUID.v4
ElseIf Pack.MarketplaceId.Compare(NewMarketplaceId, ComparisonOptions.CaseSensitive) <> 0 Or Pack.Marketplace.Compare(NewMarketplace, ComparisonOptions.CaseSensitive) <> 0 Then
OldContentPackId = Pack.ContentPackId
NewContentPackId = Beacon.ContentPack.GenerateLocalContentPackId(NewMarketplace, NewMarketplaceId)
End If

If OldContentPackId <> NewContentPackId Then
Var Rows As RowSet = Self.SQLSelect("SELECT content_pack_id FROM content_packs WHERE content_pack_id = ?1;", NewContentPackId)
If Rows.RowCount <> 0 Then
Self.RollbackTransaction()
Return False
End If

// Need to migrate
Var RunMigrations As Boolean
If Self.mContentPackMigration Is Nil Then
Self.mContentPackMigration = New Dictionary
RunMigrations = True
End If

Self.SQLExecute("UPDATE content_packs SET content_pack_id = ?2, marketplace = ?3, marketplace_id = ?4 WHERE content_pack_id = ?1;", OldContentPackId, NewContentPackId, NewMarketplace, NewMarketplaceId)
Self.ScheduleContentPackMigration(OldContentPackId, NewContentPackId)

If RunMigrations Then
Self.RunContentPackMigrations()
Self.mContentPackMigration = Nil
End If

Changed = True
End If

If Changed Then
Self.CommitTransaction()
Self.ExportCloudFiles()
Else
Self.RollbackTransaction()
End If

Return Changed
End Function
#tag EndMethod

#tag Method, Flags = &h0
Shared Function EscapeIdentifier(Identifier As String) As String
Return """" + Identifier.ReplaceAll("""", """""") + """"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,19 @@ End
End Sub
#tag EndMethod

#tag Method, Flags = &h21
Private Shared Function IsUserContentPack(Pack As Beacon.ContentPack) As Boolean
If Pack Is Nil Then
Return False
End If

Select Case Pack.ContentPackId
Case Ark.UserContentPackId, ArkSA.UserContentPackId, Palworld.UserContentPackId, SDTD.UserContentPackId
Return True
End Select
End Function
#tag EndMethod

#tag Method, Flags = &h21
Private Sub mProgress_CancelPressed(Sender As ProgressWindow)
#Pragma Unused Sender
Expand Down Expand Up @@ -979,10 +992,9 @@ End
Continue
End If

Select Case Pack.ContentPackId
Case Ark.UserContentPackId, ArkSA.UserContentPackId, Palworld.UserContentPackId, SDTD.UserContentPackId
If Self.IsUserContentPack(Pack) Then
Continue
End Select
End If

Names.Add(Pack.Name)
Packs.Add(Pack)
Expand Down Expand Up @@ -1039,12 +1051,13 @@ End
#tag EndEvent
#tag Event
Sub SelectionChanged()
Var EnableOpening, EnableEditing As Boolean
Var EnableOpening, EnableEditing, EnableSettings As Boolean
If Me.SelectedRowCount = 1 Then
EnableOpening = True
Var Pack As Beacon.ContentPack = Me.RowTagAt(Me.SelectedRowIndex)
If Pack.IsLocal Or Me.CellTagAt(Me.SelectedRowIndex, Self.ColumnType) = ModsListView.ViewModes.Remote Then
EnableEditing = True
EnableSettings = (Self.IsUserContentPack(Pack) = False)
End If
End If

Expand All @@ -1058,7 +1071,7 @@ End
End If

If (Self.ModsToolbar.Item("EditMod") Is Nil) = False Then
Self.ModsToolbar.Item("EditMod").Enabled = EnableEditing
Self.ModsToolbar.Item("EditMod").Enabled = EnableSettings
End If

Self.UpdateUI()
Expand All @@ -1080,6 +1093,7 @@ End
Me.Append(OmniBarItem.CreateButton("ExportButton", "Export", IconToolbarExport, "Export the selected mod or mods to be shared with other Beacon users.", False))
Me.Append(OmniBarItem.CreateSeparator)
Me.Append(OmniBarItem.CreateButton("EditModBlueprints", "Edit Blueprints", IconToolbarEdit, "Edit the blueprints provided by the selected mod.", Self.ModsList.SelectedRowCount = 1))
Me.Append(OmniBarItem.CreateButton("EditMod", "Mod Settings", IconToolbarSettings, "Change settings for the selected mod.", False))
Me.Append(OmniBarItem.CreateSpace)
Me.Append(OmniBarItem.CreateSeparator)
Me.Append(OmniBarItem.CreateSpace)
Expand Down Expand Up @@ -1116,6 +1130,15 @@ End
End Select
Case "EditModBlueprints"
Self.ModsList.DoEdit()
Case "EditMod"
Var Pack As Beacon.ContentPack = Self.ModsList.RowTagAt(Self.ModsList.SelectedRowIndex)
If Self.CloseModView(Pack.ContentPackId) = False Then
Self.ShowAlert("Mod content editor must be closed to edit settings.", "Save or discard your work, close the view, and try again.")
Return
End If
If ModSettingsDialog.Present(Self, Pack) Then
Self.RefreshMods()
End If
Case "DiscoverMods"
Self.RunModDiscovery()
Case "ImportButton"
Expand Down
Loading

0 comments on commit 20bb1c1

Please sign in to comment.