diff --git a/e2e/game-model/gamesystems/conditions/ConditionContradicting.spec.ts b/e2e/game-model/gamesystems/conditions/ConditionContradicting.spec.ts new file mode 100644 index 0000000..8a26afc --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/ConditionContradicting.spec.ts @@ -0,0 +1,43 @@ + +import { test, expect } from '@playwright/test'; +import {ScriptAccountCondition} from "../../../../src/app/game-model/gamesystems/conditions/ScriptAccountCondition"; +import {ScriptAccount} from "../../../../src/app/game-model/scriptAccounts/ScriptAccount"; +import exp = require("node:constants"); +import {ConditionTrainer} from "./ConditionTrainer"; +import {Conditional} from "@angular/compiler"; +test.describe('Test Contradicting Conditions', () => { + + test("Test contradicting conditions", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + + let contradictingCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.maxValue + 10, condition.maxValue+200); + expect(condition.isContradicting(contradictingCondition)).toBeTruthy(); + + contradictingCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-100, condition.minValue-50); + expect(condition.isContradicting(contradictingCondition)).toBeTruthy(); + }) + + test("Test intersecting conditions", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + let otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-1, condition.minValue+1); + expect(condition.isContradicting(otherCondition)).toBeFalsy(); + + otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.maxValue-1, condition.maxValue+1); + expect(condition.isContradicting(otherCondition)).toBeFalsy(); + + otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-1, condition.maxValue+1); + expect(condition.isContradicting(otherCondition)).toBeFalsy(); + + expect(condition.isContradicting(condition)).toBeFalsy(); + }) + + test("Test contradicting conditions with different ScriptAccount", async () => { + const condition = ConditionTrainer.withSimpleCondition(); + const otherCondition = ScriptAccountCondition.constructScriptAccountCondition( + new ScriptAccount("Another test", ""), condition.minValue-20, condition.minValue-10); + + expect(condition.isContradicting(otherCondition)).toBeFalsy(); + }) + + +}); diff --git a/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts b/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts new file mode 100644 index 0000000..d08077f --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts @@ -0,0 +1,14 @@ +import {ScriptAccount} from "../../../../src/app/game-model/scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../../../../src/app/game-model/gamesystems/conditions/ScriptAccountCondition"; + +export class ConditionTrainer { + static withSimpleCondition(): ScriptAccountCondition { + const scriptAccount = new ScriptAccount("Test", ""); + return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10); + } + + static withSimpleOtherCondition(): ScriptAccountCondition { + const scriptAccount = new ScriptAccount("Another Test", ""); + return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10); + } +} diff --git a/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts b/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts index aa04cd9..6d741be 100644 --- a/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts +++ b/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts @@ -16,5 +16,14 @@ export class ScriptAccountCondition { return new ScriptAccountCondition(scriptAccount, minValue, maxValue) } + extendCondition(condition: ScriptAccountCondition) { + + } + + isContradicting(condition: ScriptAccountCondition) { + return condition.scriptAccount === this.scriptAccount && + (this.maxValue < condition.minValue || this.minValue > condition.maxValue) + } + } diff --git a/src/app/game-model/gamesystems/transitions/Transition.ts b/src/app/game-model/gamesystems/transitions/Transition.ts index ca302c5..48e9170 100644 --- a/src/app/game-model/gamesystems/transitions/Transition.ts +++ b/src/app/game-model/gamesystems/transitions/Transition.ts @@ -1,12 +1,14 @@ import {State} from "../states/State"; import {ScriptAccountAction} from "../actions/ScriptAccountAction"; import {ScriptAccount} from "../../scriptAccounts/ScriptAccount"; +import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; export abstract class Transition> { startingState: S endingState: S scriptAccountActions: ScriptAccountAction[] = []; + scriptAccountConditions: ScriptAccountCondition[] = []; constructor(startingState: S, endingState: S) { this.startingState = startingState; @@ -36,4 +38,16 @@ export abstract class Transition> { findScriptAccountActionByScriptAccount(scriptAccount: ScriptAccount) { return this.scriptAccountActions.find(sA => sA.scriptAccount.componentName === scriptAccount.componentName); } + + addScriptAccountCondition(scriptAccountCondition: ScriptAccountCondition) { + + } + + removeScriptAccountCondition(scriptAccount: ScriptAccount) { + + } + + findScriptAccountConditionByScriptAccount(scriptAccount: ScriptAccount) { + + } }