Merge branch 'sky19-chapter2-battles'
This commit is contained in:
commit
3284e94ad4
@ -5,7 +5,7 @@ version: '3'
|
|||||||
vars:
|
vars:
|
||||||
GREETING: Hello, World!
|
GREETING: Hello, World!
|
||||||
FILES:
|
FILES:
|
||||||
sh: git diff-ls --diff-filter=d main
|
sh: git diff-ls --diff-filter=d main | grep -v .eslintignore
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
build: vite build
|
build: vite build
|
||||||
@ -19,7 +19,7 @@ tasks:
|
|||||||
lint:fix:
|
lint:fix:
|
||||||
cmds:
|
cmds:
|
||||||
- npx prettier --write {{.CLI_ARGS | default .FILES | catLines }}
|
- npx prettier --write {{.CLI_ARGS | default .FILES | catLines }}
|
||||||
- npx eslint --fix --quiet {{.CLI_ARGS | default .FILES | without '.eslintignore' | catLines }}
|
- npx eslint --fix --quiet {{.CLI_ARGS | default .FILES | catLines }}
|
||||||
integrate:
|
integrate:
|
||||||
cmds:
|
cmds:
|
||||||
- git is-clean
|
- git is-clean
|
||||||
|
@ -3,10 +3,9 @@ import chapters from './chapters.js';
|
|||||||
|
|
||||||
const pickOne = (choices) => choices[parseInt(Math.random() * choices.length)];
|
const pickOne = (choices) => choices[parseInt(Math.random() * choices.length)];
|
||||||
|
|
||||||
export function genNextBattle(battles = []) {
|
function genChapter1Battle(battles) {
|
||||||
let chapter = R.clamp(1 + parseInt(battles.length / 2), { min: 1, max: 4 });
|
const chapter = 1;
|
||||||
|
|
||||||
if (chapter === 1) {
|
|
||||||
const scenario = pickOne(
|
const scenario = pickOne(
|
||||||
chapters[chapter - 1].scenarios.filter(
|
chapters[chapter - 1].scenarios.filter(
|
||||||
(s) => !battles.map(R.prop('scenario')).includes(s),
|
(s) => !battles.map(R.prop('scenario')).includes(s),
|
||||||
@ -25,4 +24,46 @@ export function genNextBattle(battles = []) {
|
|||||||
|
|
||||||
return { scenario, character, city, status: 'ongoing', wave: 1 };
|
return { scenario, character, city, status: 'ongoing', wave: 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function genChapter2Battle(battles) {
|
||||||
|
const chapter = 2;
|
||||||
|
|
||||||
|
const scenario = pickOne(
|
||||||
|
chapters[chapter - 1].scenarios.filter(
|
||||||
|
(s) => !battles.map(R.prop('scenario')).includes(s),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const character = pickOne(
|
||||||
|
chapters[chapter - 1].characters.filter(
|
||||||
|
(s) => !battles.map(R.prop('character')).includes(s),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const city = pickOne(
|
||||||
|
chapters[chapter - 1].cities.filter(
|
||||||
|
(s) => !battles.map(R.prop('city')).includes(s),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
let choices = battles.slice(0, 2).map(R.prop('character'));
|
||||||
|
if (battles.length == 3)
|
||||||
|
choices = choices.filter(
|
||||||
|
(n) => n !== R.last(battles).additionalCharacter[0].selection,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
scenario,
|
||||||
|
character,
|
||||||
|
city,
|
||||||
|
status: 'ongoing',
|
||||||
|
wave: 1,
|
||||||
|
additionalCharacters: [{ choices, selection: R.first(choices) }],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function genNextBattle(battles = []) {
|
||||||
|
let chapter = R.clamp(1 + parseInt(battles.length / 2), { min: 1, max: 4 });
|
||||||
|
|
||||||
|
if (chapter === 1) return genChapter1Battle(battles);
|
||||||
|
|
||||||
|
if (chapter === 2) return genChapter2Battle(battles);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,33 @@
|
|||||||
import { test, expect } from 'vitest';
|
import { test, expect } from 'vitest';
|
||||||
|
|
||||||
import { genNextBattle } from './genNextBattle.js';
|
import { genNextBattle, genChapter2Battle } from './genNextBattle.js';
|
||||||
|
|
||||||
test('generate for the first chapter', () => {
|
test('generate for the first chapter', () => {
|
||||||
const next = genNextBattle();
|
const next = genNextBattle();
|
||||||
expect(next).toHaveProperty('city');
|
expect(next).toHaveProperty('city');
|
||||||
expect(next).toHaveProperty('status', 'ongoing');
|
expect(next).toHaveProperty('status', 'ongoing');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('chapter 2, first battle', () => {
|
||||||
|
const result = genChapter2Battle([
|
||||||
|
{ character: 'one' },
|
||||||
|
{ character: 'two' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(result.additionalCharacters[0].selection).toEqual('one');
|
||||||
|
expect(result.additionalCharacters[0].choices).toEqual(['one', 'two']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('chapter 2, second battle', () => {
|
||||||
|
const result = genChapter2Battle([
|
||||||
|
{ character: 'one' },
|
||||||
|
{ character: 'two' },
|
||||||
|
{
|
||||||
|
character: 'three',
|
||||||
|
additionalCharacter: [{ selection: 'two' }],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(result.additionalCharacters[0].selection).toEqual('one');
|
||||||
|
expect(result.additionalCharacters[0].choices).toEqual(['one']);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user