Skip to content
Draft
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
### Added
- Make nested step construction configurable

### Changed
- Reduced the minimum size of TeleportGround and TouchTrigger to 8
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FlexModule } from '@angular/flex-layout/flex';
import { NgClass } from '@angular/common';
import { ExtendedModule } from '@angular/flex-layout/extended';
import { RowTextComponent } from '../row-text/row-text.component';
import { Helper } from '../../../../../services/phaser/helper';

@Component({
selector: 'app-event-editor',
Expand Down Expand Up @@ -86,7 +87,7 @@ export class EventEditorComponent implements OnChanges, OnInit {
}

ngOnChanges() {
const eventCopy: EventArray = JSON.parse(JSON.stringify(this.eventData));
const eventCopy = Helper.copy(this.eventData) as EventArray;
try {
const {events} = destructureEventArray(eventCopy);
this.workingData = events?.map((val: EventType) => this.helper.getEventFromType(val, this.actionStep)) ?? [];
Expand Down Expand Up @@ -335,7 +336,7 @@ export class EventEditorComponent implements OnChanges, OnInit {
if (this.copiedNode) {
this.history.add(this.getParent(this.selectedNode));

const cpy = JSON.parse(JSON.stringify(this.copiedNode.data?.export()));
const cpy = Helper.copy(this.copiedNode.data?.export());
const event = this.helper.getEventFromType(cpy, this.actionStep);

const index = !this.selectedNode ? 0 : this.getIndex(this.selectedNode!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DomSanitizer } from '@angular/platform-browser';
import { BehaviorSubject } from 'rxjs';
import { AbstractEvent, EventType } from '../event-registry/abstract-event';
import { EventRegistryService } from '../event-registry/event-registry.service';
import { SelectRandomData } from '../event-registry/select-random';

@Injectable({
providedIn: 'root'
Expand All @@ -18,36 +17,17 @@ export class EventHelperService {
public getEventFromType(val: EventType, actionStep: boolean): AbstractEvent<any> {
const eventClass = this.eventRegistry.getEvent(val.type);
const instance: AbstractEvent<any> = new eventClass(this.domSanitizer, val, actionStep);

if (val.type === 'IF') {
const valIf = val as any;
valIf.thenStep = valIf.thenStep.map((v: EventType) => this.getEventFromType(v, actionStep));
if (valIf.elseStep) {
valIf.elseStep = valIf.elseStep.map((v: EventType) => this.getEventFromType(v, actionStep));
}
} else if (val.type === 'SHOW_CHOICE' || val.type === 'SHOW_MODAL_CHOICE') {
const valChoice = val as any;
valChoice.options.forEach((option: any, index: number) => {
valChoice[index] = valChoice[index].map((v: EventType) => this.getEventFromType(v, actionStep));
});
} else if (val.type === 'SELECT_RANDOM') {
const valRandom = val as SelectRandomData;
valRandom.options.forEach((option, optionIndex) => {
for (let branch = 0; branch < option.count; branch++) {
const key = optionIndex + '_' + branch as `${number}_${number}`;
valRandom[key] = valRandom[key].map((v) => this.getEventFromType(v as any, actionStep));

const branchNames = instance.getBranchNames();
if (branchNames) {
const valAny = val as any;
for (const name of branchNames) {
const opt = valAny[name];
if (!Array.isArray(opt)) {
continue;
}
});
} else if (val.type === 'START_NPC_TRADE_MENU') {
const valTradeMenu = val as any;
if (valTradeMenu.withBranches) {
valTradeMenu.traded = (valTradeMenu.traded ?? []).map((v: EventType) => this.getEventFromType(v, actionStep));
valTradeMenu.canceled = (valTradeMenu.canceled ?? []).map((v: EventType) => this.getEventFromType(v, actionStep));
valAny[name] = opt.map((v: EventType) => this.getEventFromType(v, actionStep));
}
} else if (val.type === 'OPEN_QUEST_DIALOG') {
const valQuestDialog = val as any;
valQuestDialog.accepted = valQuestDialog.accepted.map((v: EventType) => this.getEventFromType(v, actionStep));
valQuestDialog.declined = valQuestDialog.declined.map((v: EventType) => this.getEventFromType(v, actionStep));
}

instance.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PartialPoint3, Point, Point3 } from '../../../../models/cross-code-map'
import { Label } from '../../../../models/events';
import { ColorService } from '../../../../services/color.service';
import { EntityAttributes } from '../../../../services/phaser/entities/cc-entity';
import { Helper } from '../../../../services/phaser/helper';

export type WMTypeNames = 'Action'
| 'Actor'
Expand Down Expand Up @@ -104,7 +105,6 @@ export type WMTypeNames = 'Action'
| 'WalkAnimConfig'
| 'XenoDialog';


export namespace WMTypes {
export type VarExpression<T> =
T |
Expand Down Expand Up @@ -189,10 +189,14 @@ export abstract class AbstractEvent<T extends EventType> {

public abstract getAttributes(): EntityAttributes | undefined;

public getBranchNames(): string[] | undefined {
return undefined;
};

public abstract update(): void;

public export(): T {
return JSON.parse(JSON.stringify(this.data));
return Helper.copy(this.data);
}

protected combineStrings(...values: string[]): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DomSanitizer } from '@angular/platform-browser';
import { AttributeValue, EntityAttributes } from '../../../../services/phaser/entities/cc-entity';
import { AbstractEvent, EventType } from './abstract-event';
import { Globals } from '../../../../services/globals';
import { Helper } from '../../../../services/phaser/helper';

export interface ActionsJson {
[key: string]: JsonEventType;
Expand All @@ -15,10 +16,16 @@ interface DefaultEventData extends EventType {
[key: string]: any;
}

export interface BranchesData {
type: 'list';
names: string[];
}

interface JsonEventType {
attributes: {
[key: string]: { noLabel: boolean } & AttributeValue;
};
branches?: BranchesData;
}

export class DefaultEvent<T extends EventType = DefaultEventData> extends AbstractEvent<T> {
Expand All @@ -44,6 +51,18 @@ export class DefaultEvent<T extends EventType = DefaultEventData> extends Abstra
}
return undefined;
}

override getBranchNames(): string[] | undefined {
const branchData = this.type?.branches;
if (!branchData) {
return undefined;
}
if (branchData.type === 'list') {
return branchData.names;
} else {
throw new Error('unhandled branchData type');
}
}

update() {
this.info = this.getTypeString('#ff5a5b');
Expand All @@ -60,6 +79,31 @@ export class DefaultEvent<T extends EventType = DefaultEventData> extends Abstra
this.info += ' ' + this.getPropString(key);
}
}

const branchNames = this.getBranchNames() ?? [];
for (let i = 0; i < branchNames.length; i++) {
const branchName = branchNames[i];
const events = this.data[branchName as keyof typeof this.data] as AbstractEvent<any>[] ?? [];
this.children[i] = {
title: branchNames.length > 1 ? branchName : undefined,
events,
draggable: false
};

}
}

override export(): T {
const branchNames = this.getBranchNames();
if (!branchNames) {
return super.export();
}
const newData: any = { ...this.data, };
for (let i = 0; i < branchNames.length; i++) {
const branchName = branchNames[i];
newData[branchName] = this.children[i].events.map(v => v.export());
}
return Helper.copy(newData) as T;
}

protected generateNewDataInternal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class If extends AbstractEvent<IfData> {
getAttributes() {
return this.attributes;
}

override getBranchNames(): string[] | undefined {
return ['thenStep', 'elseStep'];
}

update() {
this.children = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export class OpenQuestDialog extends AbstractEvent<OpenQuestDialogData> {
return this.attributes;
}

override getBranchNames(): string[] | undefined {
return ['accepted', 'declined'];
}

update() {
this.info = this.combineStrings(
this.getTypeString('#7ea3ff'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ export class SelectRandom extends AbstractEvent<SelectRandomData> {
return this.attributes;
}

override getBranchNames(): string[] | undefined {
const branches: string[] = [];
this.data.options.forEach((option, optionIndex) => {
for (let branch = 0; branch < option.count; branch++) {
branches.push(optionIndex + '_' + branch);
}
});
return branches;
}

update() {
this.children = [];
this.info = this.getTypeString('#ffffff');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Helper } from '../../../../services/phaser/helper';
import { Label, Person } from '../../../../models/events';
import { EntityAttributes } from '../../../../services/phaser/entities/cc-entity';
import { AbstractEvent, EventType } from './abstract-event';
import { DefaultEvent } from './default-event';

Expand All @@ -17,6 +15,10 @@ export interface ShowChoiceData extends EventType {
}

export class ShowChoice extends DefaultEvent<ShowChoiceData> {
override getBranchNames(): string[] | undefined {
return Object.keys(this.data.options);
}

override update() {
this.children = [];
this.info = this.combineStrings(
Expand All @@ -33,25 +35,6 @@ export class ShowChoice extends DefaultEvent<ShowChoiceData> {
});
}


override export(): ShowChoiceData {
const out: ShowChoiceData = {
type: this.data.type,
person: this.data.person,
options: this.data.options,
columns: this.data.columns,
forceWidth: this.data.forceWidth
};
this.children.forEach((child, index) => {
if (!child.events) {
console.error('wtf', this);
}
out[index] = child.events.map(v => v.export());
});

return Helper.copy(out);
}

protected override generateNewDataInternal() {
return {
person: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Helper } from '../../../../services/phaser/helper';
import { Label } from '../../../../models/events';
import { AbstractEvent, EventType } from './abstract-event';
import { DefaultEvent } from './default-event';
Expand All @@ -13,6 +12,10 @@ export interface ShowModalChoiceData extends EventType {
}

export class ShowModalChoice extends DefaultEvent<ShowModalChoiceData> {
override getBranchNames(): string[] | undefined {
return Object.keys(this.data.options);
}

override update() {
this.children = [];
this.info = this.combineStrings(
Expand All @@ -29,22 +32,6 @@ export class ShowModalChoice extends DefaultEvent<ShowModalChoiceData> {
});
}

override export(): ShowModalChoiceData {
const out: ShowModalChoiceData = {
type: this.data.type,
text: this.data.text,
options: this.data.options,
};
this.children.forEach((child, index) => {
if (!child.events) {
console.error('wtf', this);
}
out[index] = child.events.map(v => v.export());
});

return Helper.copy(out);
}

protected override generateNewDataInternal() {
return {
text: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ interface ShowSideMsgData extends EventType {
}

export class ShowSideMsg extends DefaultEvent<ShowSideMsgData> {

override update() {
this.info = this.combineStrings(
this.getTypeString('#fa5aff'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class StartNpcTradeMenu extends AbstractEvent<StartNpcTradeMenuData> {
getAttributes(): EntityAttributes {
return this.attributes;
}

override getBranchNames(): string[] | undefined {
return ['traded', 'canceled'];
}

update() {
this.children.length = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { OverlayService } from '../../dialogs/overlay/overlay.service';
import { AbstractWidget } from '../abstract-widget';
import { EventType, WMTypes } from '../event-widget/event-registry/abstract-event';
import { NpcStatesComponent } from './npc-states/npc-states.component';
import { Helper } from '../../../services/phaser/helper';

export interface NPCState {
reactType: string;
Expand Down Expand Up @@ -76,7 +77,7 @@ export class NPCStatesWidgetComponent extends AbstractWidget implements OnInit,

this.ref = obj.ref;

obj.instance.states = JSON.parse(JSON.stringify(this.npcStates));
obj.instance.states = Helper.copy(this.npcStates);

obj.instance.exit.subscribe((v: any) => {
obj.ref.close();
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/app/services/height-map/gfx-mapper/gfx-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Point } from '../../../models/cross-code-map';
import { Helper } from '../../phaser/helper';
import { GFX_TYPE } from '../heightmap.constants';
import { ChipsetBase, ChipsetConfig, GfxMap, GfxMaps, GFX_MAPS } from './gfx-mapper.constants';

Expand All @@ -23,7 +24,7 @@ export class GfxMapper {
}

private copySettings(mappingSettings: ChipsetBase) {
const result: ChipsetMapping = JSON.parse(JSON.stringify(mappingSettings));
const result = Helper.copy(mappingSettings) as ChipsetMapping;
if (mappingSettings.mappingType) {
result.mapping = GFX_MAPS[mappingSettings.mappingType];
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/app/services/phaser/entities/cc-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export abstract class CCEntity extends BaseObject {
level: this.details.level.offset ? this.details.level : this.details.level.level,
settings: this.details.settings,
};
return JSON.parse(JSON.stringify(out));
return Helper.copy(out);
}

public abstract getScaleSettings(): ScaleSettings | undefined;
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/app/tests/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CrossCodeMap } from '../models/cross-code-map';
import { AssetsAccessService } from '../services/assets-access.service';
import { MapLoaderService } from '../services/map-loader.service';
import { CCMap } from '../services/phaser/tilemap/cc-map';
import { Helper } from '../services/phaser/helper';

export class TestHelper {
// the editor waits for an assets folder before it loads anything, tests use an empty one
Expand All @@ -16,7 +17,7 @@ export class TestHelper {
public static async loadMap(service: MapLoaderService, map: CrossCodeMap): Promise<{ imported: CrossCodeMap, ccmap: CCMap }> {
// needs to wait for the map to actually load
const loaded = firstValueFrom(service.tileMap.pipe(skip(1)));
await service.loadRawMap(JSON.parse(JSON.stringify(map)));
await service.loadRawMap(Helper.copy(map));
return { imported: map, ccmap: (await loaded)! };
}
}
Loading