Skip to content

Commit

Permalink
First addition of Grey Star
Browse files Browse the repository at this point in the history
  • Loading branch information
lonevvolf committed Oct 11, 2024
1 parent 2b974fe commit 7662db2
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 29 deletions.
9 changes: 5 additions & 4 deletions src/ts/controller/newGameController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ export const newGameController = {
* Start new game event
* @param {string} bookNumber The book number
*/
startNewGame( bookNumber: number) {
startNewGame( bookNumber: number, bookSeries?: string) {

state.reset(true);
routing.redirect( "setup" , {
bookNumber
bookNumber,
bookSeries
});

},

selectedBookChanged(newBookNumber: number) {
const book = new Book(newBookNumber);
selectedBookChanged(newBookNumber: number, bookSeries?: string) {
const book = new Book(newBookNumber, bookSeries ?? "lw");
newGameView.setCoverImage( book.getCoverURL() );
},

Expand Down
3 changes: 2 additions & 1 deletion src/ts/controller/setupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export const setupController = {
} else {
// New game. Get hash URL parameters
const bookNumber = Number(routing.getHashParameter("bookNumber"));
const bookSeries = routing.getHashParameter("bookSeries");
const keepActionChart = routing.getHashParameter("keepActionChart") === "true";
state.setup(bookNumber, keepActionChart);
state.setup(bookNumber, keepActionChart, bookSeries);
}
template.translateMainMenu();

Expand Down
16 changes: 9 additions & 7 deletions src/ts/model/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export class Book {
/** The book XML document */
public bookXml: XMLDocument|null;

/**
* Array of 100 positions with the random table numbers as they appear on the book
*/
/** Array of 100 positions with the random table numbers as they appear on the book */
public bookRandomTable: number[];

/** The book title cache, plain text */
Expand All @@ -75,14 +73,18 @@ export class Book {
/** The book disciplines cache */
private disciplines: DisciplinesTable|null = null;

/** The book series (lw, gs) */
public bookSeries: string = "lw";

/**
* Constructor
* @param number The book index number to create (1 = first)
*/
public constructor(num: number) {
public constructor(num: number, bookSeries?: string) {
this.bookNumber = num;
this.bookXml = null;
this.bookRandomTable = [];
this.bookSeries = bookSeries ?? "lw";
}

/**
Expand Down Expand Up @@ -224,7 +226,7 @@ export class Book {
* @returns The book code name. null if it was not found
*/
public getProjectAonBookCode(): string|null {
const bookMetadata = projectAon.supportedBooks[ this.bookNumber - 1 ];
const bookMetadata = this.bookSeries === "gs" ? projectAon.supportedBooks.filter((b) => b.series === "gs")[ this.bookNumber - 1 ] : projectAon.supportedBooks[ this.bookNumber - 1 ];
if ( !bookMetadata ) {
return null;
}
Expand All @@ -241,7 +243,7 @@ export class Book {
* Returns the book XML source URL
*/
public getBookXmlURL() {
return Book.getBaseUrl() + this.bookNumber.toFixed() + "/" + this.getProjectAonBookCode() +
return Book.getBaseUrl() + (this.bookSeries === "gs" ? "gs/" : "") + this.bookNumber.toFixed() + "/" + this.getProjectAonBookCode() +
".xml";
}

Expand Down Expand Up @@ -423,7 +425,7 @@ export class Book {
if (this.bookNumber === 29) {
return null;
}
return Book.getBaseUrl() + this.bookNumber.toFixed() + "/cover.jpg";
return Book.getBaseUrl() + (this.bookSeries !== "lw" ? this.bookSeries + "/" : "") + this.bookNumber.toFixed() + "/cover.jpg";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ts/model/mechanics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Mechanics {
* Returns the book XML URL
*/
public getXmlURL(): string {
return `data/mechanics-${this.book.bookNumber}.xml`;
return `data/mechanics${!this.book.bookSeries || this.book.bookSeries === "lw" ? "" : "-gs"}-${this.book.bookNumber}.xml`;
}

/** Set mechanics XML */
Expand Down
21 changes: 19 additions & 2 deletions src/ts/model/projectAon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export interface BookMetadata {

/** Whether a cover exists for the book */
hasCover: boolean;

/** Book Series (lw, gs) */
series: string;

/** Book Number in the series */
bookNumber: number;
}

/**
Expand Down Expand Up @@ -266,14 +272,25 @@ export const projectAon = {
hasCover: false,
},

/////////// WORLD OF LONE WOLF ///////////
// Book 1:
{
bookNumber: 1,
title: "Grey Star the Wizard",
code: "01gstw",
illustrators: ["bonner"],
biographies: ["ipbiogs", "jdbiogs", "pbbiogs"],
series: "gs",
},

] as BookMetadata[],

/**
* Returns the title of a book
* @param bookNumber Book number, 1-index based
*/
getBookTitle( bookNumber: number ): string {
return projectAon.supportedBooks[bookNumber - 1][ "title" ];
getBookTitle( bookNumber: number, bookSeries?: string ): string {
return projectAon.supportedBooks.filter((b) => (b.series === bookSeries))[bookNumber - 1][ "title" ];
},

/**
Expand Down
4 changes: 3 additions & 1 deletion src/ts/model/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ export class Section {

const sNumber = this.getSectionNumber();
if ( sNumber ) {
if ( sNumber === 1 ) {
if (this.book.bookSeries === "gs" && sNumber === 1) {
return "sage";
} else if ( sNumber === 1) {
return "kaiwisdm";
} else {
return `sect${( sNumber - 1 )}`;
Expand Down
16 changes: 10 additions & 6 deletions src/ts/scripts/bookData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,27 @@ export class BookData {
/** Array with illustrations authors directories names */
private illAuthors: string[];

/** Book Series (lw, gs) */
private bookSeries: string = "lw";

/**
* Constructor
* @param bookNumber The book number (1-based index)
*/
constructor(bookNumber: number) {
this.bookNumber = bookNumber;
this.bookNumber = projectAon.supportedBooks[ bookNumber - 1 ].bookNumber ?? bookNumber;
this.bookMetadata = projectAon.supportedBooks[ bookNumber - 1 ];
this.code = this.bookMetadata.code;
this.illAuthors = this.bookMetadata.illustrators;
this.hasCover = this.bookMetadata.hasCover === undefined ? true : this.bookMetadata.hasCover;
this.bookSeries = this.bookMetadata.series ?? "lw";
}

/**
* Get the local relative path for the book data
*/
private getBookDir(): string {
return BookData.TARGET_ROOT + "/" + this.bookNumber.toFixed();
return BookData.TARGET_ROOT + "/" + (this.bookSeries !== "lw" ? this.bookSeries + "/" : "") + this.bookNumber.toFixed();
}

/**
Expand Down Expand Up @@ -86,7 +90,7 @@ export class BookData {
* Get the svn absolute URL for illustrations directory of a given author
*/
private getSvnIllustrationsDir(author: string): string {
return "project-aon/en/png/lw/" + this.code + "/ill/" +
return `project-aon/en/png/${this.bookSeries}/` + this.code + "/ill/" +
author;
}

Expand Down Expand Up @@ -139,19 +143,19 @@ export class BookData {
*/
private downloadCover() {
if ( this.hasCover ) {
const coverPath = "project-aon/en/jpeg/lw/" + this.code +
const coverPath = `project-aon/en/jpeg/${this.bookSeries}/` + this.code +
"/skins/ebook/cover.jpg";
const targetPath = this.getBookDir() + "/cover.jpg";
fs.copyFileSync(coverPath, targetPath);
}
}

public downloadBookData() {
const bookDir = BookData.TARGET_ROOT + "/" + this.bookNumber.toFixed();
const bookDir = this.getBookDir();

console.log("Re-creating directory " + bookDir);
fs.removeSync( bookDir );
fs.mkdirSync( bookDir );
fs.mkdirSync( bookDir, {recursive: true} );

this.downloadCover();

Expand Down
4 changes: 2 additions & 2 deletions src/ts/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ export class State {
/**
* Setup the state for a book number
*/
public setup(bookNumber: number, keepActionChart: boolean) {
public setup(bookNumber: number, keepActionChart: boolean, bookSeries?: string) {

if (!bookNumber) {
bookNumber = 1;
}

this.sectionStates = new BookSectionStates();
this.book = new Book(bookNumber);
this.book = new Book(bookNumber, bookSeries);

// Action chart
this.actionChart = null;
Expand Down
15 changes: 10 additions & 5 deletions src/ts/views/newGameView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export const newGameView = {
let html = "";
let series: BookSeriesId|null = null;
for ( let i = 1; i <= projectAon.supportedBooks.length; i++) {
let seriesId = new Book(i).getBookSeries().id;
let bookNumber = projectAon.supportedBooks[i-1].bookNumber ?? i;
let bookSeries = projectAon.supportedBooks[i-1].series;
let seriesId = new Book(bookNumber, bookSeries).getBookSeries().id;
if (seriesId !== series) {
html += `<optgroup label="${translations.text(BookSeriesId[seriesId])}"></optgroup>`;
series = seriesId;
}
const title = projectAon.getBookTitle( i )
html += '<option value="' + i.toFixed() + '" >' + i.toFixed() + ". " + title + "</option>";
const title = projectAon.getBookTitle( bookNumber, bookSeries );
html += "<option value='" + JSON.stringify({"bookNumber": bookNumber.toFixed(), "bookSeries": bookSeries}) + "' >" + bookNumber.toFixed() + ". " + title + "</option>";
}
$("#newgame-book").html(html);

Expand All @@ -29,12 +31,15 @@ export const newGameView = {
alert(translations.text("youMustAgree"));
return;
}
newGameController.startNewGame(parseInt(<string>$("#newgame-book").val()));

let selectedBook = JSON.parse(<string>$("#newgame-book").val());
newGameController.startNewGame(parseInt(selectedBook.bookNumber), selectedBook.bookSeries);
});

// Book change
$("#newgame-book").on("change", () => {
newGameController.selectedBookChanged(parseInt(<string>$("#newgame-book").val()));
let selectedBook = JSON.parse(<string>$("#newgame-book").val());
newGameController.selectedBookChanged(parseInt(selectedBook.bookNumber), selectedBook.bookSeries);
});

// Random table change
Expand Down
11 changes: 11 additions & 0 deletions www/data/mechanics-gs-1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>

<mechanics book="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/cracrayol/kaichronicles/master/www/data/mechanics.xsd">

<!-- GAME RULES -->
<sections>


</sections>

</mechanics>

0 comments on commit 7662db2

Please sign in to comment.