Skip to content

Commit

Permalink
remove text format create functional from calc
Browse files Browse the repository at this point in the history
  • Loading branch information
userXinos committed Jan 14, 2024
1 parent 98d7db2 commit d0b118f
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 73 deletions.
1 change: 0 additions & 1 deletion i18n/locales/en/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"COPIED": "Copied",
"CREATE": "Create",
"LIST": "List",
"FROM_TEXT_FORMAT": "From text format (optional)",
"REMOVE_CONFIG": "Delete \"{0}\" configuration ?",
"UPDATED": "Updated",
"CURRENT_VERSION": "Current version",
Expand Down
46 changes: 3 additions & 43 deletions src/components/Calculator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</div>

<MultiConfigGUI
:on-create-new="() => openNewModal = true"
:on-create-new="createConfig"
:instance="ConfigManager"
:data-to-string="ConfigManager.selectedConfig.actually"
/>
Expand All @@ -107,31 +107,6 @@

</Modal>

<Modal
v-model:open="openNewModal"
:title="$t('CREATE')"
:size="SIZES.SMALL"
>
<template #body>
<div class="input">
<p
v-t="'FROM_TEXT_FORMAT'"
class="name"
/>
<p class="name">Example: Fortify 8 Bond 5</p>
<input v-model="newConfigFromText">
</div>

<div class="flex-end margin-bottom">
<button
v-t="'TID_OK'"
class="button green"
@click="createConfig"
/>
</div>
</template>
</Modal>

<Modal
v-model:open="openInfo"
:title="$t('TID_MORE_INFO_BTN')"
Expand Down Expand Up @@ -210,14 +185,11 @@ const setupArgs: SetupComponent = {
format: format,
Config: ConfigManager.store,
provideGetterElements: (cb: SetupGetElementsCB) =>
provideGetterElements((...args) => cb(ConfigManager.TIDs, ...args)),
provideGetterElements: (cb: SetupGetElementsCB) => provideGetterElements(cb),
};
const settingsModal = ref(false);
const openNewModal = ref(false);
const openInfo = ref(false);
const newConfigFromText = ref('');
const title = computed(() => t(props.titleKey));
const totalResultKeys = computed(() => Object.keys(output.total.result));
Expand Down Expand Up @@ -271,19 +243,7 @@ async function onReset(event: Event): Promise<void> {
ConfigManager.save();
}
async function createConfig(): Promise<void> {
let parsed = {};
if (newConfigFromText.value) {
await ConfigManager.parseString(newConfigFromText.value)
.then((data) => parsed = data)
.catch((err) => {
alert(err.message);
console.error(err);
});
}
ConfigManager.add({ actually: { ...parsed }, plan: { ...parsed } });
newConfigFromText.value = '';
openNewModal.value = false;
ConfigManager.add({ actually: { }, plan: { } });
fullUpdate();
}
function totalTableClasses(type: string, key: string): object {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/ModulesCalc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function calcTotal(store: ElementsStore, output: Output) {
val.result.ReqBank = (UnlockPrice > val.result.ReqBank) ? UnlockPrice : val.result.ReqBank;
};
}
function getModulesBySlotType(type: string, ...[TIDs, getChars, elements]: Parameters<SetupGetElementsCB>) {
function getModulesBySlotType(type: string, ...[getChars, elements]: Parameters<SetupGetElementsCB>) {
const modules = getBySlotType(type) as OutputMap;
return Object.entries(modules).map(([name, module]: [string, OutputMap]) => {
Expand All @@ -289,7 +289,6 @@ function getModulesBySlotType(type: string, ...[TIDs, getChars, elements]: Param
}
elements[name] = getChars((modules as {[k: string]: object})[name] as OutputValue, MaxModuleLevel);
TIDs[name] = module.TID;
return [module, MaxModuleLevel];
});
Expand Down
4 changes: 1 addition & 3 deletions src/pages/PlanetsCalc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function calcTotal(store: ElementsStore, output: Output) {
}
};
}
function getPlanets(...[TIDs, getChars, elements]: Parameters<SetupGetElementsCB>): unknown[] {
function getPlanets(...[getChars, elements]: Parameters<SetupGetElementsCB>): unknown[] {
type TS = {
Name: string,
MaxUpgradeLevel?: number,
Expand Down Expand Up @@ -335,8 +335,6 @@ function getPlanets(...[TIDs, getChars, elements]: Parameters<SetupGetElementsCB
},
});
TIDs[name] = planet.TID;
return [name, planet];
},
});
Expand Down
3 changes: 1 addition & 2 deletions src/typings/calculator.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import MultiConfig from '@Utils/MultiConfig';
import { Callback as mapFn } from '@Utils/objectArrayify';

// Core
Expand Down Expand Up @@ -47,7 +46,7 @@ export interface Config {

// Component
type keyInput = keyof Input;
export type SetupGetElementsCB = (TIDs: MultiConfig['TIDs'], ...args: Parameters<getElementsCB>) => unknown
export type SetupGetElementsCB = (...args: Parameters<getElementsCB>) => unknown
export interface SetupComponent {
output: Output,
isSelected: (type: keyInput, key: string, value: number) => boolean,
Expand Down
22 changes: 0 additions & 22 deletions src/utils/MultiConfig.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { reactive } from 'vue';
import i18n from '@Utils/Vue/i18n';
import { loadLocaleMessages } from '@Utils/Vue/i18n';
import JSONCrush from 'jsoncrush';

const NAME_ZERO = 'default entry';
const STRING_FORMAT_LOCALE = 'en';

interface Store<Value> {
configs: { name: string, temporary?: boolean, value: Value }[],
Expand All @@ -14,8 +11,6 @@ interface Store<Value> {
export default class MultiConfig<ConfigValue> {
public readonly store: Store<ConfigValue>;

public readonly TIDs: Record<string, string> = {};

constructor(private readonly localStoreKey: string, private readonly zeroConfig: ConfigValue) {
this.store = reactive({ configs: [], selected: 0 }) as Store<ConfigValue>;
this.load();
Expand Down Expand Up @@ -74,23 +69,6 @@ export default class MultiConfig<ConfigValue> {
}
}

public async parseString(text: string) {
const entries: [string, number][] = [];

if (!(i18n.global.availableLocales as string[]).includes(STRING_FORMAT_LOCALE)) {
await loadLocaleMessages(STRING_FORMAT_LOCALE);
}

for (const [key, TID] of Object.entries(this.TIDs)) {
const name = i18n.global.t(TID, STRING_FORMAT_LOCALE);
const regex = new RegExp(`${name}\\s+?(\\d+)\\s?`, 'mi'); // EMP 99
const [, lvl] = text.match(regex) || [undefined, '0'];

entries.push([key, parseInt(lvl as string)]);
}
return Object.fromEntries(entries.filter(([, l]) => l));
}

public static stringifyUrl(obj: object): string {
const json = JSON.stringify(obj);
return JSONCrush.crush(json);
Expand Down

0 comments on commit d0b118f

Please sign in to comment.