diff --git a/CHANGELOG.md b/CHANGELOG.md index 89f2b215..7ffdd8a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/) diff --git a/webapp/src/app/components/widgets/event-widget/event-editor/event-helper.service.ts b/webapp/src/app/components/widgets/event-widget/event-editor/event-helper.service.ts index bb8498b6..01ba9bc9 100644 --- a/webapp/src/app/components/widgets/event-widget/event-editor/event-helper.service.ts +++ b/webapp/src/app/components/widgets/event-widget/event-editor/event-helper.service.ts @@ -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' @@ -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) { diff --git a/webapp/src/app/components/widgets/event-widget/event-registry/abstract-event.ts b/webapp/src/app/components/widgets/event-widget/event-registry/abstract-event.ts index cf2f842a..b11607dd 100644 --- a/webapp/src/app/components/widgets/event-widget/event-registry/abstract-event.ts +++ b/webapp/src/app/components/widgets/event-widget/event-registry/abstract-event.ts @@ -160,6 +160,7 @@ export interface EventType { export interface EventTypeChild { title?: string; + key?: string; draggable?: boolean; events: AbstractEvent[]; } diff --git a/webapp/src/app/components/widgets/event-widget/event-registry/event-registry.service.ts b/webapp/src/app/components/widgets/event-widget/event-registry/event-registry.service.ts index 49a816af..8e2b4da1 100644 --- a/webapp/src/app/components/widgets/event-widget/event-registry/event-registry.service.ts +++ b/webapp/src/app/components/widgets/event-widget/event-registry/event-registry.service.ts @@ -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 = new ( domSanitizer: DomSanitizer, @@ -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); diff --git a/webapp/src/app/components/widgets/event-widget/event-registry/select-random.ts b/webapp/src/app/components/widgets/event-widget/event-registry/select-random.ts new file mode 100644 index 00000000..512037a7 --- /dev/null +++ b/webapp/src/app/components/widgets/event-widget/event-registry/select-random.ts @@ -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[]; + + options: RandomDistributionOption[]; +} + +export class SelectRandom extends AbstractEvent { + 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, + }] + }; + } +} \ No newline at end of file diff --git a/webapp/src/app/components/widgets/npc-states-widget/npc-states-widget.component.ts b/webapp/src/app/components/widgets/npc-states-widget/npc-states-widget.component.ts index d334f508..48851bda 100644 --- a/webapp/src/app/components/widgets/npc-states-widget/npc-states-widget.component.ts +++ b/webapp/src/app/components/widgets/npc-states-widget/npc-states-widget.component.ts @@ -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; diff --git a/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.html b/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.html index fa9f0120..931d7811 100644 --- a/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.html +++ b/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.html @@ -1,6 +1,6 @@ -
+
@@ -8,125 +8,79 @@
-
- - + @for (state of states; track state; let index = $index) { - + } @if (currentState) { -
- - -
-
- - -
- -
-
+
+
+ +
-
-
+ +
+
-
-
- Position - -
+
+ + Position +
@if (currentState.position!.active) { -
-
- - +
+ +
- - + +
+
- +
- -
- - - - + + +


} - - -
- Page name: - -
- - -
- Event type: - -
- - + + + @if (isTradeEvent) { -
- Trader: - -
- } - - - @for (prop of props | keyvalue; track prop) { -
- {{ prop.key }}: - -
+ } + + + + + + + + + - @for (warning of warnings; track warning) { -
- warning - {{ warning }} +
+ warning + {{ warning }}
}
-
- - + diff --git a/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.scss b/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.scss index 27d8a600..063fe766 100644 --- a/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.scss +++ b/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.scss @@ -1,17 +1,5 @@ @use '@angular/material' as mat; -.container { - height: 100%; -} - -.toolbar { - padding-left: 32px; - - & button { - margin: 0 8px; - } -} - #groupTabGroup { &::ng-deep.mat-tab-label, &::ng-deep.mat-tab-label-active { min-width: 50px !important; @@ -26,10 +14,6 @@ } } -.content { - height: 100%; -} - .tab-content { flex-direction: column; min-height: 0; @@ -37,57 +21,12 @@ } .tab-content-inner { - padding-left: 12px; - padding-right: 12px; border-bottom: 1px solid var(--gray-600); border-top: 1px solid var(--gray-600); } -.condition-label { - margin: 0 10px; -} - -.condition-icon { - margin: 0 10px; -} - -.content-left { - margin: 10px; - - .select-input { - height: 26px; - - option { - background-color: var(--gray-800); - } - } - - .attribute { - margin-bottom: 10px; - } - - .pos-label { - margin-right: 20px; - } -} - -.event-block { - margin: 0 10px 0px 10px; -} - -.middle-container { - overflow: hidden; -} - -.event-container { - min-width: 0; -} - .warning-message { - margin-bottom: 14px; - & > mat-icon { color: orange; - margin-right: 4px; } } diff --git a/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.ts b/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.ts index d0889e1d..df3f5608 100644 --- a/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.ts +++ b/webapp/src/app/components/widgets/npc-states-widget/npc-states/npc-states.component.ts @@ -1,25 +1,26 @@ -import { Component, EventEmitter, Input, OnInit, Output, ViewChild, ChangeDetectionStrategy } from '@angular/core'; -import settingsJson from '../../../../../assets/npc-settings.json'; +import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { MatButton } from '@angular/material/button'; +import { MatCheckbox } from '@angular/material/checkbox'; +import { MatIcon } from '@angular/material/icon'; +import { MatTab, MatTabGroup } from '@angular/material/tabs'; import { createEventArray, destructureEventArray, EventArrayType } from '../../../../models/events'; +import { EntityAttributes } from '../../../../services/phaser/entities/cc-entity'; +import { OverlayPanelComponent } from '../../../dialogs/overlay/overlay-panel/overlay-panel.component'; +import { BooleanWidgetComponent } from '../../boolean-widget/boolean-widget.component'; import { EventEditorComponent } from '../../event-widget/event-editor/editor/event-editor.component'; import { EventType } from '../../event-widget/event-registry/abstract-event'; +import { EventWidgetComponent } from '../../event-widget/event-widget.component'; +import { JsonWidgetComponent } from '../../json-widget/json-widget.component'; +import { StringWidgetComponent } from '../../string-widget/string-widget.component'; import { type NPCState } from '../npc-states-widget.component'; -import { OverlayPanelComponent } from '../../../dialogs/overlay/overlay-panel/overlay-panel.component'; -import { FlexModule } from '@angular/flex-layout/flex'; -import { MatButton } from '@angular/material/button'; -import { MatTab, MatTabGroup } from '@angular/material/tabs'; -import { FormsModule } from '@angular/forms'; -import { MatCheckbox } from '@angular/material/checkbox'; -import { MatIcon } from '@angular/material/icon'; -import { KeyValuePipe } from '@angular/common'; @Component({ selector: 'app-npc-states', templateUrl: './npc-states.component.html', styleUrls: ['./npc-states.component.scss', '../../widget.scss'], - changeDetection: ChangeDetectionStrategy.Eager, - imports: [OverlayPanelComponent, - FlexModule, + imports: [ + OverlayPanelComponent, MatButton, MatTabGroup, MatTab, @@ -27,7 +28,10 @@ import { KeyValuePipe } from '@angular/common'; MatCheckbox, MatIcon, EventEditorComponent, - KeyValuePipe + EventWidgetComponent, + JsonWidgetComponent, + StringWidgetComponent, + BooleanWidgetComponent, ] }) export class NpcStatesComponent implements OnInit { @@ -35,22 +39,127 @@ export class NpcStatesComponent implements OnInit { @Input() states: NPCState[] = []; @Output() exit: EventEmitter = new EventEmitter(); - currentState?: NPCState; - index = 0; + protected currentState?: NPCState; + protected index = 0; - props = settingsJson; - eventTypes = Object.values(EventArrayType); - warnings: string[] = []; + protected warnings: string[] = []; private missingTradeEvent = false; + // Used by app-string-widget eventType: EventArrayType = EventArrayType.Simple; + // Used by app-string-widget trader?: string; // TODO: move to global events service - clipboard = ''; + protected clipboard = ''; - constructor() { - } + protected readonly attributes = { + condition: { + type: 'VarCondition', + description: 'Condition for this page to be active', + height: 24 + }, + position: { + type: 'Vec3', + description: 'Position of NPC for this page', + pointSelect: true, + optional: true + }, + reactType: { + type: 'String', + description: 'How NPC will react on touches and talking', + float: true, + options: { + PUSHABLE: 0, + FIXED_POS: 1, + FIXED_FACE: 2 + }, + default: 'FIXED_POS' + }, + face: { + type: 'Face', + description: 'Face direction.', + float: true, + options: { + NORTH: 0, + EAST: 1, + SOUTH: 2, + WEST: 3, + NORTH_EAST: 4, + SOUTH_EAST: 5, + SOUTH_WEST: 6, + NORTH_WEST: 7 + } + }, + config: { + type: 'CharConfig', + description: 'Configuration of Charater for this page', + float: true, + options: { + 'normal': 0, + 'run': 0, + 'ground': 0, + 'groundFloat': 0, + 'offline': 0, + 'sit': 0, + 'sitFloat': 0, + 'sit2': 0, + 'sit2Float': 0 + } + }, + action: { + type: 'Action', + description: 'Action to perform constantly', + popup: true, + float: true, + clear: true, + optional: true + }, + showFx: { + type: 'Effect', + description: 'Action to perform constantly', + popup: true, + float: true, + optional: true + }, + hideFx: { + type: 'Effect', + description: 'Action to perform constantly', + popup: true, + float: true, + optional: true + }, + permaFx: { + type: 'Effect', + description: 'Action to perform constantly', + popup: true, + float: true, + optional: true + }, + hidden: { + type: 'Boolean', + description: 'If true: NPC is hidden.', + float: true, + clear: true + }, + door: { + type: 'Entity', + description: 'Door that NPC should enter from/leave to (only specify when hidden!)', + optional: true, + float: true + }, + eventType: { + type: 'String', + description: 'Type of npc event. e.g. simple event or trade.', + options: { + simple: 'simple', + quest: 'quest', + shop: 'shop', + arena: 'arena', + trade: 'trade' + } + } + } satisfies EntityAttributes; ngOnInit() { this.states.forEach(state => { @@ -68,7 +177,7 @@ export class NpcStatesComponent implements OnInit { this.selectTab(this.index); } - selectTab(index: number) { + protected selectTab(index: number) { if (this.currentState) { if (!this.eventEditor) { throw new Error('event editor is not defined'); @@ -83,10 +192,10 @@ export class NpcStatesComponent implements OnInit { } } - newPage() { + protected newPage() { this.index++; this.states.splice(this.index, 0, { - reactType: '', + reactType: 'FIXED_POS', position: { x: 0, y: 0, @@ -103,7 +212,7 @@ export class NpcStatesComponent implements OnInit { } // TODO: make proper export for copy/paste and export - copyPage() { + protected copyPage() { if (!this.currentState) { return; } @@ -115,17 +224,17 @@ export class NpcStatesComponent implements OnInit { console.log(JSON.parse(this.clipboard)); } - pastePage() { + protected pastePage() { this.index++; this.states.splice(this.index, 0, JSON.parse(this.clipboard)); } - removePage() { + protected removePage() { this.states.splice(this.index, 1); this.index = Math.max(0, this.index - 1); } - export() { + private export() { if (!this.eventEditor) { throw new Error('event editor is not defined'); } @@ -144,15 +253,15 @@ export class NpcStatesComponent implements OnInit { return out; } - save() { + protected save() { this.exit.emit(this.export()); } - cancel() { + protected cancel() { this.exit.error('cancel'); } - updateDisplayedWarnings() { + private updateDisplayedWarnings() { this.warnings.length = 0; if (this.isTradeEvent) { if (!this.trader) { @@ -165,7 +274,7 @@ export class NpcStatesComponent implements OnInit { } } - updateTradeEventWarning(updatedEvents: EventType[]) { + protected updateTradeEventWarning(updatedEvents: EventType[]) { function hasEventOfTypeRecursive(object: any, type: string): boolean { if (typeof object !== 'object' || object === null) { return false; @@ -185,7 +294,7 @@ export class NpcStatesComponent implements OnInit { this.updateDisplayedWarnings(); } - get isTradeEvent() { + protected get isTradeEvent() { return this.eventType === EventArrayType.Trade; } } diff --git a/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.html b/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.html new file mode 100644 index 00000000..a24fa436 --- /dev/null +++ b/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.html @@ -0,0 +1,21 @@ +
+
+ + +
+ +
+ @for (option of settings[key]; track $index) { +
+ + + + +
+ } +
+
diff --git a/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.scss b/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.scss new file mode 100644 index 00000000..74058c17 --- /dev/null +++ b/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.scss @@ -0,0 +1,5 @@ +@use '@angular/material' as mat; + +:host { + @include mat.icon-button-density(-4); +} diff --git a/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.ts b/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.ts new file mode 100644 index 00000000..09a1d890 --- /dev/null +++ b/webapp/src/app/components/widgets/random-distribution-widget/random-distribution-widget.component.ts @@ -0,0 +1,53 @@ +import { Component, OnChanges } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { MatIconButton } from '@angular/material/button'; +import { MatIcon } from '@angular/material/icon'; +import { MatTooltip } from '@angular/material/tooltip'; +import { AbstractWidget } from '../abstract-widget'; +import { NumberWidgetComponent } from '../number-widget/number-widget.component'; +import { StringWidgetComponent } from '../string-widget/string-widget.component'; + + +interface RandomDistributionSettings { + [key: string]: RandomDistributionOption[] | undefined; +} + + +export interface RandomDistributionOption { + activeCondition?: string; + count: number; + weight: number; +} + + +@Component({ + selector: 'app-random-distribution-widget', + imports: [ + FormsModule, + MatTooltip, + MatIconButton, + MatIcon, + NumberWidgetComponent, + StringWidgetComponent, + ], + templateUrl: './random-distribution-widget.component.html', + styleUrls: ['./random-distribution-widget.component.scss', '../widget.scss'] +}) +export class RandomDistributionWidgetComponent extends AbstractWidget implements OnChanges { + remove(index: number) { + this.settings[this.key]?.splice(index, 1); + this.update(); + } + + add() { + this.settings[this.key]?.push({ + count: 1, + weight: 1, + }); + this.update(); + } + + protected update() { + this.updateType(this.settings[this.key]); + } +} diff --git a/webapp/src/app/components/widgets/widget-registry.service.ts b/webapp/src/app/components/widgets/widget-registry.service.ts index 92c45340..f6898b8d 100644 --- a/webapp/src/app/components/widgets/widget-registry.service.ts +++ b/webapp/src/app/components/widgets/widget-registry.service.ts @@ -1,20 +1,21 @@ import { Injectable } from '@angular/core'; +import { ArrayWidgetComponent } from './array-widget/array-widget.component'; import { BooleanWidgetComponent } from './boolean-widget/boolean-widget.component'; +import { CharacterWidgetComponent } from './character-widget/character-widget.component'; +import { CustomDesTypeWidgetComponent } from './custom-des-type-widget/custom-des-type-widget.component'; import { EnemyTypeWidgetComponent } from './enemy-type-widget/enemy-type-widget.component'; import { EventWidgetComponent } from './event-widget/event-widget.component'; import { JsonWidgetComponent } from './json-widget/json-widget.component'; import { LangLabelWidgetComponent } from './langlabel-widget/langlabel-widget.component'; +import { MapsWidgetComponent } from './maps-widget/maps-widget.component'; import { NPCStatesWidgetComponent } from './npc-states-widget/npc-states-widget.component'; import { NumberWidgetComponent } from './number-widget/number-widget.component'; import { PersonExpressionWidgetComponent } from './person-expression-widget/person-expression-widget.component'; -import { StringWidgetComponent } from './string-widget/string-widget.component'; -import { Vec2WidgetComponent } from './vec2-widget/vec2-widget.component'; import { PropTypeWidgetComponent } from './prop-type-widget/prop-type-widget.component'; +import { RandomDistributionWidgetComponent } from './random-distribution-widget/random-distribution-widget.component'; import { ScalablePropConfigWidgetComponent } from './scalable-prop-config-widget/scalable-prop-config-widget.component'; -import { CustomDesTypeWidgetComponent } from './custom-des-type-widget/custom-des-type-widget.component'; -import { CharacterWidgetComponent } from './character-widget/character-widget.component'; -import { ArrayWidgetComponent } from './array-widget/array-widget.component'; -import { MapsWidgetComponent } from './maps-widget/maps-widget.component'; +import { StringWidgetComponent } from './string-widget/string-widget.component'; +import { Vec2WidgetComponent } from './vec2-widget/vec2-widget.component'; @Injectable({ providedIn: 'root' @@ -45,6 +46,7 @@ export class WidgetRegistryService { this.register('Array', ArrayWidgetComponent); this.register('Maps', MapsWidgetComponent); this.register('Face', StringWidgetComponent); + this.register('RandomDistribution', RandomDistributionWidgetComponent); } private setDefaultWidget(widget: any) {