Refactor launcher profiles and port automation
This commit is contained in:
@@ -19,8 +19,8 @@ const editorHint = document.getElementById('editorHint')
|
||||
const saveCatalogButton = document.getElementById('saveCatalogButton')
|
||||
const duplicateProfileButton = document.getElementById('duplicateProfileButton')
|
||||
const deleteProfileButton = document.getElementById('deleteProfileButton')
|
||||
const mapSection = document.getElementById('mapSection')
|
||||
const serverPackSection = document.getElementById('serverPackSection')
|
||||
const addProfileButton = document.getElementById('addProfileButton')
|
||||
const serverSection = document.getElementById('serverSection')
|
||||
const editDistributionButton = document.getElementById('editDistributionButton')
|
||||
const createDistributionButton = document.getElementById('createDistributionButton')
|
||||
const distributionEditorModal = document.getElementById('distributionEditorModal')
|
||||
@@ -32,20 +32,20 @@ const saveDistributionFileButton = document.getElementById('saveDistributionFile
|
||||
|
||||
const fieldElements = {
|
||||
id: document.getElementById('field-id'),
|
||||
kind: document.getElementById('field-kind'),
|
||||
name: document.getElementById('field-name'),
|
||||
description: document.getElementById('field-description'),
|
||||
details: document.getElementById('field-details'),
|
||||
modsEnabled: document.getElementById('field-modsEnabled'),
|
||||
pluginsEnabled: document.getElementById('field-pluginsEnabled'),
|
||||
serverEnabled: document.getElementById('field-serverEnabled'),
|
||||
distributionUrl: document.getElementById('field-distributionUrl'),
|
||||
worldArchiveUrl: document.getElementById('field-worldArchiveUrl'),
|
||||
worldDirectoryName: document.getElementById('field-worldDirectoryName'),
|
||||
serverBundleUrl: document.getElementById('field-serverBundleUrl'),
|
||||
serverDirectoryName: document.getElementById('field-serverDirectoryName'),
|
||||
serverLaunchCommand: document.getElementById('field-serverLaunchCommand'),
|
||||
serverWorkingDirectory: document.getElementById('field-serverWorkingDirectory'),
|
||||
serverJarUrl: document.getElementById('field-serverJarUrl'),
|
||||
serverPort: document.getElementById('field-serverPort'),
|
||||
tunnelCommand: document.getElementById('field-tunnelCommand'),
|
||||
tunnelAddressRegex: document.getElementById('field-tunnelAddressRegex')
|
||||
serverMemoryMb: document.getElementById('field-serverMemoryMb'),
|
||||
serverMaxPlayers: document.getElementById('field-serverMaxPlayers'),
|
||||
serverWhitelistEnabled: document.getElementById('field-serverWhitelistEnabled')
|
||||
}
|
||||
|
||||
function slugify(value){
|
||||
@@ -60,24 +60,24 @@ function isRemoteUrl(value){
|
||||
return /^https?:\/\//i.test(String(value ?? '').trim())
|
||||
}
|
||||
|
||||
function createProfile(kind){
|
||||
function createProfile(){
|
||||
const timestamp = Date.now()
|
||||
return {
|
||||
id: `${kind}-${timestamp}`,
|
||||
name: kind === 'map' ? '새 맵 프로필' : kind === 'server-pack' ? '새 서버팩 프로필' : '새 모드팩 프로필',
|
||||
kind,
|
||||
id: `profile-${timestamp}`,
|
||||
name: '새 프로필',
|
||||
description: '',
|
||||
details: '',
|
||||
modsEnabled: false,
|
||||
pluginsEnabled: false,
|
||||
serverEnabled: false,
|
||||
distributionUrl: '',
|
||||
worldArchiveUrl: '',
|
||||
worldDirectoryName: '',
|
||||
serverBundleUrl: '',
|
||||
serverDirectoryName: `${kind}-${timestamp}-server`,
|
||||
serverLaunchCommand: '',
|
||||
serverWorkingDirectory: '',
|
||||
serverJarUrl: '',
|
||||
serverPort: 25565,
|
||||
tunnelCommand: '',
|
||||
tunnelAddressRegex: ''
|
||||
serverMemoryMb: 4096,
|
||||
serverMaxPlayers: 20,
|
||||
serverWhitelistEnabled: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,20 @@ function selectProfile(profileId){
|
||||
populateEditor()
|
||||
}
|
||||
|
||||
function describeProfileFeatures(profile){
|
||||
const badges = ['맵']
|
||||
if(profile.modsEnabled){
|
||||
badges.push('모드')
|
||||
}
|
||||
if(profile.pluginsEnabled){
|
||||
badges.push('플러그인')
|
||||
}
|
||||
if(profile.serverEnabled){
|
||||
badges.push('서버')
|
||||
}
|
||||
return badges
|
||||
}
|
||||
|
||||
function renderSidebar(){
|
||||
profileList.innerHTML = ''
|
||||
profileCount.textContent = `${state.catalog.profiles.length}개`
|
||||
@@ -126,10 +140,9 @@ function renderSidebar(){
|
||||
|
||||
const meta = document.createElement('div')
|
||||
meta.className = 'profileListMeta'
|
||||
meta.innerHTML = `
|
||||
<span class="badge">${profile.kind}</span>
|
||||
${profile.distributionUrl ? '<span class="badge">distribution 연결</span>' : '<span class="badge">distribution 비어있음</span>'}
|
||||
`
|
||||
meta.innerHTML = describeProfileFeatures(profile)
|
||||
.map((label) => `<span class="badge">${label}</span>`)
|
||||
.join('')
|
||||
|
||||
const description = document.createElement('div')
|
||||
description.className = 'profileListDescription'
|
||||
@@ -146,9 +159,18 @@ function renderSidebar(){
|
||||
}
|
||||
}
|
||||
|
||||
function syncKindSections(kind){
|
||||
mapSection.hidden = kind !== 'map'
|
||||
serverPackSection.hidden = kind !== 'server-pack'
|
||||
function syncFeatureDependencies(profile, showMessage = false){
|
||||
if(profile.pluginsEnabled && !profile.serverEnabled){
|
||||
profile.serverEnabled = true
|
||||
if(showMessage){
|
||||
showStatus('플러그인 사용을 켜면 서버 사용도 자동으로 같이 켜집니다.', 'info')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function syncServerSection(profile){
|
||||
serverSection.hidden = !profile?.serverEnabled
|
||||
fieldElements.serverEnabled.disabled = profile?.pluginsEnabled === true
|
||||
}
|
||||
|
||||
function updateDistributionEditorHint(profile, pathOverride){
|
||||
@@ -183,29 +205,32 @@ function populateEditor(){
|
||||
|
||||
if(!profile){
|
||||
editorHint.textContent = '왼쪽에서 프로필을 선택하거나 새 프로필을 추가하세요.'
|
||||
syncServerSection(null)
|
||||
updateDistributionEditorHint(null)
|
||||
return
|
||||
}
|
||||
|
||||
editorHint.textContent = `${profile.kind} 프로필을 편집 중입니다. 저장하면 런처 카탈로그도 같이 갱신됩니다.`
|
||||
syncFeatureDependencies(profile)
|
||||
|
||||
editorHint.textContent = '맵은 기본이고, 모드/플러그인/서버를 체크해서 조합하는 프로필입니다. 저장하면 런처 카탈로그도 같이 갱신됩니다.'
|
||||
|
||||
fieldElements.id.value = profile.id ?? ''
|
||||
fieldElements.kind.value = profile.kind ?? 'modpack'
|
||||
fieldElements.name.value = profile.name ?? ''
|
||||
fieldElements.description.value = profile.description ?? ''
|
||||
fieldElements.details.value = profile.details ?? ''
|
||||
fieldElements.modsEnabled.checked = profile.modsEnabled === true
|
||||
fieldElements.pluginsEnabled.checked = profile.pluginsEnabled === true
|
||||
fieldElements.serverEnabled.checked = profile.serverEnabled === true
|
||||
fieldElements.distributionUrl.value = profile.distributionUrl ?? ''
|
||||
fieldElements.worldArchiveUrl.value = profile.worldArchiveUrl ?? ''
|
||||
fieldElements.worldDirectoryName.value = profile.worldDirectoryName ?? ''
|
||||
fieldElements.serverBundleUrl.value = profile.serverBundleUrl ?? ''
|
||||
fieldElements.serverDirectoryName.value = profile.serverDirectoryName ?? ''
|
||||
fieldElements.serverLaunchCommand.value = profile.serverLaunchCommand ?? ''
|
||||
fieldElements.serverWorkingDirectory.value = profile.serverWorkingDirectory ?? ''
|
||||
fieldElements.serverJarUrl.value = profile.serverJarUrl ?? ''
|
||||
fieldElements.serverPort.value = profile.serverPort ?? 25565
|
||||
fieldElements.tunnelCommand.value = profile.tunnelCommand ?? ''
|
||||
fieldElements.tunnelAddressRegex.value = profile.tunnelAddressRegex ?? ''
|
||||
fieldElements.serverMemoryMb.value = profile.serverMemoryMb ?? 4096
|
||||
fieldElements.serverMaxPlayers.value = profile.serverMaxPlayers ?? 20
|
||||
fieldElements.serverWhitelistEnabled.checked = profile.serverWhitelistEnabled === true
|
||||
|
||||
syncKindSections(profile.kind)
|
||||
syncServerSection(profile)
|
||||
updateDistributionEditorHint(profile)
|
||||
}
|
||||
|
||||
@@ -216,8 +241,10 @@ function updateSelectedProfile(patch){
|
||||
}
|
||||
|
||||
Object.assign(profile, patch)
|
||||
syncFeatureDependencies(profile)
|
||||
markDirty(true)
|
||||
renderSidebar()
|
||||
syncServerSection(profile)
|
||||
|
||||
if(Object.prototype.hasOwnProperty.call(patch, 'distributionUrl')){
|
||||
updateDistributionEditorHint(profile, patch.distributionUrl)
|
||||
@@ -248,15 +275,27 @@ function bindTextField(fieldName){
|
||||
})
|
||||
}
|
||||
|
||||
function bindNumberField(fieldName){
|
||||
function bindNumberField(fieldName, fallback){
|
||||
fieldElements[fieldName].addEventListener('input', (event) => {
|
||||
const value = Number.parseInt(event.target.value || '25565', 10)
|
||||
const value = Number.parseInt(event.target.value || String(fallback), 10)
|
||||
updateSelectedProfile({
|
||||
[fieldName]: Number.isFinite(value) ? value : 25565
|
||||
[fieldName]: Number.isFinite(value) ? value : fallback
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function bindCheckboxField(fieldName){
|
||||
fieldElements[fieldName].addEventListener('change', (event) => {
|
||||
updateSelectedProfile({
|
||||
[fieldName]: event.target.checked
|
||||
})
|
||||
|
||||
if(fieldName === 'pluginsEnabled' || fieldName === 'serverEnabled'){
|
||||
populateEditor()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function bindProfileForm(){
|
||||
profileEditorForm.addEventListener('submit', (event) => {
|
||||
event.preventDefault()
|
||||
@@ -269,30 +308,14 @@ function bindProfileForm(){
|
||||
bindTextField('distributionUrl')
|
||||
bindTextField('worldArchiveUrl')
|
||||
bindTextField('worldDirectoryName')
|
||||
bindTextField('serverBundleUrl')
|
||||
bindTextField('serverDirectoryName')
|
||||
bindTextField('serverLaunchCommand')
|
||||
bindTextField('serverWorkingDirectory')
|
||||
bindNumberField('serverPort')
|
||||
bindTextField('tunnelCommand')
|
||||
bindTextField('tunnelAddressRegex')
|
||||
|
||||
fieldElements.kind.addEventListener('change', (event) => {
|
||||
const profile = getSelectedProfile()
|
||||
if(!profile){
|
||||
return
|
||||
}
|
||||
|
||||
profile.kind = event.target.value
|
||||
|
||||
if(profile.kind === 'server-pack' && !profile.serverDirectoryName){
|
||||
profile.serverDirectoryName = `${slugify(profile.id || profile.name) || 'profile'}-server`
|
||||
}
|
||||
|
||||
markDirty(true)
|
||||
renderSidebar()
|
||||
populateEditor()
|
||||
})
|
||||
bindTextField('serverJarUrl')
|
||||
bindNumberField('serverPort', 25565)
|
||||
bindNumberField('serverMemoryMb', 4096)
|
||||
bindNumberField('serverMaxPlayers', 20)
|
||||
bindCheckboxField('modsEnabled')
|
||||
bindCheckboxField('pluginsEnabled')
|
||||
bindCheckboxField('serverEnabled')
|
||||
bindCheckboxField('serverWhitelistEnabled')
|
||||
|
||||
for(const button of document.querySelectorAll('.uploadButton')){
|
||||
button.addEventListener('click', async () => {
|
||||
@@ -507,12 +530,23 @@ async function loadMeta(){
|
||||
localCatalogUrl.href = meta.localCatalogUrl
|
||||
}
|
||||
|
||||
function normalizeLoadedProfile(profile){
|
||||
return {
|
||||
...createProfile(),
|
||||
...profile,
|
||||
modsEnabled: profile.modsEnabled === true,
|
||||
pluginsEnabled: profile.pluginsEnabled === true,
|
||||
serverEnabled: profile.serverEnabled === true || profile.pluginsEnabled === true,
|
||||
serverWhitelistEnabled: profile.serverWhitelistEnabled === true
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCatalog(){
|
||||
const response = await fetch('/api/catalog')
|
||||
const catalog = await response.json()
|
||||
state.catalog = {
|
||||
version: 1,
|
||||
profiles: Array.isArray(catalog.profiles) ? catalog.profiles : []
|
||||
profiles: Array.isArray(catalog.profiles) ? catalog.profiles.map(normalizeLoadedProfile) : []
|
||||
}
|
||||
|
||||
if(state.catalog.profiles.length > 0){
|
||||
@@ -526,8 +560,8 @@ async function loadCatalog(){
|
||||
populateEditor()
|
||||
}
|
||||
|
||||
function addProfile(kind){
|
||||
const profile = createProfile(kind)
|
||||
function addProfile(){
|
||||
const profile = createProfile()
|
||||
state.catalog.profiles.push(profile)
|
||||
markDirty(true)
|
||||
selectProfile(profile.id)
|
||||
@@ -587,7 +621,10 @@ async function saveCatalog(){
|
||||
throw new Error(result.message || '카탈로그 저장에 실패했습니다.')
|
||||
}
|
||||
|
||||
state.catalog = result.catalog
|
||||
state.catalog = {
|
||||
version: 1,
|
||||
profiles: result.catalog.profiles.map(normalizeLoadedProfile)
|
||||
}
|
||||
if(!state.catalog.profiles.some((profile) => profile.id === state.selectedProfileId)){
|
||||
state.selectedProfileId = state.catalog.profiles[0]?.id ?? null
|
||||
}
|
||||
@@ -605,11 +642,9 @@ async function saveCatalog(){
|
||||
}
|
||||
|
||||
function bindTopLevelActions(){
|
||||
for(const button of document.querySelectorAll('[data-add-kind]')){
|
||||
button.addEventListener('click', () => {
|
||||
addProfile(button.dataset.addKind)
|
||||
})
|
||||
}
|
||||
addProfileButton.addEventListener('click', () => {
|
||||
addProfile()
|
||||
})
|
||||
|
||||
saveCatalogButton.addEventListener('click', async () => {
|
||||
await saveCatalog()
|
||||
|
||||
Reference in New Issue
Block a user