1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-11 09:11:50 +00:00

Simplify GameState legacy HTML string support

Move the getInnerHTML fallback to the default implementation of
getContentLayout; this allows for code reuse in TextualGameState too.
This commit is contained in:
Даниїл Григор'єв 2024-09-21 21:41:12 +03:00
parent ec8a6dec18
commit 8955e37c78
No known key found for this signature in database
GPG Key ID: B890DF16341D8C1D
2 changed files with 11 additions and 12 deletions

View File

@ -200,10 +200,12 @@ export class GameState {
/**
* Should return the element(s) to be displayed in the state.
* If null, {@link getInnerHTML} will be used instead.
* If not overridden, {@link getInnerHTML} will be used to provide the layout.
*/
protected getContentLayout(): Node {
return null;
const template = document.createElement("template");
template.innerHTML = this.getInnerHTML();
return template.content;
}
/**
@ -320,9 +322,6 @@ export class GameState {
*/
internalGetWrappedContent(): Node {
const elements = this.getContentLayout();
if (elements instanceof Node) {
return elements;
}
if (Array.isArray(elements)) {
const fragment = document.createDocumentFragment();
@ -330,10 +329,7 @@ export class GameState {
return fragment;
}
// Fall back to deprecated HTML strings solution
const template = document.createElement("template");
template.innerHTML = this.getInnerHTML();
return template.content;
return elements;
}
/**

View File

@ -30,6 +30,11 @@ export abstract class TextualGameState extends GameState {
return "";
}
/**
* Should return the element(s) to be displayed in the state.
* If not overridden, a default layout consisting of a back button,
* title, and content returned by {@link getInitialContent}.
*/
protected override getContentLayout(): Node {
let content = this.getInitialContent();
@ -44,9 +49,7 @@ export abstract class TextualGameState extends GameState {
`;
}
const template = document.createElement("template");
template.innerHTML = html;
content = template.content;
content = super.getContentLayout();
}
return (