mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #884 from paulkaplan/costume-backdrop-blocks
Implement opcodes for new costume/backdrop reporters
This commit is contained in:
commit
980efedf0f
4 changed files with 92 additions and 17 deletions
|
@ -236,9 +236,8 @@ class Scratch3LooksBlocks {
|
||||||
looks_gotofrontback: this.goToFrontBack,
|
looks_gotofrontback: this.goToFrontBack,
|
||||||
looks_goforwardbackwardlayers: this.goForwardBackwardLayers,
|
looks_goforwardbackwardlayers: this.goForwardBackwardLayers,
|
||||||
looks_size: this.getSize,
|
looks_size: this.getSize,
|
||||||
looks_costumeorder: this.getCostumeIndex,
|
looks_costumenumbername: this.getCostumeNumberName,
|
||||||
looks_backdroporder: this.getBackdropIndex,
|
looks_backdropnumbername: this.getBackdropNumberName
|
||||||
looks_backdropname: this.getBackdropName
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,18 +432,21 @@ class Scratch3LooksBlocks {
|
||||||
return Math.round(util.target.size);
|
return Math.round(util.target.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
getBackdropIndex () {
|
getBackdropNumberName (args) {
|
||||||
const stage = this.runtime.getTargetForStage();
|
|
||||||
return stage.currentCostume + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
getBackdropName () {
|
|
||||||
const stage = this.runtime.getTargetForStage();
|
const stage = this.runtime.getTargetForStage();
|
||||||
|
if (args.NUMBER_NAME === 'number') {
|
||||||
|
return stage.currentCostume + 1;
|
||||||
|
}
|
||||||
|
// Else return name
|
||||||
return stage.sprite.costumes[stage.currentCostume].name;
|
return stage.sprite.costumes[stage.currentCostume].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCostumeIndex (args, util) {
|
getCostumeNumberName (args, util) {
|
||||||
return util.target.currentCostume + 1;
|
if (args.NUMBER_NAME === 'number') {
|
||||||
|
return util.target.currentCostume + 1;
|
||||||
|
}
|
||||||
|
// Else return name
|
||||||
|
return util.target.sprite.costumes[util.target.currentCostume].name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -602,17 +602,38 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updated layering blocks
|
// Updates for blocks that have new menus (e.g. in Looks)
|
||||||
if (oldOpcode === 'comeToFront') {
|
switch (oldOpcode) {
|
||||||
|
case 'comeToFront':
|
||||||
activeBlock.fields.FRONT_BACK = {
|
activeBlock.fields.FRONT_BACK = {
|
||||||
name: 'FRONT_BACK',
|
name: 'FRONT_BACK',
|
||||||
value: 'front'
|
value: 'front'
|
||||||
};
|
};
|
||||||
} else if (oldOpcode === 'goBackByLayers:') {
|
break;
|
||||||
|
case 'goBackByLayers:':
|
||||||
activeBlock.fields.FORWARD_BACKWARD = {
|
activeBlock.fields.FORWARD_BACKWARD = {
|
||||||
name: 'FORWARD_BACKWARD',
|
name: 'FORWARD_BACKWARD',
|
||||||
value: 'backward'
|
value: 'backward'
|
||||||
};
|
};
|
||||||
|
break;
|
||||||
|
case 'backgroundIndex':
|
||||||
|
activeBlock.fields.NUMBER_NAME = {
|
||||||
|
name: 'NUMBER_NAME',
|
||||||
|
value: 'number'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'sceneName':
|
||||||
|
activeBlock.fields.NUMBER_NAME = {
|
||||||
|
name: 'NUMBER_NAME',
|
||||||
|
value: 'name'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'costumeIndex':
|
||||||
|
activeBlock.fields.NUMBER_NAME = {
|
||||||
|
name: 'NUMBER_NAME',
|
||||||
|
value: 'number'
|
||||||
|
};
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special cases to generate mutations.
|
// Special cases to generate mutations.
|
||||||
|
|
|
@ -360,12 +360,12 @@ const specMap = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'costumeIndex': {
|
'costumeIndex': {
|
||||||
opcode: 'looks_costumeorder',
|
opcode: 'looks_costumenumbername',
|
||||||
argMap: [
|
argMap: [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'sceneName': {
|
'sceneName': {
|
||||||
opcode: 'looks_backdropname',
|
opcode: 'looks_backdropnumbername',
|
||||||
argMap: [
|
argMap: [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -390,7 +390,7 @@ const specMap = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'backgroundIndex': {
|
'backgroundIndex': {
|
||||||
opcode: 'looks_backdroporder',
|
opcode: 'looks_backdropnumbername',
|
||||||
argMap: [
|
argMap: [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
52
test/unit/blocks_looks.js
Normal file
52
test/unit/blocks_looks.js
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
const test = require('tap').test;
|
||||||
|
const Looks = require('../../src/blocks/scratch3_looks');
|
||||||
|
const util = {
|
||||||
|
target: {
|
||||||
|
currentCostume: 0, // Internally, current costume is 0 indexed
|
||||||
|
sprite: {
|
||||||
|
costumes: [
|
||||||
|
{name: 'first name'},
|
||||||
|
{name: 'second name'},
|
||||||
|
{name: 'third name'}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fakeRuntime = {
|
||||||
|
getTargetForStage: () => util.target, // Just return the dummy target above.
|
||||||
|
on: () => {} // Stub out listener methods used in constructor.
|
||||||
|
};
|
||||||
|
const blocks = new Looks(fakeRuntime);
|
||||||
|
|
||||||
|
test('getCostumeNumberName returns 1-indexed costume number', t => {
|
||||||
|
util.target.currentCostume = 0; // This is 0-indexed.
|
||||||
|
const args = {NUMBER_NAME: 'number'};
|
||||||
|
const number = blocks.getCostumeNumberName(args, util);
|
||||||
|
t.strictEqual(number, 1);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getCostumeNumberName can return costume name', t => {
|
||||||
|
util.target.currentCostume = 0; // This is 0-indexed.
|
||||||
|
const args = {NUMBER_NAME: 'name'};
|
||||||
|
const number = blocks.getCostumeNumberName(args, util);
|
||||||
|
t.strictEqual(number, 'first name');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getBackdropNumberName returns 1-indexed costume number', t => {
|
||||||
|
util.target.currentCostume = 2; // This is 0-indexed.
|
||||||
|
const args = {NUMBER_NAME: 'number'};
|
||||||
|
const number = blocks.getBackdropNumberName(args, util);
|
||||||
|
t.strictEqual(number, 3);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getBackdropNumberName can return costume name', t => {
|
||||||
|
util.target.currentCostume = 2; // This is 0-indexed.
|
||||||
|
const args = {NUMBER_NAME: 'name'};
|
||||||
|
const number = blocks.getBackdropNumberName(args, util);
|
||||||
|
t.strictEqual(number, 'third name');
|
||||||
|
t.end();
|
||||||
|
});
|
Loading…
Reference in a new issue