overlay inventory with doc

pull/118/head
Jon Eugster 3 years ago
parent a05361022e
commit e339f00e21

@ -7,17 +7,12 @@ import Markdown from './Markdown';
import { useLoadDocQuery, InventoryTile, LevelInfo } from '../state/api'; import { useLoadDocQuery, InventoryTile, LevelInfo } from '../state/api';
import { GameIdContext } from '../App'; import { GameIdContext } from '../App';
export function Inventory({levelInfo, setInventoryDoc } : export function Inventory({levelInfo, openDoc } :
{ {
levelInfo: LevelInfo, levelInfo: LevelInfo,
setInventoryDoc: (inventoryDoc: {name: string, type: string}) => void, openDoc: (name: string, type: string) => void,
}) { }) {
// TODO: This seems like a useless wrapper to me
function openDoc(name, type) {
setInventoryDoc({name, type})
}
return ( return (
<div className="inventory"> <div className="inventory">
{/* TODO: Click on Tactic: show info {/* TODO: Click on Tactic: show info
@ -98,14 +93,15 @@ function InventoryItem({name, displayName, locked, disabled, newly, showDoc}) {
return <div className={`item ${className}`} onClick={handleClick} title={title}>{icon} {displayName}</div> return <div className={`item ${className}`} onClick={handleClick} title={title}>{icon} {displayName}</div>
} }
export function Documentation({name, type}) { export function Documentation({name, type, handleClose}) {
const gameId = React.useContext(GameIdContext) const gameId = React.useContext(GameIdContext)
const doc = useLoadDocQuery({game: gameId, type: type, name: name}) const doc = useLoadDocQuery({game: gameId, type: type, name: name})
return <> return <div className="documentation">
<h2 className="doc">{doc.data?.displayName}</h2> <div className="codicon codicon-close modal-close" onClick={handleClose}></div>
<h1 className="doc">{doc.data?.displayName}</h1>
<p><code>{doc.data?.statement}</code></p> <p><code>{doc.data?.statement}</code></p>
{/* <code>docstring: {doc.data?.docstring}</code> */} {/* <code>docstring: {doc.data?.docstring}</code> */}
<Markdown>{doc.data?.content}</Markdown> <Markdown>{doc.data?.content}</Markdown>
</> </div>
} }

@ -188,9 +188,18 @@ function PlayableLevel({worldId, levelId}) {
} }
}, [editor, commandLineMode]) }, [editor, commandLineMode])
// if this is set to a pair `(name, type)` then the according doc will be open. // When clicking on an inventory item, the inventory is overlayed by the item's doc.
// If this state is set to a pair `(name, type)` then the according doc will be open.
const [inventoryDoc, setInventoryDoc] = useState<{name: string, type: string}>(null) const [inventoryDoc, setInventoryDoc] = useState<{name: string, type: string}>(null)
// TODO: This seems like a useless wrapper to me
function openInventoryDoc(name, type) {
setInventoryDoc({name, type})
}
// Set `inventoryDoc` to `null` to close the doc
const closeInventoryDoc = () => setInventoryDoc(null);
const levelTitle = <>{levelId && `Level ${levelId}`}{level?.data?.title && `: ${level?.data?.title}`}</> const levelTitle = <>{levelId && `Level ${levelId}`}{level?.data?.title && `: ${level?.data?.title}`}</>
return <> return <>
@ -256,11 +265,13 @@ function PlayableLevel({worldId, levelId}) {
</div> </div>
<div className="inventory-panel"> <div className="inventory-panel">
{!level.isLoading && {!level.isLoading &&
<Inventory levelInfo={level?.data} setInventoryDoc={setInventoryDoc} />} <>{inventoryDoc ?
<Documentation name={inventoryDoc.name} type={inventoryDoc.type} handleClose={closeInventoryDoc}/>
:
<Inventory levelInfo={level?.data} openDoc={openInventoryDoc} />
}</>
}
</div> </div>
{/* <div className="doc-panel">
{inventoryDoc && <Documentation name={inventoryDoc.name} type={inventoryDoc.type} />}
</div> */}
</Split> </Split>
</> </>
} }

@ -1,13 +1,22 @@
.inventory { .inventory, .documentation {
padding: 0 1em 1em 1em; padding: 0 1em 1em 1em;
} }
.inventory h2 { .inventory h2, .documentation h2, .documentation h1 {
font-size: 1.5em; font-size: 1.5em;
margin-top: 1em; margin-top: 1em;
margin-bottom: .2em; margin-bottom: .2em;
} }
.documentation h1 {
font-weight: 900;
}
.documentation.hidden {
display: none;
transition: display 2s;
}
.inventory-list { .inventory-list {
display: flex; display: flex;
gap: .5em; gap: .5em;
@ -55,15 +64,3 @@
color: black; color: black;
border-bottom: 0.3em solid var(--clr-primary); border-bottom: 0.3em solid var(--clr-primary);
} }
.doc-panel {
padding: 0 1em;
}
.doc-panel h2 {
font-size: 1.5em;
margin-top: 1em;
margin-bottom: .2em;
font-weight: 900;
}

Loading…
Cancel
Save