-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable client module to manage mapping
- Loading branch information
Showing
10 changed files
with
144 additions
and
28 deletions.
There are no files selected for viewing
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,46 @@ | ||
import base from 'universal/store/modules/client'; | ||
import fs from 'fs'; | ||
import { join } from 'path'; | ||
|
||
/** | ||
* @type {import('universal/store/modules/client').ClientModule} | ||
*/ | ||
const mod = { | ||
...base, | ||
actions: { | ||
async load(context) { | ||
const protocolFile = context.rootGetters.path('protocol.json'); | ||
if (fs.existsSync(protocolFile)) { | ||
const buf = await fs.promises.readFile(protocolFile); | ||
const object = JSON.parse(buf.toString()); | ||
if (object.eTag) { | ||
// request server for new one | ||
} | ||
/** | ||
* @type any | ||
*/ | ||
const mcversionMapping = {}; | ||
for (const [mc, prot] of Object.values(object.protocol)) { | ||
if (!mcversionMapping[mc]) mcversionMapping[mc] = []; | ||
mcversionMapping[mc].push(prot); | ||
} | ||
context.commit('protocolMapping', { | ||
protocol: object.protocol, | ||
mcversion: mcversionMapping, | ||
}); | ||
} else { | ||
const rev = await fs.promises.readFile(join(__static, 'protocol.json')) | ||
.then(b => b.toString()).then(JSON.parse); | ||
const forward = await fs.promises.readFile(join(__static, 'mc-protocol.json')) | ||
.then(b => b.toString()).then(JSON.parse); | ||
|
||
context.commit('protocolMapping', { | ||
protocol: forward, | ||
mcversion: rev, | ||
}); | ||
} | ||
}, | ||
}, | ||
}; | ||
|
||
export default mod; |
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
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,51 @@ | ||
|
||
|
||
import { Module, Context } from "../store"; | ||
|
||
export declare namespace ClientModule { | ||
type ProtocolToVersion = { | ||
[protocol: string]: string[]; | ||
}; | ||
type PackFormatToVersioRange = { | ||
[range: string]: string; | ||
}; | ||
|
||
type Protocol = string; | ||
type MinecraftVersion = string; | ||
|
||
interface ResourcePackFormatMapping { | ||
mcversion: { | ||
[format: number]: string; | ||
}; | ||
} | ||
interface ClientProtocolMapping { | ||
mcversion: { | ||
[mcversion: string]: Protocol; | ||
}; | ||
protocol: { | ||
[protocol: Protocol]: MinecraftVersion[]; | ||
}; | ||
} | ||
|
||
interface State { | ||
protocolMapping: ClientProtocolMapping; | ||
packFormatMapping: ResourcePackFormatMapping; | ||
} | ||
|
||
interface Getters { | ||
isResourcePackCompatible(format: number, mcversion: string): boolean; | ||
} | ||
|
||
interface Mutations { | ||
packFormatMapping(state: State, mapping: ResourcePackFormatMapping): void; | ||
protocolMapping(state: State, mapping: ClientProtocolMapping): void; | ||
} | ||
type C = Context<State, Getters, Mutations, Actions>; | ||
interface Actions { | ||
} | ||
} | ||
export interface ClientModule extends Module<"client", ClientModule.State, ClientModule.Getters, ClientModule.Mutations, ClientModule.Actions> { } | ||
|
||
declare const mod: ClientModule; | ||
|
||
export default mod; |
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,34 @@ | ||
import { isCompatible } from 'universal/utils/versions'; | ||
/** | ||
* @type {import('./client').ClientModule} | ||
*/ | ||
const mod = { | ||
state: { | ||
protocolMapping: { | ||
protocol: {}, | ||
mcversion: {}, | ||
}, | ||
packFormatMapping: { | ||
mcversion: Object.freeze({ | ||
1: '[1.6, 1.9)', | ||
2: '[1.9, 1.11)', | ||
3: '[1.11, 1.13)', | ||
4: '[1.13,]', | ||
}), | ||
}, | ||
}, | ||
getters: { | ||
isResourcePackCompatible: state => (format, mcversion) => isCompatible(mcversion, | ||
state.packFormatMapping.mcversion[format]), | ||
}, | ||
mutations: { | ||
protocolMapping(state, p) { | ||
state.protocolMapping = Object.freeze(p); | ||
}, | ||
packFormatMapping(state, m) { | ||
state.packFormatMapping = Object.freeze(m); | ||
}, | ||
}, | ||
}; | ||
|
||
export default mod; |
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 was deleted.
Oops, something went wrong.