Skip to content

Commit

Permalink
closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 12, 2024
1 parent 7035ca4 commit d0de684
Show file tree
Hide file tree
Showing 17 changed files with 615 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/app/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './id';
export * from './item';
export * from './npc';
export * from './recipe';
export * from './spawner';
33 changes: 33 additions & 0 deletions src/app/helpers/spawner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ISpawnerData } from '../../interfaces';
import { id } from './id';

export const defaultSpawner: () => ISpawnerData = () => ({
_id: id(),
tag: '',
paths: [],
shouldSerialize: false,
alwaysSpawn: false,
requireDeadToRespawn: false,
doInitialSpawnImmediately: false,
canSlowDown: true,
isDangerous: false,
npcAISettings: [],
npcIds: [],
respawnRate: 120,
randomWalkRadius: 10,
leashRadius: 20,
eliteTickCap: 50,
initialSpawn: 0,
spawnRadius: 0,
maxCreatures: 5,
stripRadius: 0,
stripX: 0,
stripY: 0,
shouldEatTier: 0,
shouldStrip: false,
stripOnSpawner: false,
respectKnowledge: true,
attributeAddChance: 0,
requireHoliday: undefined as unknown as string,
_paths: '',
});
4 changes: 3 additions & 1 deletion src/app/home/home.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { RecipesEditorComponent } from '../tabs/recipes/recipes-editor/recipes-e
import { RecipesComponent } from '../tabs/recipes/recipes.component';
import { SpawnersComponent } from '../tabs/spawners/spawners.component';
import { HomeComponent } from './home.component';
import { SpawnersEditorComponent } from '../tabs/spawners/spawners-editor/spawners-editor.component';

@NgModule({
declarations: [
Expand All @@ -37,6 +38,7 @@ import { HomeComponent } from './home.component';
RecipesEditorComponent,
SpawnersComponent,
NpcsEditorComponent,
SpawnersEditorComponent,
],
imports: [
CommonModule,
Expand All @@ -47,6 +49,6 @@ import { HomeComponent } from './home.component';
NgxFloatUiModule,
NgIconsModule,
],
exports: [NpcsEditorComponent],
exports: [NpcsEditorComponent, SpawnersEditorComponent],
})
export class HomeModule {}
35 changes: 31 additions & 4 deletions src/app/services/mod.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
IModKit,
INPCDefinition,
IRecipe,
ISpawnerData,
} from '../../interfaces';

