Skip to content

Commit bf0c4dd

Browse files
Merge pull request #30 from GoogleChromeLabs/pizza-nits
Add Wales style and fix share in non-WebMCP
2 parents 75ab6e8 + cb22cb5 commit bf0c4dd

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

β€Ždemos/pizza-maker/README.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ navigator.modelContext.registerTool({
3232

3333
When an AI agent is active, it can:
3434
- **Change Size**: Adjust the pizza size from Small to "Too Large".
35-
- **Set Style**: Switch between Classic, Bianca, BBQ, and Pesto themes.
35+
- **Set Style**: Switch between Classic, Bianca, BBQ, Pesto, and Wales themes.
3636
- **Manage Layers**: Add or remove sauce and cheese.
3737
- **Add/Remove Toppings**: Place various emoji-based toppings on the pizza with realistic animations.
3838
- **Share**: Generate a shareable URL that encodes the current pizza state.

β€Ždemos/pizza-maker/index.htmlβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ <h1>WebMCP zaMaker!</h1>
3838
<button class="btn-style" onclick="setPizzaStyle('Bianca')">Bianca</button>
3939
<button class="btn-style" onclick="setPizzaStyle('BBQ')">BBQ</button>
4040
<button class="btn-style" onclick="setPizzaStyle('Pesto')">Pesto</button>
41+
<button class="btn-style" onclick="setPizzaStyle('Wales')">Wales</button>
4142
</div>
4243
<hr />
4344
<div class="btn-group">

β€Ždemos/pizza-maker/script.jsβ€Ž

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const styles = {
1919
Bianca: { crust: '#e6c27b', sauce: '#fff3e0', cheese: '#fff9c4' },
2020
BBQ: { crust: '#d4a342', sauce: '#5d4037', cheese: '#ffab00' },
2121
Pesto: { crust: '#c5e1a5', sauce: '#388e3c', cheese: '#f1f8e9' },
22+
Wales: { crust: '#53d442', sauce: '#d32f2f', cheese: '#ffffff' },
2223
};
2324

2425
function setPizzaStyle(styleName) {
@@ -28,6 +29,9 @@ function setPizzaStyle(styleName) {
2829
document.documentElement.style.setProperty('--crust', style.crust);
2930
document.documentElement.style.setProperty('--sauce', style.sauce);
3031
document.documentElement.style.setProperty('--cheese', style.cheese);
32+
if (styleName === 'Wales') {
33+
addTopping('πŸ‘', 'Medium', 10);
34+
}
3135
}
3236
}
3337

@@ -104,9 +108,7 @@ function resetPizza() {
104108
function getPizzaState() {
105109
const sauceVisible = document.getElementById('sauce-layer').style.display === 'block';
106110
const cheeseVisible = document.getElementById('cheese-layer').style.display === 'block';
107-
const toppings = Array.from(document.querySelectorAll('.topping span')).map(
108-
(s) => s.innerText,
109-
);
111+
const toppings = Array.from(document.querySelectorAll('.topping span')).map((s) => s.innerText);
110112

111113
return {
112114
size: sizeText.innerText,
@@ -116,7 +118,7 @@ function getPizzaState() {
116118
};
117119
}
118120

119-
function sharePizza() {
121+
function sharePizza(agentInvoked = false) {
120122
const state = getPizzaState();
121123
const jsonString = JSON.stringify(state);
122124
// Correctly handle Unicode (emojis) with btoa
@@ -126,7 +128,15 @@ function sharePizza() {
126128
const params = new URLSearchParams(url.search);
127129
params.set('share', base64);
128130
url.search = params.toString();
129-
return url.toString();
131+
const shareUrl = url.toString();
132+
133+
navigator.clipboard.writeText(shareUrl).then(() => {
134+
if (!agentInvoked) {
135+
alert('Link copied to clipboard!');
136+
}
137+
});
138+
139+
return shareUrl;
130140
}
131141

132142
function loadPizzaStateFromURL() {
@@ -186,7 +196,7 @@ if (window.navigator.modelContext) {
186196
inputSchema: {
187197
type: 'object',
188198
properties: {
189-
style: { type: 'string', enum: ['Classic', 'Bianca', 'BBQ', 'Pesto'] },
199+
style: { type: 'string', enum: ['Classic', 'Bianca', 'BBQ', 'Pesto', 'Wales'] },
190200
},
191201
required: ['style'],
192202
},
@@ -224,7 +234,7 @@ if (window.navigator.modelContext) {
224234
properties: {
225235
topping: {
226236
type: 'string',
227-
enum: ['πŸ•', 'πŸ„', '🌿', '🍍', 'πŸ«‘', 'πŸ₯“', 'πŸ§…', 'πŸ«’', '🌽', '🌢️'],
237+
enum: ['πŸ•', 'πŸ„', '🌿', '🍍', 'πŸ«‘', 'πŸ₯“', 'πŸ§…', 'πŸ«’', '🌽', '🌢️', 'πŸ‘'],
228238
},
229239
size: { type: 'string', enum: ['Small', 'Medium', 'Large', 'Extra Large'] },
230240
count: {
@@ -249,7 +259,7 @@ if (window.navigator.modelContext) {
249259
properties: {
250260
topping: {
251261
type: 'string',
252-
enum: ['πŸ•', 'πŸ„', '🌿', '🍍', 'πŸ«‘', 'πŸ₯“', 'πŸ§…', 'πŸ«’', '🌽', '🌢️'],
262+
enum: ['πŸ•', 'πŸ„', '🌿', '🍍', 'πŸ«‘', 'πŸ₯“', 'πŸ§…', 'πŸ«’', '🌽', '🌢️', 'πŸ‘'],
253263
},
254264
all: {
255265
type: 'boolean',

0 commit comments

Comments
Β (0)