Skip to content

Commit

Permalink
add achievement editor, fix other bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Sep 22, 2024
1 parent c4a6ed6 commit b7e73df
Show file tree
Hide file tree
Showing 31 changed files with 666 additions and 38 deletions.
45 changes: 45 additions & 0 deletions src/app/helpers/achievement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
BaseClassType,
IAchievement,
IAchievementRequirements,
SkillType,
TradeskillType,
} from '../../interfaces';
import { id } from './id';

export const defaultAchievementRequirements: () => IAchievementRequirements =
() => ({
bindItem: {
item: '',
},
kill: {
npc: '',
},
level: {
baseClass: undefined as unknown as BaseClassType,
level: 0,
},
skill: {
level: 0,
skill: undefined as unknown as SkillType,
},
tradeskill: {
level: 0,
tradeskill: undefined as unknown as TradeskillType,
},
});

export const defaultAchievement: () => IAchievement = () => ({
_id: id(),
ap: 0,
desc: '',
icon: 'uncertainty',
iconColor: '',
iconBgColor: '',
iconBorderColor: '',
activationType: 'other',
hidden: false,
name: '',
requirements: defaultAchievementRequirements(),
shareWithParty: false,
});
1 change: 1 addition & 0 deletions src/app/helpers/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function formatMod(modData: IModKit): IModKit {
cores: modData.cores,
stems: modData.stems,
traitTrees: modData.traitTrees,
achievements: modData.achievements,
};

return exported;
Expand Down
1 change: 1 addition & 0 deletions src/app/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './achievement';
export * from './constants';
export * from './core';
export * from './dialog';
Expand Down
10 changes: 10 additions & 0 deletions src/app/helpers/schemas/_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from 'lodash';
import {
Allegiance,
BaseClass,
DamageClass,
HasIdentification,
ItemClass,
Expand All @@ -20,6 +21,7 @@ import {
SchemaValidatorMessage,
Skill,
Stat,
Tradeskill,
} from '../../../interfaces';

const itemSlots = [
Expand Down Expand Up @@ -132,6 +134,10 @@ export function isSkill(val: any): boolean {
return Object.values(Skill).includes(val as Skill);
}

export function isTradeskill(val: any): boolean {
return Object.values(Tradeskill).includes(val as Tradeskill);
}

export function isItemSlot(val: any): boolean {
return itemSlots.includes(val as ItemSlot);
}
Expand Down Expand Up @@ -239,6 +245,10 @@ export function isRequirement(req: any): boolean {
return !!(req.level || req.baseClass || req.alignment || req.quest);
}

export function isBaseClass(req: any): boolean {
return Object.values(BaseClass).includes(req as BaseClass);
}

export function isSuccor(suc: any): boolean {
return suc.map && isInteger(suc.x) && isInteger(suc.y);
}
Expand Down
38 changes: 38 additions & 0 deletions src/app/helpers/schemas/achievement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { isBoolean, isNumber, isObject, isString } from 'lodash';
import { Schema } from '../../../interfaces';
import { isBaseClass, isSkill, isTradeskill } from './_helpers';

export const achievementSchema: Schema = [
['ap', true, isNumber],
['desc', true, isString],
['name', true, isString],
['hidden', false, isBoolean],
['shareWithParty', false, isBoolean],

['activationType', true, isString],

['icon', true, isString],
['iconColor', true, isString],
['iconBgColor', true, isString],
['iconBorderColor', true, isString],

['requirements', true, isObject],

['requirements.bindItem', true, isObject],
['requirements.bindItem.item', false, isString],

['requirements.kill', true, isObject],
['requirements.kill.npc', false, isString],

['requirements.level', true, isObject],
['requirements.level.baseClass', false, isBaseClass],
['requirements.level.level', false, isNumber],

['requirements.skill', true, isObject],
['requirements.skill.skill', false, isSkill],
['requirements.skill.level', false, isNumber],

['requirements.tradeskill', true, isObject],
['requirements.tradeskill.skill', false, isTradeskill],
['requirements.tradeskill.level', false, isNumber],
];
1 change: 1 addition & 0 deletions src/app/helpers/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './achievement';
export * from './dialog';
export * from './droptable';
export * from './item';
Expand Down
2 changes: 2 additions & 0 deletions src/app/helpers/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
nonexistentItems,
nonexistentNPCs,
nonexistentRecipes,
validateAchievements,
validateDialogs,
validateDialogsItems,
validateDroptables,
Expand Down Expand Up @@ -67,6 +68,7 @@ export function validationMessagesForMod(
validateSTEMs(mod),
validateSTEMProperties(mod),
validateRNGDungeons(mod, classes),
validateAchievements(mod),
nonexistentItems(mod),
nonexistentNPCs(mod),
nonexistentRecipes(mod),
Expand Down
30 changes: 30 additions & 0 deletions src/app/helpers/validators/achievement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
IAchievement,
IModKit,
ValidationMessage,
ValidationMessageGroup,
} from '../../../interfaces';
import { achievementSchema } from '../schemas';
import { validateSchema } from '../schemas/_helpers';

export function validateAchievements(mod: IModKit): ValidationMessageGroup {
const itemValidations: ValidationMessageGroup = {
header: 'Invalid Achievements',
messages: [],
};

mod.achievements.forEach((item) => {
const failures = validateSchema<IAchievement>(
item.name,
item,
achievementSchema
);
const validationFailures: ValidationMessage[] = failures.map((f) => ({
type: 'error',
message: f,
}));
itemValidations.messages.push(...validationFailures);
});

return itemValidations;
}
1 change: 1 addition & 0 deletions src/app/helpers/validators/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './achievement';
export * from './autogenerated';
export * from './dialog';
export * from './droptable';
Expand Down
4 changes: 4 additions & 0 deletions src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
<app-trait-trees class="h-full"></app-trait-trees>
}

@case (11) {
<app-achievements class="h-full"></app-achievements>
}

}
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export class HomeComponent implements OnInit {
name: 'Trait Trees',
count: computed(() => this.modService.mod().traitTrees.length),
},
{
name: 'Achievements',
count: computed(() => this.modService.mod().achievements.length),
},
];

