Skip to content

Commit

Permalink
Link costumes from scripts 👔.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarty committed Sep 17, 2024
1 parent 86e9121 commit 156b94a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
54 changes: 54 additions & 0 deletions src/components/ScriptCodeInstruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,59 @@ const prettifyArguments = (operation) => {
let args = operation.slice(2);

switch (opCode) {
// resourceRoutines
case 0x0c:
case 0x8c:
if (args[0].endsWith('Costume')) {
// Note: The link goes to costume set 0. The actual costume set used can't be determined statically.
args = [
<Link
className="underline"
to={`/costumes/0/${args[1]}`}>
{args[0]}({args[1]})
</Link>,
];
} else if (args[0].endsWith('Room')) {
args = [
<Link
className="underline"
to={`/rooms/${args[1]}`}>
{args[0]}({args[1]})
</Link>,
];
} else if (args[0].endsWith('Script')) {
args = [
<Link
className="underline"
to={`/scripts/${args[1]}`}>
{args[0]}({args[1]})
</Link>,
];
}
break;
// actorOps
case 0x13:
case 0x53:
case 0x93:
case 0xd3:
if (args[1] === 'Color') {
args = [args[0], `${args[1]}(${args[3]}, ${args[2]})`];
} else if (args[1] === 'Name') {
args = [args[0], `${args[1]}("${args[2]}")`];
} else if (args[1] === 'Costume') {
// Note: The link goes to costume set 0. The actual costume set used can't be determined statically.
args = [
args[0],
<Link
className="underline"
to={`/costumes/0/${args[2]}`}>
{args[1]}({args[2]})
</Link>,
];
} else {
args = [args[0], `${args[1]}(${args[2]})`];
}
break;
case 0x18: // goTo
args = [
<Link
Expand All @@ -28,6 +81,7 @@ const prettifyArguments = (operation) => {
args[3],
];
break;
// loadRoom
case 0x72:
args = [
<Link
Expand Down
24 changes: 15 additions & 9 deletions src/lib/parser/parseScriptCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ const parseScriptCode = (parser, startAddress, parentOffset = 0) => {
case 0x0c:
case 0x8c: {
const resTypes = [
0, // Invalid
0, // Invalid
null, // Invalid
null, // Invalid
'Costume',
'Room',
'0', // Invalid
null, // Invalid
'Script',
'Sound',
];
Expand All @@ -169,7 +169,7 @@ const parseScriptCode = (parser, startAddress, parentOffset = 0) => {
}

const type = resTypes[subOp >> 4];
if (type === 0) {
if (!type) {
console.error(`Resource Routines: Invalid type ${type}`);
}

Expand Down Expand Up @@ -242,21 +242,27 @@ const parseScriptCode = (parser, startAddress, parentOffset = 0) => {
const subOp = parser.getUint8();
switch (subOp) {
case 0x01:
scriptRow.push(`Sound(${subOpArg})`);
scriptRow.push(`Sound`);
scriptRow.push(subOpArg);
break;
case 0x02:
const value = parser.getUint8();
scriptRow.push(`Color(${value}, ${subOpArg})`);
scriptRow.push(`Color`);
scriptRow.push(subOpArg);
scriptRow.push(value);
break;
case 0x03:
const name = parser.getString();
scriptRow.push(`Name("${name}")`);
scriptRow.push(`Name`);
scriptRow.push(name);
break;
case 0x04:
scriptRow.push(`Costume(${subOpArg})`);
scriptRow.push(`Costume`);
scriptRow.push(subOpArg);
break;
case 0x05:
scriptRow.push(`TalkColor(${subOpArg})`);
scriptRow.push(`TalkColor`);
scriptRow.push(subOpArg);
break;
default:
scriptRow.push(`// Unknown subop: 0x${hex(subOp, 2)}`);
Expand Down

0 comments on commit 156b94a

Please sign in to comment.