mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 02:31:51 +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.
|
* 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 {
|
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 {
|
internalGetWrappedContent(): Node {
|
||||||
const elements = this.getContentLayout();
|
const elements = this.getContentLayout();
|
||||||
if (elements instanceof Node) {
|
|
||||||
return elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(elements)) {
|
if (Array.isArray(elements)) {
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
@ -330,10 +329,7 @@ export class GameState {
|
|||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to deprecated HTML strings solution
|
return elements;
|
||||||
const template = document.createElement("template");
|
|
||||||
template.innerHTML = this.getInnerHTML();
|
|
||||||
return template.content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -30,6 +30,11 @@ export abstract class TextualGameState extends GameState {
|
|||||||
return "";
|
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 {
|
protected override getContentLayout(): Node {
|
||||||
let content = this.getInitialContent();
|
let content = this.getInitialContent();
|
||||||
|
|
||||||
@ -44,9 +49,7 @@ export abstract class TextualGameState extends GameState {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const template = document.createElement("template");
|
content = super.getContentLayout();
|
||||||
template.innerHTML = html;
|
|
||||||
content = template.content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user