Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/AppMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import ModalGotoCoords from '@/components/ModalGotoCoords.vue';
import ObjectInfo from '@/components/ObjectInfo.vue';

import { MapMgr, ObjectData, ObjectMinData } from '@/services/MapMgr';
import { MsgMgr } from '@/services/MsgMgr';
import { MetaMgr } from '@/services/MetaMgr';

import * as map from '@/util/map';
import { Point } from '@/util/map';
Expand Down Expand Up @@ -1353,8 +1353,8 @@ export default defineComponent({
for (const layer of layers) {
let label = (name == "MapTower") ? mapTowerAreas[parseInt(data)] : 'Area ' + data.toString();
if (name == 'FieldMapArea') {
const area = await MsgMgr.getInstance().getAreaData(parseInt(data));
const climate = await MsgMgr.getInstance().getClimateData(climate_names.indexOf(area.Climate));
const area = await MetaMgr.getInstance().getAreaData(parseInt(data));
const climate = await MetaMgr.getInstance().getClimateData(climate_names.indexOf(area.Climate));
for (const kind of ['Bluesky', 'Cloudy', 'Rain', 'HeavyRain', 'Storm']) {
const name = `Weather${kind}Rate`;
if (climate[name] > 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/ObjectInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineComponent, PropType } from 'vue';
import { rankUpEnemyForHardMode } from '@/level_scaling';
import MixinUtil from '@/components/MixinUtil';
import { MsgMgr } from '@/services/MsgMgr';
import { MetaMgr } from '@/services/MetaMgr';
import { ObjectData, ObjectMinData, PlacementLink } from '@/services/MapMgr';

export default defineComponent({
Expand Down Expand Up @@ -45,7 +46,7 @@ export default defineComponent({
async loadMetaIfNeeded(): Promise<void> {
if (!this.metadata) {
const data = this.data;
const metadata = await MsgMgr.getInstance().getObjectMetaData(this.getRankedUpActorNameForObj(data));
const metadata = await MetaMgr.getInstance().getObjectMetaData(this.getRankedUpActorNameForObj(data));
if (data === this.data)
this.metadata = metadata;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import router from './router';

import { MapMgr } from '@/services/MapMgr';
import { MsgMgr } from '@/services/MsgMgr';
import { MetaMgr } from '@/services/MetaMgr';
import { vTooltip } from '@/util/tooltip';

async function main() {
Expand All @@ -21,6 +22,7 @@ async function initServices() {
await Promise.all([
MsgMgr.getInstance().init(),
MapMgr.getInstance().init(),
MetaMgr.getInstance().init(),
]);
}

Expand Down
49 changes: 49 additions & 0 deletions src/services/MetaMgr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { GAME_FILES } from '@/util/map';

type File = { [label: string]: any };

const metaFileList = {
'area': 'area_data.json',
'climate': 'climate_data.json',
'metadata': 'object_meta.json'
};

export class MetaMgr {
private static instance: MetaMgr;
static getInstance() {
if(!this.instance) {
this.instance = new this()
}
return this.instance;
}

private files: Map<string, File> = new Map();

async init() {
const fileLoadPromises = []
for(const [file, path] of Object.entries(metaFileList)) {
fileLoadPromises.push(fetch(GAME_FILES + '/' + path).then(r => r.json()).then((d) => {
this.files.set(file, Object.freeze(d))
}))
}
await Promise.all( fileLoadPromises )
}
private getFile(file: string) {
return this.files.get(file)
}
getClimateData(item: number) {
const data = this.getFile('climate');
if(!data) { return }
return data[`ClimateDefines_${item}`];
}
getAreaData(item: number) {
const data = this.getFile('area')
if(!data) { return }
return data.find((val: any) => val.AreaNumber == item);
}
getObjectMetaData(item: string): any {
const data = this.getFile('metadata');
if(!data) { return }
return data[item]
}
}
33 changes: 0 additions & 33 deletions src/services/MsgMgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export class MsgMgr {

private names: { [actorName: string]: string } = {};
private files: Map<string, File> = new Map();
private climate: any | null = null;
private area: any | null = null;
private metadata: any | null = null;

async init() {
const PREFIX = `${GAME_FILES}/text/`;
Expand All @@ -41,36 +38,6 @@ export class MsgMgr {
return f === undefined ? "???" : f[label];
}

async getAreaData(item: number) {
if (!this.area) {
const res = await fetch(`${GAME_FILES}/area_data.json`);
this.area = await res.json();
}
if (this.area) {
return this.area.find((val: any) => val.AreaNumber == item);
}
return null;
}

async getClimateData(item: number) {
if (!this.climate) {
const res = await fetch(`${GAME_FILES}/climate_data.json`);
this.climate = await res.json();
}
if (this.climate) {
return this.climate[`ClimateDefines_${item}`];
}
return null;
}

async getObjectMetaData(item: string) {
if (!this.metadata) {
const res = await fetch(`${GAME_FILES}/object_meta.json`);
this.metadata = await res.json();
}
return this.metadata[item];
}

/// Get a message by its message ID (e.g. EventFlowMsg/AncientBall_Kakariko:Label).
getMsg(id: string): string {
const [file, label] = id.split(':');
Expand Down
Loading