Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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
- Added support for SELECT_RANDOM events
- Added missing properties to NPC States

## [2.7.0] 2026-11-24
### Added
- The editor is now available as a website: [ccdirectlink.github.io/crosscode-map-editor](https://ccdirectlink.github.io/crosscode-map-editor/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 @@ -29,6 +30,14 @@ export class EventHelperService {
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));
}
});
} else if (val.type === 'START_NPC_TRADE_MENU') {
const valTradeMenu = val as any;
if (valTradeMenu.withBranches) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export interface EventType {

export interface EventTypeChild {
title?: string;
key?: string;
draggable?: boolean;
events: AbstractEvent<any>[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import { GotoLabel } from './goto-label';
import { If } from './if';
import { Label } from './label';
import { OpenQuestDialog } from './open-quest-dialogue';
import { SelectRandom } from './select-random';
import { SetCameraBetween } from './set-camera-between';
import { SetCameraPos } from './set-camera-pos';
import { SetCameraTarget } from './set-camera-target';
import { SetCameraZoom } from './set-camera-zoom';
import { SetMsgExpression } from './set-msg-expression';
import { SetOverlay } from './set-overlay';
import { SetPlayerCore } from './set-player-core';
import { ShowChoice } from './show-choice';
import { ShowModalChoice } from './show-modal-choice';
import { ShowMsg } from './show-msg';
import { ShowSideMsg } from './show-side-msg';
import { StartNpcTradeMenu } from './start-npc-trade-menu';
import { Wait } from './wait';
import { ShowSideMsg } from './show-side-msg';
import { ShowModalChoice } from './show-modal-choice';
import { SetMsgExpression } from './set-msg-expression';

type EventConstructor<T extends EventType> = new (
domSanitizer: DomSanitizer,
Expand All @@ -42,6 +43,7 @@ export class EventRegistryService {
this.register('ADD_MSG_PERSON', AddMsgPerson);
this.register('SHOW_MSG', ShowMsg);
this.register('SHOW_CHOICE', ShowChoice);
this.register('SELECT_RANDOM', SelectRandom);
this.register('IF', If);
this.register('SET_PLAYER_CORE', SetPlayerCore);
this.register('CLEAR_SLOW_MOTION', ClearSlowMotion);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { EntityAttributes } from '../../../../services/phaser/entities/cc-entity';
import { Helper } from '../../../../services/phaser/helper';
import { RandomDistributionOption } from '../../random-distribution-widget/random-distribution-widget.component';
import { AbstractEvent, EventType } from './abstract-event';

export interface SelectRandomData extends EventType {
[key: `${number}_${number}`]: AbstractEvent<any>[];

options: RandomDistributionOption[];
}

export class SelectRandom extends AbstractEvent<SelectRandomData> {
private attributes: EntityAttributes = {
options: {
type: 'RandomDistribution',
description: 'Defines the possible branches for this event, as well as their chances.',
noLabel: true,
}
};

getAttributes() {
return this.attributes;
}

update() {
this.children = [];
this.info = this.getTypeString('#ffffff');

this.data.options?.forEach((option, optionIndex) => {
for (let branch = 0; branch < option.count; branch++) {
const key = optionIndex + '_' + branch as `${number}_${number}`;
this.children.push({
title: this.combineStrings(
this.getPropString('Entry', optionIndex + ' #' + branch),
this.getPropString('weight', option.weight),
(option.activeCondition ? this.getPropString('activeCondition', option.activeCondition) : '')),
events: this.data[key] || [],
key,
draggable: false,
});
}
});
}


override export(): SelectRandomData {
const out: SelectRandomData = {
type: this.data.type,
options: this.data.options,
};
for (const child of this.children) {
out[child.key as `${number}_${number}`] = child.events?.map(v => v.export()) ?? [];
}

return Helper.copy(out);
}

protected override generateNewDataInternal(): SelectRandomData {
return {
type: 'SELECT_RANDOM',
options: [{
count: 2,
weight: 1,
}]
};
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { Overlay } from '@angular/cdk/overlay';
import { Component, OnChanges, OnDestroy, OnInit, inject, ChangeDetectionStrategy } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnChanges, OnDestroy, OnInit, inject } from '@angular/core';

import { FlexModule } from '@angular/flex-layout/flex';
import { MatTooltip } from '@angular/material/tooltip';
import { EventArray } from '../../../models/events';
import { FACE8 } from '../../../services/phaser/entities/registry/npc';
import { OverlayRefControl } from '../../dialogs/overlay/overlay-ref-control';
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 { FACE8 } from '../../../services/phaser/entities/registry/npc';
import { FlexModule } from '@angular/flex-layout/flex';
import { MatTooltip } from '@angular/material/tooltip';

export interface NPCState {
reactType: string;
pageName?: string;
face: keyof typeof FACE8;
action: any;
action?: EventType[];
showFx?: WMTypes.Effect;
hideFx?: WMTypes.Effect;
permaFx?: WMTypes.Effect;
hidden: boolean;
door?: WMTypes.Entity;
position?: {
x: number;
y: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,132 +1,86 @@
<cc-overlay-panel>
<ng-container ngProjectAs="toolbar">
<div class="toolbar" fxLayout="row" fxFlexAlign="start">
<div class="px-3 gap-3 flex flex-row">
<button mat-stroked-button (click)="newPage()">New Page</button>
<button mat-stroked-button (click)="copyPage()">Copy Page</button>
<button mat-stroked-button (click)="pastePage()" [disabled]="!clipboard">Paste Page</button>
<button mat-stroked-button (click)="removePage()">Remove Page</button>
</div>
</ng-container>
<ng-container ngProjectAs="content">
<div fxLayout="column" class="container">

<mat-tab-group fxFlex="0 0 auto"
id="groupTabGroup"
<div class="h-full flex flex-col">
<mat-tab-group id="groupTabGroup"
animationDuration="0ms"
mat-stretch-tabs="false"
(selectedIndexChange)="selectTab($event)"
[selectedIndex]="index">
@for (state of states; track state; let index = $index) {
<mat-tab class="stretched-tabs"
[label]="state.pageName && state.pageName.trim() ? state.pageName : ((index + 1) + '')">
<mat-tab [label]="state.pageName && state.pageName.trim() ? state.pageName : ((index + 1) + '')">
</mat-tab>
}
</mat-tab-group>

@if (currentState) {
<div class="tab-content" fxLayout="column" fxFlex="1 1 0">

<!-- condition -->
<div fxFlex="0 0 54px" fxLayout="row">
<div fxLayout="row" fxFlexAlign="center" fxFlex="auto">
<label for="condition" class="condition-label" fxFlexAlign="center">condition:</label>
<input class="default-input condition-padding" id="condition"
[(ngModel)]="currentState.condition">
<div class="condition-icon">
<!--TODO: search icon-->
</div>
</div>
<div class="tab-content flex flex-col grow">
<div class="flex flex-row items-center p-3 gap-2">
<label [for]="condition">Condition:</label>
<input class="default-input" #condition [(ngModel)]="currentState.condition">
</div>
<div fxFlex="1 1 0" fxLayout="row" class="middle-container tab-content-inner">
<div class="content-left" fxFlex="0 0 225px" fxLayout="column">

<div class="tab-content-inner flex flex-row grow overflow-hidden">
<div class="w-[250px] flex flex-col px-3">

<!-- Position -->
<div fxFlex="0 0 auto">
<div fxLayout="row" class="attribute">
<mat-checkbox color="primary" [(ngModel)]="currentState.position!.active">Position
</mat-checkbox>
</div>
<div class="flex flex-row">
<mat-checkbox color="primary" [(ngModel)]="currentState.position!.active">
Position
</mat-checkbox>
</div>
@if (currentState.position!.active) {
<div fxFlex="0 1 auto">
<div fxLayout="row" class="property-container">
<label fxFlexAlign="center" class="pos-label">Pos:</label>

<div class="grid grid-cols-3 gap-2">
<label>Pos:</label>
<div class="flex">
<label class="property-name-small">X:</label>
<input type="number" class="default-input small-input"
[(ngModel)]="currentState.position!.x">
<input type="number" class="default-input small-input" [(ngModel)]="currentState.position!.x">
</div>
<div class="flex">
<label class="property-name-small">Y:</label>
<input type="number" class="default-input small-input"
[(ngModel)]="currentState.position!.y">
<input type="number" class="default-input small-input" [(ngModel)]="currentState.position!.y">
</div>

<div fxLayout="row" class="property-container">
<label fxFlexAlign="center" class="pos-label" for="level">Level:</label>

<input id="level" type="number" class="default-input small-input" min="0"
[(ngModel)]="currentState.position!.lvl">

<label [for]="level">Level:</label>
<input #level type="number" class="default-input small-input" min="0" [(ngModel)]="currentState.position!.lvl">
<div class="flex">
<label for="offset" class="property-name-small">+</label>
<input disabled id="offset" type="number" class="default-input small-input">
</div>
<br><br>
</div>
}

<!-- page name -->
<div fxLayout="row" class="attribute" fxFlex="0 0 auto">
<span fxFlex="0 0 87px" fxFlexAlign="center">Page name: </span>
<input class="default-input" [(ngModel)]="currentState.pageName">
</div>

<!-- Event type -->
<div fxLayout="row" class="attribute" fxFlex="0 0 auto">
<span fxFlex="0 0 87px" fxFlexAlign="center">Event type: </span>
<select class="default-input select-input" [(ngModel)]="eventType"
(ngModelChange)="updateDisplayedWarnings()">
@for (type of eventTypes; track type) {
<option [value]="type">
{{ type }}
</option>
}
</select>
</div>

<!-- Trader -->

<app-string-widget [custom]="currentState" key="pageName" />
<app-string-widget [custom]="this" key="eventType" [attribute]="attributes.eventType" />
@if (isTradeEvent) {
<div fxLayout="row" class="attribute" fxFlex="0 0 auto">
<span fxFlex="0 0 87px" fxFlexAlign="center">Trader: </span>
<input class="default-input" [(ngModel)]="trader"
(ngModelChange)="updateDisplayedWarnings()">
</div>
}

<!-- Other -->
@for (prop of props | keyvalue; track prop) {
<div fxLayout="row" class="attribute" fxFlex="0 0 auto">
<span fxFlex="0 0 87px" fxFlexAlign="center">{{ prop.key }}: </span>
<select class="default-input select-input" [(ngModel)]="$any(currentState)[$any(prop.key)]">
@for (item of $any(prop.value); track item) {
<option [value]="item">
{{ item }}
</option>
}
</select>
</div>
<app-string-widget [custom]="this" key="trader" />
}
<app-string-widget [custom]="currentState" key="reactType" [attribute]="attributes.reactType" />
<app-string-widget [custom]="currentState" key="face" [attribute]="attributes.face" />
<app-string-widget [custom]="currentState" key="config" [attribute]="attributes.config" />
<app-event-widget [custom]="currentState" key="action" [attribute]="attributes.action" />
<app-json-widget [custom]="currentState" key="showFx" [attribute]="attributes.showFx" />
<app-json-widget [custom]="currentState" key="hideFx" [attribute]="attributes.hideFx" />
<app-json-widget [custom]="currentState" key="permaFx" [attribute]="attributes.permaFx" />
<app-boolean-widget [custom]="currentState" key="hidden" [attribute]="attributes.hidden" />
<app-json-widget [custom]="currentState" key="door" [attribute]="attributes.door" />

<!-- Warnings -->
@for (warning of warnings; track warning) {
<div fxLayout="row" class="warning-message">
<mat-icon>warning</mat-icon>
<span fxFlexAlign="center">{{ warning }}</span>
<div class="flex flex-row warning-message">
<mat-icon class="!w-7 shrink-0">warning</mat-icon>
<span>{{ warning }}</span>
</div>
}
</div>
<div fxFlex="1 1 0" fxLayout="column" class="event-container">
<!-- Event Editor -->
<app-event-editor #eventEditor class="event-block" fxLayout="column"
<div class="min-w-0 flex flex-col grow">
<app-event-editor #eventEditor class="mx-2 flex flex-col"
[eventData]="currentState.event"
(eventsChanged)="updateTradeEventWarning($event)"
></app-event-editor>
Expand Down
Loading
Loading