Skip to content

Commit

Permalink
Consolidate the individual parts of a logic dump
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Apr 21, 2024
1 parent 8b63b7b commit 5e3d7b3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/ImportExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ async function importState(importedState: ExportState, dispatch: AppDispatch) {
alert('invalid source');
return;
}
const { requirements, locations, hints, options } = await LogicLoader.loadLogicFiles(source);
const { rawLogic, options } = await LogicLoader.loadLogicFiles(source);

importedState.state.settings ??= defaultSettings(options);

const logic = new Logic(requirements, locations, hints, importedState.state.settings);
const logic = new Logic(rawLogic, importedState.state.settings);
const state = importedState.state;

dispatch(loadTracker(state));
Expand Down
4 changes: 2 additions & 2 deletions src/TrackerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export default function TrackerContainer() {
async (source: string) => {
setLoadingSource(source);
try {
const { requirements, locations, hints, options } = await LogicLoader.loadLogicFiles(source);
const { rawLogic, options } = await LogicLoader.loadLogicFiles(source);
const path = new URLSearchParams(window.location.search);
const permalink = decodeURIComponent(path.get('options')!);
const settings = decodePermalink(options, permalink);
const logic = new Logic(requirements, locations, hints, settings);
const logic = new Logic(rawLogic, settings);
dispatch(reset({ settings }));
dispatch(
loadLogic({ logic, options, source }),
Expand Down
4 changes: 2 additions & 2 deletions src/logic/Logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import crystalLocations from '../data/crystals.json';
import BooleanExpression from './BooleanExpression';
import { completionRequirementToDungeon, splitLocationName } from './Locations';
import { InventoryItem, isItem } from './Inventory';
import { RawHints, RawLocations, RawRequirements } from './UpstreamTypes';
import { Settings } from '../permalink/SettingsTypes';
import { RawLogic } from './LogicLoader';

class Logic {
settings: Settings;
Expand All @@ -21,7 +21,7 @@ class Logic {
cubeList: Record<string, ItemLocation> = {};
crystalList: Record<string, ItemLocation> = {};

constructor(requirements: RawRequirements, locations: RawLocations, hints: RawHints, settings: Settings) {
constructor({ hints, locations, requirements }: RawLogic, settings: Settings) {
this.settings = settings;
this.requirements = new Requirements(requirements);

Expand Down
9 changes: 8 additions & 1 deletion src/logic/LogicLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { RawHints, RawLocations, RawRequirements } from './UpstreamTypes';
import { MultiChoiceOption, Option } from '../permalink/SettingsTypes';
import _ from 'lodash';

/** Raw data loaded from a ssrando repository */
export interface RawLogic {
requirements: RawRequirements,
hints: RawHints,
locations: RawLocations,
}

class LogicLoader {
static async loadLogicFiles(branch: string) {
const [
Expand All @@ -26,7 +33,7 @@ class LogicLoader {
excludedLocs.choices.push(location);
});

return { requirements, locations, hints, options };
return { rawLogic: { requirements, locations, hints }, options };
}

static async loadLogicFile<T>(file: string, branch: string) {
Expand Down

0 comments on commit 5e3d7b3

Please sign in to comment.