add syntax for attr in statements; add new key to computed inventory items.

pull/68/head
Jon Eugster 3 years ago
parent d837344797
commit ebcc1df171

@ -73,17 +73,19 @@ function InventoryList({items, docType, openDoc, defaultTab=null, level=undefine
).map(item => { ).map(item => {
if ((tab ?? categories[0]) == item.category) { if ((tab ?? categories[0]) == item.category) {
return <InventoryItem key={item.name} showDoc={() => {openDoc(item.name, docType)}} return <InventoryItem key={item.name} showDoc={() => {openDoc(item.name, docType)}}
name={item.name} displayName={item.displayName} locked={item.locked} disabled={item.disabled} /> name={item.name} displayName={item.displayName} locked={item.locked}
disabled={item.disabled} newly={item.new}/>
} }
}) } }) }
</div> </div>
</> </>
} }
function InventoryItem({name, displayName, locked, disabled, showDoc}) { function InventoryItem({name, displayName, locked, disabled, newly, showDoc}) {
const icon = locked ? <FontAwesomeIcon icon={faLock} /> : const icon = locked ? <FontAwesomeIcon icon={faLock} /> :
disabled ? <FontAwesomeIcon icon={faBan} /> : "" disabled ? <FontAwesomeIcon icon={faBan} /> : ""
const className = locked ? "locked" : disabled ? "disabled" : "" const className = newly ? "new" : "old"
// const className = locked ? "locked" : disabled ? "disabled" : newly ? "new" : ""
const title = locked ? "Not unlocked yet" : const title = locked ? "Not unlocked yet" :
disabled ? "Not available in this level" : "" disabled ? "Not available in this level" : ""

@ -26,6 +26,9 @@
color: #ccc; color: #ccc;
} }
.inventory .item.new {
color: rgb(247, 216, 93);
}
.inventory .item:not(.locked):not(.disabled) { .inventory .item:not(.locked):not(.disabled) {
cursor: pointer; cursor: pointer;

@ -15,7 +15,8 @@ export interface ComputedInventoryItem {
displayName: string, displayName: string,
category: string, category: string,
disabled: boolean, disabled: boolean,
locked: boolean locked: boolean,
new: boolean
} }
export interface LevelInfo { export interface LevelInfo {

@ -72,7 +72,7 @@ elab "Path" s:Parser.path : command => do
/-! # Inventory /-! # Inventory
The inventory contains docs for tactics, lemmas, and definitions. These are all disabled The inventory contains docs for tactics, lemmas, and definitions. These are all locked
in the first level and get enabled during the game. in the first level and get enabled during the game.
-/ -/
@ -222,8 +222,11 @@ partial def reprintCore : Syntax → Option Format
def reprint (stx : Syntax) : Format := def reprint (stx : Syntax) : Format :=
reprintCore stx |>.getD "" reprintCore stx |>.getD ""
/-- A `attr := ...` option for `Statement`. Add attributes to the defined theorem. -/
syntax statementAttr := "(" &"attr" ":=" Parser.Term.attrInstance,* ")"
/-- Define the statement of the current level. -/ /-- Define the statement of the current level. -/
elab "Statement" statementName:ident ? descr:str ? sig:declSig val:declVal : command => do elab "Statement" statementName:ident ? attr:statementAttr ? descr:str ? sig:declSig val:declVal : command => do
let lvlIdx ← getCurLevelIdx let lvlIdx ← getCurLevelIdx
-- Save the messages before evaluation of the proof. -- Save the messages before evaluation of the proof.
@ -485,12 +488,12 @@ elab "MakeGame" : command => do
return (item, { return (item, {
name := item name := item
displayName := data.displayName displayName := data.displayName
category := data.category category := data.category })
locked := true })
-- Availability after a given world -- Availability after a given world
let mut itemsInWorld : HashMap Name (HashMap Name ComputedInventoryItem) := {} let mut itemsInWorld : HashMap Name (HashMap Name ComputedInventoryItem) := {}
for (worldId, _) in game.worlds.nodes.toArray do for (worldId, _) in game.worlds.nodes.toArray do
-- Unlock all items from previous worlds
let mut items := Availability₀ let mut items := Availability₀
let predecessors := game.worlds.predecessors worldId let predecessors := game.worlds.predecessors worldId
for predWorldId in predecessors do for predWorldId in predecessors do
@ -511,16 +514,18 @@ elab "MakeGame" : command => do
for (levelId, level) in levels do for (levelId, level) in levels do
let levelInfo := level.getInventory inventoryType let levelInfo := level.getInventory inventoryType
-- add items in `levelInfo.new` permanently as unlocked -- unlock items that are unlocked in this level
for item in levelInfo.new do for item in levelInfo.new do
let data := (← getInventoryDoc? item inventoryType).get! let data := (← getInventoryDoc? item inventoryType).get!
items := items.insert item { items := items.insert item {
name := item name := item
displayName := data.displayName displayName := data.displayName
category := data.category category := data.category
new := true
locked := false } locked := false }
-- add the statement from the previous level permanently as unlocked -- add the exercise statement from the previous level
-- if it was named
if inventoryType == .Lemma then if inventoryType == .Lemma then
match lemmaStatements.find? (worldId, levelId) with match lemmaStatements.find? (worldId, levelId) with
| none => pure () | none => pure ()
@ -530,14 +535,14 @@ elab "MakeGame" : command => do
name := name name := name
displayName := data.displayName displayName := data.displayName
category := data.category category := data.category
new := true
locked := false } locked := false }
-- sort items and disable disabled ones
let itemsArray := items.toArray let itemsArray := items.toArray
|>.insertionSort (fun a b => a.1.toString < b.1.toString) |>.insertionSort (fun a b => a.1.toString < b.1.toString)
|>.map (·.2) |>.map (·.2)
|>.map (fun item => { item with |>.map (fun item => { item with
-- if `levelInfo.only` is set, disable everything not in there,
-- otherwise disable all in `levelInfo.disabled`
disabled := if levelInfo.only.size == 0 then disabled := if levelInfo.only.size == 0 then
levelInfo.disabled.contains item.name levelInfo.disabled.contains item.name
else else

@ -72,9 +72,11 @@ structure ComputedInventoryItem where
/-- Category to group inventory items by (currently only used for lemmas). -/ /-- Category to group inventory items by (currently only used for lemmas). -/
category : String category : String
/-- If `true` then the item only gets unlocked in a later level. -/ /-- If `true` then the item only gets unlocked in a later level. -/
locked : Bool locked := true
/-- If `true` then the item is blocked for this level. -/ /-- If `true` then the item is blocked for this level. -/
disabled : Bool := false disabled := false
/-- To mark an item that has been added freshly in this level. -/
new := false
deriving ToJson, FromJson, Repr, Inhabited deriving ToJson, FromJson, Repr, Inhabited
/-- Environment extension for inventory documentation. -/ /-- Environment extension for inventory documentation. -/

Loading…
Cancel
Save