issue-5-product-gamesystems #11

Merged
sebastian merged 6 commits from issue-5-product-gamesystems into main 2024-02-16 20:02:12 +01:00
7 changed files with 99 additions and 43 deletions
Showing only changes of commit 9e43b3901c - Show all commits

View File

@ -1,2 +1,4 @@
<app-product-state-editor [gamesystem]="gamesystem" (onOpenGamesystemEditor)="onOpenGamesystemEditor($event)"></app-product-state-editor>
<div id="productStateEditor">
<app-product-transition-editor [gamesystem]="gamesystem" (onOpenGamesystem)="onOpenGamesystemEditor($event)"></app-product-transition-editor>
</div>

View File

@ -0,0 +1,3 @@
#productStateEditor {
margin-top: 20px;
}

View File

@ -1,3 +1,9 @@
<mat-card>
<mat-card-content>
<mat-form-field class="long-form">
<mat-label>Filter</mat-label>
<input matInput (keyup)="applyFilter($event)" placeholder="Filter" #input>
</mat-form-field>
<table mat-table [dataSource]="dataSource">
<ng-container *ngFor="let col of displayedColumns; let i = index" [matColumnDef]="col.internalName">
<th mat-header-cell *matHeaderCellDef (dblclick)="openGamesystemEditor(i)">{{col.displayedName}}</th>
@ -39,4 +45,10 @@
<tr mat-header-row *matHeaderRowDef="columns;sticky:true"></tr>
<tr mat-row *matRowDef="let row; columns: columns;"></tr>
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" colspan="4">No data matching the filter "{{input.value}}"</td>
</tr>
</table>
</mat-card-content>
</mat-card>

View File

@ -5,7 +5,7 @@ import {
MatCell, MatCellDef,
MatColumnDef,
MatHeaderCell,
MatHeaderCellDef, MatHeaderRow, MatHeaderRowDef, MatRow, MatRowDef,
MatHeaderCellDef, MatHeaderRow, MatHeaderRowDef, MatNoDataRow, MatRow, MatRowDef,
MatTable,
MatTableDataSource
} from "@angular/material/table";
@ -14,6 +14,10 @@ import {NgForOf, NgIf} from "@angular/common";
import {ProductTransition} from "../../../../game-model/gamesystems/ProductTransition";
import {ProductState} from "../../../../game-model/gamesystems/ProductState";
import {MatTooltip} from "@angular/material/tooltip";
import {MatFormField} from "@angular/material/form-field";
import {MatInput} from "@angular/material/input";
import {Transition} from "../../../../game-model/gamesystems/Transition";
import {MatCard, MatCardContent, MatCardTitle} from "@angular/material/card";
class DisplayedColumnName {
displayedName: string
@ -41,7 +45,13 @@ class DisplayedColumnName {
MatRow,
MatHeaderRowDef,
MatRowDef,
MatTooltip
MatTooltip,
MatFormField,
MatInput,
MatNoDataRow,
MatCard,
MatCardContent,
MatCardTitle
],
templateUrl: './product-transition-editor.component.html',
styleUrl: './product-transition-editor.component.scss'
@ -51,7 +61,7 @@ export class ProductTransitionEditorComponent implements OnInit{
@Input() gamesystem: ProductGamesystem | undefined
@Output() onOpenGamesystem = new EventEmitter<SimpleGamesystem>();
dataSource = new MatTableDataSource();
dataSource = new MatTableDataSource<ProductTransition>();
displayedColumns: DisplayedColumnName[] = [];
columns: string[] = [];
numberLeafSystems: number = -1;
@ -66,6 +76,14 @@ export class ProductTransitionEditorComponent implements OnInit{
this.columns = this.displayedColumns.map(column => column.internalName)
this.dataSource.data = this.gamesystem.transitions;
this.dataSource.filterPredicate = (data: ProductTransition, filter: string) => {
const leaf_starting_states = LeafGamesystemCalculator.calcLeafStates(data.startingState);
const leaf_ending_states = LeafGamesystemCalculator.calcLeafStates(data.endingState);
const combined_leaf_states = leaf_starting_states.concat(leaf_ending_states);
return combined_leaf_states.some((state) => state.stateLabel.toLowerCase().includes(filter))
}
}
}
@ -79,8 +97,6 @@ export class ProductTransitionEditorComponent implements OnInit{
index = leafIndex - this.numberLeafSystems;
}
const leafStates = LeafGamesystemCalculator.calcLeafStates(state);
console.log(leafStates)
return leafStates[index];
@ -94,4 +110,9 @@ export class ProductTransitionEditorComponent implements OnInit{
this.onOpenGamesystem.emit(leafGamesystems[leafIndex - this.numberLeafSystems])
}
}
applyFilter(event: KeyboardEvent) {
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();
}
}

View File

@ -38,5 +38,16 @@ export class ProductState extends State<ProductTransition> {
return true;
}
existsInnerStateByLowerCaseLabel(label: string): boolean {
this.innerStates.forEach(innerState => {
if(innerState instanceof SimpleState && innerState.stateLabel.toLowerCase() === label) {
return true;
} else if(innerState instanceof ProductState) {
return innerState.existsInnerStateByLowerCaseLabel(label);
}
})
return false;
}
}

View File

@ -3,4 +3,7 @@ import {ProductState} from "./ProductState";
export class ProductTransition extends Transition<ProductState> {
containsInnerStateByLabel(label: string) {
return this.startingState.existsInnerStateByLowerCaseLabel(label) || this.endingState.existsInnerStateByLowerCaseLabel(label);
}
}