pxt-common-packages 9.4.9 → 9.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,15 @@
1
- //% color="#7B2CBF" weight=100 icon="\uf021" block="Sprite Scaling"
2
- //% advanced=true
1
+ //% color="#95078E" weight=99 icon="\u2195" block="Sprite Scaling"
3
2
  namespace scaling {
4
- //% blockId=sprite_set_scale_ex
5
- //% block="set $sprite=variables_get(mySprite) scale to $value || $direction anchor $anchor"
3
+ //% blockId=sprite_scale_to_percent_ex
4
+ //% block="set $sprite=variables_get(mySprite) scale to $value percent $direction anchor $anchor"
6
5
  //% expandableArgumentMode=enabled
7
6
  //% inlineInputMode=inline
8
- //% value.defl=1
7
+ //% value.defl=150
9
8
  //% direction.defl=ScaleDirection.Uniformly
10
9
  //% anchor.defl=ScaleAnchor.Middle
11
- //% help=sprites/sprite-scaling/set-scale
12
- export function setScale(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
10
+ //% help=sprites/sprite-scaling/scale
11
+ export function scaleToPercent(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
12
+ value /= 100;
13
13
  direction = direction || ScaleDirection.Uniformly;
14
14
  anchor = anchor || ScaleAnchor.Middle;
15
15
 
@@ -22,82 +22,91 @@ namespace scaling {
22
22
  sprite.setScaleCore(sx, sy, anchor);
23
23
  }
24
24
 
25
- //% blockId=sprite_grow_by_percent_ex
26
- //% block="grow $sprite=variables_get(mySprite) by $amount percent || $direction anchor $anchor"
25
+ //% blockId=sprite_scale_by_percent_ex
26
+ //% block="change $sprite=variables_get(mySprite) scale by $value percent $direction anchor $anchor"
27
27
  //% expandableArgumentMode=enabled
28
28
  //% inlineInputMode=inline
29
- //% amount.defl=10
29
+ //% value.defl=50
30
30
  //% direction.defl=ScaleDirection.Uniformly
31
31
  //% anchor.defl=ScaleAnchor.Middle
32
- //% help=sprites/sprite-scaling/grow-by-amount
33
- export function growByPercent(sprite: Sprite, amount: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
34
- amount /= 100;
32
+ //% help=sprites/sprite-scaling/scale
33
+ export function scaleByPercent(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
34
+ value /= 100;
35
35
  direction = direction || ScaleDirection.Uniformly;
36
36
  anchor = anchor || ScaleAnchor.Middle;
37
37
 
38
38
  let sx: number;
39
39
  let sy: number;
40
40
 
41
- if (direction & ScaleDirection.Horizontally) sx = sprite.sx + amount;
42
- if (direction & ScaleDirection.Vertically) sy = sprite.sy + amount;
41
+ if (direction & ScaleDirection.Horizontally) sx = sprite.sx + value;
42
+ if (direction & ScaleDirection.Vertically) sy = sprite.sy + value;
43
43
 
44
44
  sprite.setScaleCore(sx, sy, anchor);
45
45
  }
46
46
 
47
- //% blockId=sprite_shrink_by_percent_ex
48
- //% block="shrink $sprite=variables_get(mySprite) by $amount percent || $direction anchor $anchor"
47
+ //% blockId=sprite_scale_to_pixels_ex
48
+ //% block="set $sprite=variables_get(mySprite) scale to $value pixels $direction anchor $anchor || proportional $proportional"
49
49
  //% expandableArgumentMode=enabled
50
50
  //% inlineInputMode=inline
51
- //% amount.defl=10
52
- //% direction.defl=ScaleDirection.Uniformly
53
- //% anchor.defl=ScaleAnchor.Middle
54
- //% help=sprites/sprite-scaling/shrink-by-percent
55
- export function shrinkByPercent(sprite: Sprite, amount: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
56
- growByPercent(sprite, -amount, direction, anchor);
57
- }
58
-
59
- //% blockId=sprite_grow_by_pixels_ex
60
- //% block="grow $sprite=variables_get(mySprite) by $amount pixels $direction || anchor $anchor proportional $proportional"
61
- //% expandableArgumentMode=enabled
62
- //% inlineInputMode=inline
63
- //% amount.defl=10
51
+ //% value.defl=32
64
52
  //% direction.defl=ScaleDirection.Horizontally
65
53
  //% anchor.defl=ScaleAnchor.Middle
66
54
  //% proportional.defl=0
67
- //% help=sprites/sprite-scaling/grow-by-pixels
68
- export function growByPixels(sprite: Sprite, amount: number, direction?: ScaleDirection, anchor?: ScaleAnchor, proportional?: boolean): void {
55
+ //% help=sprites/sprite-scaling/scale
56
+ export function scaleToPixels(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor, proportional?: boolean): void {
69
57
  direction = direction || ScaleDirection.Horizontally;
70
58
  anchor = anchor || ScaleAnchor.Middle;
71
- if (typeof proportional !== 'boolean') proportional = direction === ScaleDirection.Uniformly;
59
+
60
+ if (proportional == null) proportional = direction === ScaleDirection.Uniformly;
72
61
 
73
62
  let sx: number;
74
63
  let sy: number;
75
64
 
76
65
  if (direction & ScaleDirection.Horizontally) {
77
66
  const imgW = sprite.image.width;
78
- const newW = sprite.width + amount;
67
+ const newW = value;
79
68
  sx = newW / imgW;
80
69
  }
81
70
 
82
71
  if (direction & ScaleDirection.Vertically) {
83
72
  const imgH = sprite.image.height;
84
- const newH = sprite.height + amount;
73
+ const newH = value;
85
74
  sy = newH / imgH;
86
75
  }
87
76
 
88
77
  sprite.setScaleCore(sx, sy, anchor, proportional);
89
78
  }
90
79
 
91
- //% blockId=sprite_shrink_by_pixels_ex
92
- //% block="shrink $sprite=variables_get(mySprite) by $amount pixels $direction || anchor $anchor proportional $proportional"
80
+ //% blockId=sprite_scale_by_pixels_ex
81
+ //% block="change $sprite=variables_get(mySprite) scale by $value pixels $direction anchor $anchor || proportional $proportional"
93
82
  //% expandableArgumentMode=enabled
94
83
  //% inlineInputMode=inline
95
- //% amount.defl=10
84
+ //% value.defl=10
96
85
  //% direction.defl=ScaleDirection.Horizontally
97
86
  //% anchor.defl=ScaleAnchor.Middle
98
87
  //% proportional.defl=0
99
- //% help=sprites/sprite-scaling/grow-by-pixels
100
- export function shrinkByPixels(sprite: Sprite, amount: number, direction?: ScaleDirection, anchor?: ScaleAnchor, proportional?: boolean): void {
101
- growByPixels(sprite, -amount, direction, anchor, proportional);
88
+ //% help=sprites/sprite-scaling/scale
89
+ export function scaleByPixels(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor, proportional?: boolean): void {
90
+ direction = direction || ScaleDirection.Horizontally;
91
+ anchor = anchor || ScaleAnchor.Middle;
92
+
93
+ if (proportional == null) proportional = direction === ScaleDirection.Uniformly;
94
+
95
+ let sx: number;
96
+ let sy: number;
97
+
98
+ if (direction & ScaleDirection.Horizontally) {
99
+ const imgW = sprite.image.width;
100
+ const newW = sprite.width + value;
101
+ sx = newW / imgW;
102
+ }
103
+
104
+ if (direction & ScaleDirection.Vertically) {
105
+ const imgH = sprite.image.height;
106
+ const newH = sprite.height + value;
107
+ sy = newH / imgH;
108
+ }
109
+
110
+ sprite.setScaleCore(sx, sy, anchor, proportional);
102
111
  }
103
112
  }
@@ -34518,7 +34518,7 @@ switch (step) {
34518
34518
  return leave(s, r0)
34519
34519
  default: oops()
34520
34520
  } } }
34521
- Sprite_toString__P153950.info = {"start":37695,"length":93,"line":1169,"column":4,"endLine":1171,"endColumn":5,"fileName":"pxt_modules/game/sprite.ts","functionName":"toString","argumentNames":["this"]}
34521
+ Sprite_toString__P153950.info = {"start":37672,"length":93,"line":1169,"column":4,"endLine":1171,"endColumn":5,"fileName":"pxt_modules/game/sprite.ts","functionName":"toString","argumentNames":["this"]}
34522
34522
 
34523
34523
  function Sprite_toString__P153950_mk(s) {
34524
34524
  checkStack(s.depth);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pxt-common-packages",
3
- "version": "9.4.9",
3
+ "version": "9.4.10",
4
4
  "description": "Microsoft MakeCode (PXT) common packages",
5
5
  "keywords": [
6
6
  "MakeCode",