constructor() {}
Expand Down
10 changes: 6 additions & 4 deletions src/app/home/home.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { NgxFloatUiModule } from 'ngx-float-ui';

import { AnalysisComponent } from '../analysis/analysis.component';
import { PinpointComponent } from '../pinpoint/pinpoint.component';
import { QueryComponent } from '../query/query.component';
import { SharedModule } from '../shared/shared.module';
import { AchievementsEditorComponent } from '../tabs/achievements/achievements-editor/achievements-editor.component';
import { AchievementsComponent } from '../tabs/achievements/achievements.component';
import { CoresEditorComponent } from '../tabs/cores/cores-editor/cores-editor.component';
import { CoresComponent } from '../tabs/cores/cores.component';
import { DialogsEditorComponent } from '../tabs/dialogs/dialogs-editor/dialogs-editor.component';
Expand All @@ -36,7 +39,6 @@ import { TraitTreesEditorComponent } from '../tabs/trait-trees/trait-trees-edito
import { TraitTreesComponent } from '../tabs/trait-trees/trait-trees.component';
import { ValidationComponent } from '../validation/validation.component';
import { HomeComponent } from './home.component';
import { QueryComponent } from '../query/query.component';

@NgModule({
declarations: [
Expand All @@ -61,6 +63,8 @@ import { QueryComponent } from '../query/query.component';
CoresEditorComponent,
TraitTreesComponent,
TraitTreesEditorComponent,
AchievementsComponent,
AchievementsEditorComponent,
StemsComponent,
StemsEditorComponent,
PinpointComponent,
Expand All @@ -78,8 +82,6 @@ import { QueryComponent } from '../query/query.component';
CodeEditorModule,
ColorPickerModule,
],
exports: [
QueryComponent
],
exports: [QueryComponent],
})
export class HomeModule {}
1 change: 1 addition & 0 deletions src/app/services/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class ElectronService {
// the mod has no backup, which means it was a clean export. it might need some reformatting to get it back in
window.api.receive('loadmod', (mod: IModKit) => {
const importedMod = importMod(mod);
this.modService.migrateMod(importedMod);
this.modService.updateMod(importedMod);
tryEnsureMaps();

Expand Down
Loading

0 comments on commit b7e73df

Please sign in to comment.