From d6cd0b4d881fdc4ce1ce5a682509ca03c7ef45e0 Mon Sep 17 00:00:00 2001 From: HypoxiE Date: Tue, 15 Jul 2025 03:02:19 +0300 Subject: [PATCH] Added a script to save user settings --- About/About.xml | 16 ++++----- README.md | 21 +++++++++--- add_my_music.bat | 46 +------------------------ add_my_music.ps1 | 80 ++++++++++++++++++++++++++++++++++++++++++++ add_my_music_old.bat | 46 +++++++++++++++++++++++++ 5 files changed, 152 insertions(+), 57 deletions(-) create mode 100644 add_my_music.ps1 create mode 100644 add_my_music_old.bat diff --git a/About/About.xml b/About/About.xml index 6712b52..257e2c4 100644 --- a/About/About.xml +++ b/About/About.xml @@ -13,14 +13,14 @@ [EN] -This mod adds the ability to put your own music in the game. -Quick guide: -1) Throw your music into the Sounds\Gameplay\ folder of this mod -2) Run the add_my_music.bat script +This mod adds the ability to play your own music in the game. +Short guide: +1) Put your music files into the Sounds\Gameplay\ folder of this mod. +2) Run the add_my_music.bat script. -After running add_my_music.bat, the Defs\SongDefs\Songs_Gameplay.xml file will be completely rewritten. After that, you can change the modifiers in this file, delete something from it or add. Initially, the default parameters are written to it, so you can change them at your discretion. In the future, we plan to make a script that adds and removes music, but does not touch the existing parameters. +After running add_my_music.bat, the file Defs\SongDefs\Songs_Gameplay.xml will be overwritten (existing settings will be preserved). After that, you can modify the settings in this file, delete entries, or add new ones. Initially, default parameters are written to the file, so you can customize them as you like. -Mod source code: https://github.com/HypoxiE/rimworld-ammp +Mod source code: https://github.com/HypoxiE/rimworld-add-my-music-mod [RU] Данный мод добавляет возможность ставить свою музыку в игру. @@ -28,8 +28,8 @@ Mod source code: https://github.com/HypoxiE/rimworld-ammp 1) Закиньте свою музыку в папку Sounds\Gameplay\ этого мода 2) Запустите скрипт add_my_music.bat -После запуска add_my_music.bat файл Defs\SongDefs\Songs_Gameplay.xml полностью перезапишется. После этого вы можете менять модификаторы в этом файле, удалять что-либо из него или добавлять. Изначально в него записываются параметры по умолчанию, так что вы можете менять их на своё усмотрение. В будущем планируется сделать скрипт, который добавляет и удаляет музыку, но при этом не трогает уже существующие параметры. +После запуска add_my_music.bat файл Defs\SongDefs\Songs_Gameplay.xml перезапишется (уже существующие настройки останутся). После этого вы можете менять модификаторы в этом файле, удалять что-либо из него или добавлять. Изначально в него записываются параметры по умолчанию, так что вы можете менять их на своё усмотрение. -Исходный код мода: https://github.com/HypoxiE/rimworld-ammp +Исходный код мода: https://github.com/HypoxiE/rimworld-add-my-music-mod \ No newline at end of file diff --git a/README.md b/README.md index c11a170..65e8578 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,20 @@ -# Add my music, please! mod for rimworld +# Add my music, please! -## A short guide +## Short guide +Add your music in **.mp3** or **.ogg** format to the `Sounds\Gameplay` directory. Then run `add_my_music.bat` or `add_my_music.ps1`. -In this version, after installing the modification, you need to run add_my_music.bat. After that, in the folder C:\Users\\AppData\LocalLow\Ludeon Studios\RimWorld by Ludeon Studios\AddMyMusic_data\music_is_here, leave your music and run add_my_music.bat again. After that, run rimworld, close it and load it again. After that, the music should load in the game +Done! The script will automatically create all the necessary files. You can now launch the game and enjoy your music. -~~To add your music, you just need to drop your music into the Sounds\Gameplay\ folder and run the add_my_music.bat script. After that, the Defs\SongDefs\Songs_Gameplay.xml file will be automatically overwritten and after you enable the mod in the game, your music will appear there.~~ \ No newline at end of file +In the new version, you can freely customize your tracks in `Defs\SongDefs\Songs_Gameplay.xml`. +The settings for existing songs will not be lost if you decide to delete old or add new tracks. +Simply run `add_my_music.bat` after removing or adding music, and the script will carry over your settings into the new `Songs_Gameplay.xml`. + + +## Короткое руководство +Добавьте свою музыку формата **.mp3** или **.ogg** в директорию `Sounds\Gameplay`. После этого запустите `add_my_music.bat` или `add_my_music.ps1`. + +Готово, скрипт автоматически создаст нужные файлы. Можете заходить в игру и наслаждаться своей музыкой + +В новой версии вы можете спокойно настраивать свои композиции в `Defs\SongDefs\Songs_Gameplay.xml`. +Настройки существующих песен не собьются, если вы решите удалить старые или добавить новые. +Просто нажмите `add_my_music.bat` после удаления/добавления музыки и скрипт перенесёт ваши настройки в новый `Songs_Gameplay.xml` \ No newline at end of file diff --git a/add_my_music.bat b/add_my_music.bat index fca4634..80454f9 100644 --- a/add_my_music.bat +++ b/add_my_music.bat @@ -1,46 +1,2 @@ @echo off -echo This command will completely overwrite the Songs_Gameplay.xml file of this modification. If you agree, press Enter, and if not, close this window. -pause - -setlocal enabledelayedexpansion -set "Songs_Gameplay_XML_path=Defs\SongDefs" - -set "music_path=Sounds\Gameplay" - - -chcp 65001 -echo ^ > "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" -echo ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - -for %%f in ("%music_path%\*") do ( - set sound_name=%%~nf - - echo ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^!sound_name!^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^Gameplay/!sound_name!^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^<^^!--The probability of music appearing in the game--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^1.0^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^<^^!--Music volume--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^1.0^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^<^^!--If true, it only plays in a combat situation--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^false^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^<^^!--If you want to limit the time of day, delete '^<^^!- -' and '- -^>' of the desired option--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^<^^!--^Day^--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^<^^!--^Night^--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^<^^!--Listing the seasons in which this song is played--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo ^ ^Winter^^Spring^^Summer^^Fall^ ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - - echo ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - echo Added !sound_name! -) - -echo ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" - -echo Songs_Gameplay.xml overwritten. After restarting the game, music will be added. -pause \ No newline at end of file +powershell -ExecutionPolicy Bypass -File %~dp0add_my_music.ps1 \ No newline at end of file diff --git a/add_my_music.ps1 b/add_my_music.ps1 new file mode 100644 index 0000000..b2bcded --- /dev/null +++ b/add_my_music.ps1 @@ -0,0 +1,80 @@ +# Включаем кодировку UTF8 для консоли +[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 +$lineBreak = [Environment]::NewLine + +# Пути +$SongsGameplayXMLPath = "Defs\SongDefs" +$musicPath = "Sounds\Gameplay" + +# Проверяем, что папка для xml существует, если нет — создаём +if (-not (Test-Path $SongsGameplayXMLPath)) { + New-Item -ItemType Directory -Path $SongsGameplayXMLPath | Out-Null +} + +if (Test-Path "$SongsGameplayXMLPath\Songs_Gameplay.xml") { + $content = Get-Content -Path "$SongsGameplayXMLPath\Songs_Gameplay.xml" -Raw +} else { + $content = "" +} + +$allSongDefs = @() +if ($content -ne "") { + $blockPattern = "" + $allSongDefs = [regex]::Matches($content, $blockPattern, [System.Text.RegularExpressions.RegexOptions]::Singleline) +} + +# Переменная для накопления текста +$xmlContent = @" + + +"@ + +Get-ChildItem -Path $musicPath -File | ForEach-Object { + $soundName = $_.BaseName + $existingBlock = $null + + foreach ($block in $allSongDefs) { + if ($block.Value -like "*$soundName*") { + $existingBlock = $block.Value + break + } + } + + if ($existingBlock) { + Write-Output "Found existing block for $soundName" + $xmlContent += "${lineBreak}$existingBlock${lineBreak}" + } else { + Write-Output "Added new block for $soundName" + $xmlContent += @" +${lineBreak} + $soundName + Gameplay/$soundName + + + 1.0 + + + 1.0 + + + false + + + + + + +
  • Winter
  • Spring
  • Summer
  • Fall
  • +
    ${lineBreak} +"@ + } +} + +# Закрываем тег +$xmlContent += "
    " + +# Записать в файл одним вызовом +$xmlContent | Out-File -FilePath "$SongsGameplayXMLPath\Songs_Gameplay.xml" -Encoding utf8 + +Write-Host "Songs_Gameplay.xml overwritten. After restarting the game, music will be added." +Read-Host "Press Enter to exit" diff --git a/add_my_music_old.bat b/add_my_music_old.bat new file mode 100644 index 0000000..fca4634 --- /dev/null +++ b/add_my_music_old.bat @@ -0,0 +1,46 @@ +@echo off +echo This command will completely overwrite the Songs_Gameplay.xml file of this modification. If you agree, press Enter, and if not, close this window. +pause + +setlocal enabledelayedexpansion +set "Songs_Gameplay_XML_path=Defs\SongDefs" + +set "music_path=Sounds\Gameplay" + + +chcp 65001 +echo ^ > "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" +echo ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + +for %%f in ("%music_path%\*") do ( + set sound_name=%%~nf + + echo ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^!sound_name!^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^Gameplay/!sound_name!^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^<^^!--The probability of music appearing in the game--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^1.0^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^<^^!--Music volume--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^1.0^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^<^^!--If true, it only plays in a combat situation--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^false^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^<^^!--If you want to limit the time of day, delete '^<^^!- -' and '- -^>' of the desired option--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^<^^!--^Day^--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^<^^!--^Night^--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^<^^!--Listing the seasons in which this song is played--^> >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo ^ ^Winter^^Spring^^Summer^^Fall^ ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + + echo ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo. >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + echo Added !sound_name! +) + +echo ^ >> "%Songs_Gameplay_XML_path%\Songs_Gameplay.xml" + +echo Songs_Gameplay.xml overwritten. After restarting the game, music will be added. +pause \ No newline at end of file