export function defaultModKit(): IModKit {
Expand Down Expand Up @@ -39,6 +40,7 @@ export class ModService {
public modName = computed(() => this.mod().meta.name);
public modAuthor = computed(() => this.mod().meta.author);

public availableNPCs = computed(() => this.mod().npcs);
public availableItems = computed(() => this.mod().items);
public availableMaps = computed(() => this.mod().maps);

Expand Down Expand Up @@ -200,7 +202,7 @@ export class ModService {

public removeItem(item: IItemDefinition) {
const mod = this.mod();
mod.items = mod.items.filter((i) => i !== item);
mod.items = mod.items.filter((i) => i._id !== item._id);

this.updateMod(mod);
}
Expand Down Expand Up @@ -230,7 +232,7 @@ export class ModService {

public removeDroptable(item: IDroptable) {
const mod = this.mod();
mod.drops = mod.drops.filter((i) => i !== item);
mod.drops = mod.drops.filter((i) => i._id !== item._id);

this.updateMod(mod);
}
Expand All @@ -255,7 +257,7 @@ export class ModService {

public removeRecipe(item: IRecipe) {
const mod = this.mod();
mod.recipes = mod.recipes.filter((i) => i !== item);
mod.recipes = mod.recipes.filter((i) => i._id !== item._id);

this.updateMod(mod);
}
Expand All @@ -280,7 +282,32 @@ export class ModService {

public removeNPC(npc: INPCDefinition) {
const mod = this.mod();
mod.npcs = mod.npcs.filter((i) => i !== npc);
mod.npcs = mod.npcs.filter((i) => i._id !== npc._id);

this.updateMod(mod);
}

// spawner functions
public addSpawner(spawner: ISpawnerData) {
const mod = this.mod();
mod.spawners.push(spawner);

this.updateMod(mod);
}

public editSpawner(oldSpawner: ISpawnerData, newSpawner: ISpawnerData) {
const mod = this.mod();
const foundItemIdx = mod.npcs.findIndex((i) => i._id === oldSpawner._id);
if (foundItemIdx === -1) return;

mod.spawners[foundItemIdx] = newSpawner;

this.updateMod(mod);
}

public removeSpawner(spawner: ISpawnerData) {
const mod = this.mod();
mod.spawners = mod.spawners.filter((i) => i._id !== spawner._id);

this.updateMod(mod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class InputHolidayComponent {
private electronService = inject(ElectronService);
private modService = inject(ModService);

public holiday = model.required<string>();
public holiday = model.required<string | undefined>();
public label = input<string>('Holiday');
public change = output<string>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div class="relative">
{{ item | json }}
<ng-select class="form-control" [items]="values()" bindValue="data" groupBy="category" [(ngModel)]="item"
placeholder="Select item..." (change)="change.emit($event?.value)" [compareWith]="itemCompare" [searchFn]="search">

Expand Down
29 changes: 29 additions & 0 deletions src/app/shared/components/input-npc/input-npc.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="relative">
<ng-select class="form-control" [items]="values()" bindValue="data" groupBy="category" [(ngModel)]="npc"
placeholder="Select NPC..." (change)="change.emit($event?.value)" [compareWith]="npcCompare" [searchFn]="search">

<ng-template ng-label-tmp let-item="item">
<div class="relative">
@if(item.data) {
<app-sprite class="absolute -top-5 -left-5" [scale]="0.5" [type]="'creatures'"
[sprite]="item.data.sprite"></app-sprite>
}
<div class="ml-7 text-white">
{{ item.data.npcId }}
</div>
</div>
</ng-template>

<ng-template ng-option-tmp let-item="item">
<div class="relative">
<app-sprite class="absolute -top-5 -left-7" [scale]="0.5" [type]="'creatures'"
[sprite]="item.data.sprite"></app-sprite>
<div class="ml-5 text-white">
{{ item.data.npcId }}
</div>
</div>
</ng-template>
</ng-select>

<app-input-floating-label>{{ label() }}</app-input-floating-label>
</div>
Empty file.
55 changes: 55 additions & 0 deletions src/app/shared/components/input-npc/input-npc.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
Component,
computed,
inject,
input,
model,
OnInit,
output,
} from '@angular/core';
import { INPCDefinition } from '../../../../interfaces';
import { ModService } from '../../../services/mod.service';

type NPCModel = { category: string; data: INPCDefinition; value: string };

@Component({
selector: 'app-input-npc',
templateUrl: './input-npc.component.html',
styleUrl: './input-npc.component.scss',
})
export class InputNpcComponent implements OnInit {
private modService = inject(ModService);

public npc = model.required<INPCDefinition | undefined>();
public label = input<string>('NPC');
public defaultValue = input<string>();
public change = output<string>();

public values = computed(() => {
const mod = this.modService.mod();

return [
...mod.npcs.map((i) => ({
category: 'My Mod NPCs',
data: i,
value: i.npcId,
})),
];
});

ngOnInit() {
const defaultItem = this.defaultValue();
if (defaultItem) {
const foundItem = this.values().find((i) => i.value === defaultItem);
this.npc.set(foundItem as unknown as INPCDefinition);
}
}

public itemCompare(itemA: NPCModel, itemB: NPCModel): boolean {
return itemA.value === itemB.value;
}

public search(term: string, item: { value: string }) {
return item.value.toLowerCase().includes(term.toLowerCase());
}
}
3 changes: 3 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { InputCategoryComponent } from './components/input-category/input-catego
import { InputChallengeratingComponent } from './components/input-challengerating/input-challengerating.component';
import { InputItemslotComponent } from './components/input-itemslot/input-itemslot.component';
import { InputSfxComponent } from './components/input-sfx/input-sfx.component';
import { InputNpcComponent } from './components/input-npc/input-npc.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -74,6 +75,7 @@ import { InputSfxComponent } from './components/input-sfx/input-sfx.component';
InputChallengeratingComponent,
InputItemslotComponent,
InputSfxComponent,
InputNpcComponent,
],
imports: [
CommonModule,
Expand Down Expand Up @@ -117,6 +119,7 @@ import { InputSfxComponent } from './components/input-sfx/input-sfx.component';
InputChallengeratingComponent,
InputItemslotComponent,
InputSfxComponent,
InputNpcComponent,
],
})
export class SharedModule {}
Loading

0 comments on commit d0de684

Please sign in to comment.