@@ -32,6 +32,13 @@ enum ToolbarNumberAttribute {
3232 MaxItems
3333}
3434
35+ enum InventoryNumberAttribute {
36+ //% block="selected index"
37+ SelectedIndex ,
38+ //% block="max items"
39+ MaxItems
40+ }
41+
3542//% color="#7732B3"
3643//% group="['Item', 'Toolbar', 'Inventory']"
3744namespace Inventory {
@@ -395,6 +402,16 @@ namespace Inventory {
395402 return this . _items ;
396403 }
397404
405+ /**
406+ * Get the items in the inventory. Only rewrapped for blocks.
407+ */
408+ //% block="%Inventory(Inventory) get items"
409+ //% weight=80
410+ //% group="Inventory"
411+ public get_items ( ) {
412+ return this . items ;
413+ }
414+
398415 /**
399416 * Set the items in the inventory.
400417 */
@@ -403,6 +420,14 @@ namespace Inventory {
403420 this . update ( ) ;
404421 }
405422
423+ //% block="%Inventory(Inventory) set items to %new_items"
424+ //% new_items.shadow="lists_create_with"
425+ //% weight=90
426+ //% group="Inventory"
427+ public set_items ( new_items : Item [ ] ) {
428+ this . items = new_items ;
429+ }
430+
406431 /**
407432 * Get the maximum amount of items in the inventory.
408433 */
@@ -417,6 +442,35 @@ namespace Inventory {
417442 this . _max_items = new_max ;
418443 this . update ( ) ;
419444 }
445+
446+ /**
447+ * Set the selected index or max items. Only rewrapped for blocks.
448+ */
449+ //% block="%Inventory(Inventory) set %attribute to %value"
450+ //% weight=70
451+ //% group="Inventory"
452+ public set_number ( attribute : InventoryNumberAttribute , value : number ) {
453+ if ( attribute == InventoryNumberAttribute . SelectedIndex ) {
454+ this . selected = value ;
455+ } else if ( attribute == InventoryNumberAttribute . MaxItems ) {
456+ this . max_items = value ;
457+ }
458+ }
459+
460+ /**
461+ * Get the selected index or max items. Only rewrapped for blocks.
462+ */
463+ //% block="%Inventory(Inventory) get %attribute"
464+ //% weight=60
465+ //% group="Inventory"
466+ public get_number ( attribute : InventoryNumberAttribute ) {
467+ if ( attribute == InventoryNumberAttribute . SelectedIndex ) {
468+ return this . selected ;
469+ } else if ( attribute == InventoryNumberAttribute . MaxItems ) {
470+ return this . max_items ;
471+ }
472+ return - 1 ;
473+ }
420474
421475 /**
422476 * Get the text in the inventory.
@@ -425,6 +479,16 @@ namespace Inventory {
425479 return this . _text ;
426480 }
427481
482+ /**
483+ * Get the text in the inventory. Only rewrapped for blocks.
484+ */
485+ //% block="%Inventory(Inventory) get text"
486+ //% weight=40
487+ //% group="Inventory"
488+ public get_text ( ) {
489+ return this . text ;
490+ }
491+
428492 /**
429493 * Set the text in the inventory.
430494 */
@@ -433,11 +497,25 @@ namespace Inventory {
433497 this . update ( ) ;
434498 }
435499
500+ /**
501+ * Set the text in the inventory. Only rewrapped for blocks.
502+ */
503+ //% block="%Inventory(Inventory) set text to %new_text"
504+ //% weight=50
505+ //% group="Inventory"
506+ public set_text ( new_text : string ) {
507+ this . text = new_text ;
508+ }
509+
436510 /**
437511 * Set a specific part of the inventory to a specific color.
438512 * @param attribute: A property of the InventoryColorAttribute enum.
439513 * @param color: A number which should be the new color of the attribute.
440514 */
515+ //% block="%Inventory(Inventory) set color of %attribute to %color"
516+ //% color.shadow=colorindexpicker
517+ //% weight=30
518+ //% group="Inventory"
441519 public set_color ( attribute : InventoryColorAttribute , color : number ) {
442520 if ( attribute == InventoryColorAttribute . InventoryOutline ) {
443521 this . _inv_outline_color = color ;
@@ -456,6 +534,9 @@ namespace Inventory {
456534 * @param attribute: A property of the InventoryColorAttribute enum.
457535 * @return : The color (which is a number) of the attribute, otherwise -1.
458536 */
537+ //% block="%Inventory(Inventory) get color of %attribute"
538+ //% weight=20
539+ //% group="Inventory"
459540 public get_color ( attribute : InventoryColorAttribute ) {
460541 if ( attribute == InventoryColorAttribute . InventoryOutline ) {
461542 return this . _inv_outline_color ;
@@ -472,6 +553,9 @@ namespace Inventory {
472553 /**
473554 * Update the image of the inventory.
474555 */
556+ //% block="%Inventory(Inventory) force redraw of inventory"
557+ //% weight=10
558+ //% group="Inventory"
475559 public update ( ) {
476560 let image_size : number = 16 ;
477561 let padding : number = 1 ;
@@ -501,4 +585,17 @@ namespace Inventory {
501585 this . setImage ( new_image ) ;
502586 }
503587 }
588+
589+ /**
590+ * Create a new inventory - for blocks.
591+ */
592+ //% block="create inventory with items %items and max items %max_items"
593+ //% blockSetVariable=inventory
594+ //% items.shadow="lists_create_with"
595+ //% max_items.dfl=3
596+ //% weight=100
597+ //% group="Inventory"
598+ export function create_inventory ( items : Item [ ] , max_items : number ) {
599+ return new Inventory ( items , max_items ) ;
600+ }
504601}
0 commit comments