-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Resource pack enable and instance user play time
- Loading branch information
Showing
10 changed files
with
104 additions
and
182 deletions.
There are no files selected for viewing
Submodule xmcl
updated
3 files
+1 −0 | packages/installer/index.ts | |
+126 −0 | packages/installer/labymod.ts | |
+3 −2 | packages/installer/tsconfig.json |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ResourceDomain } from '@xmcl/runtime-api' | ||
import { existsSync } from 'fs' | ||
import { readdir } from 'fs/promises' | ||
import { join } from 'path' | ||
import { LauncherAppPlugin } from '../app/LauncherApp' | ||
import { kGameDataPath } from '../entities/gameDataPath' | ||
import { InstanceOptionsService } from '../services/InstanceOptionsService' | ||
import { InstanceResourcePackService } from '../services/InstanceResourcePacksService' | ||
import { LaunchService } from '../services/LaunchService' | ||
import { linkWithTimeoutOrCopy } from '../util/fs' | ||
|
||
export const pluginResourcePackLink: LauncherAppPlugin = async (app) => { | ||
const launchService = await app.registry.get(LaunchService) | ||
const resourcePackService = await app.registry.get(InstanceResourcePackService) | ||
const options = await app.registry.get(InstanceOptionsService) | ||
const getPath = await app.registry.get(kGameDataPath) | ||
|
||
launchService.registerPlugin({ | ||
async onBeforeLaunch(input, output) { | ||
const path = output.gamePath | ||
const linked = await resourcePackService.link(path) | ||
if (linked) return | ||
|
||
const files = await readdir(join(path, ResourceDomain.ResourcePacks)) | ||
|
||
// if not linked, we need to link the resource pack to the instance | ||
const promises: Promise<any>[] = [] | ||
const gameOptions = await options.getGameOptions(path) | ||
const packs = gameOptions.resourcePacks || [] | ||
for (let fileName of packs) { | ||
if (fileName === 'vanilla') { | ||
continue | ||
} | ||
fileName = fileName.startsWith('file/') ? fileName.slice(5) : fileName | ||
if (files.includes(fileName)) { | ||
// Skip for existed file | ||
continue | ||
} | ||
const src = getPath(ResourceDomain.ResourcePacks, fileName) | ||
const dest = join(path, ResourceDomain.ResourcePacks, fileName) | ||
if (!existsSync(dest)) { | ||
promises.push(linkWithTimeoutOrCopy(src, dest).catch((e) => resourcePackService.error(e))) | ||
} | ||
} | ||
await Promise.all(promises) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { LauncherAppPlugin } from '../app/LauncherApp' | ||
import { InstanceService } from '../services/InstanceService' | ||
import { LaunchService } from '../services/LaunchService' | ||
import { LaunchService as ILaunchService } from '@xmcl/runtime-api' | ||
|
||
export const pluginUserPlaytime: LauncherAppPlugin = async (app) => { | ||
const launchService: ILaunchService = await app.registry.get(LaunchService) | ||
const instanceService = await app.registry.get(InstanceService) | ||
|
||
launchService.on('minecraft-start', (options) => { | ||
instanceService.editInstance({ | ||
instancePath: options.gameDirectory, | ||
lastPlayedDate: Date.now(), | ||
}) | ||
}) | ||
|
||
launchService.on('minecraft-exit', (options) => { | ||
if (options.gameDirectory) { | ||
const instance = instanceService.state.all[options.gameDirectory] | ||
if (instance) { | ||
instanceService.editInstance({ | ||
instancePath: options.gameDirectory, | ||
playtime: instance.playtime + options.duration, | ||
}) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters