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:
parent
ec8a6dec18
commit
8955e37c78
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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 (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user