Skip to content

Commit b44c9fe

Browse files
authored
Merge pull request #266 from opentiny/add-extend-case
feat(homepage): add coin game case
2 parents b8a8454 + 885374d commit b44c9fe

7 files changed

Lines changed: 616 additions & 144 deletions

File tree

pnpm-lock.yaml

Lines changed: 107 additions & 128 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sites/homepage/web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"preview": "vite preview"
1212
},
1313
"dependencies": {
14-
"@opentiny/genui-sdk-vue": "1.1.0",
14+
"@opentiny/genui-sdk-vue": "1.3.0",
15+
"@opentiny/genui-sdk-materials-vue-opentiny-vue": "1.3.0",
1516
"@opentiny/tiny-robot-svgs": "^0.3.3",
1617
"@opentiny/vue": "~3.28.0",
1718
"@opentiny/vue-button": "~3.28.0",

sites/homepage/web/src/components/HomeExtend.vue

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang="ts">
22
import { onMounted, onUnmounted, ref, computed, watch } from 'vue';
33
import { TinyButton, TinyButtonGroup, TinyTooltip } from '@opentiny/vue';
4-
import { GenuiRenderer } from '@opentiny/genui-sdk-vue';
4+
import { GenuiRenderer, GenuiConfigProvider } from '@opentiny/genui-sdk-vue';
5+
import { materials } from '@opentiny/genui-sdk-materials-vue-opentiny-vue';
56
import { IconAi, IconUser } from '@opentiny/tiny-robot-svgs';
67
import { IconArrowRight, IconPause, IconRefresh, IconStartCircle } from '@opentiny/vue-icon';
78
import { LinkKey, linkMap } from '@/utils/link';
@@ -10,6 +11,8 @@ import { splitJsonIntoChunks } from '@/utils/jsonUtil';
1011
import caculatorJson from '@/static/caculator.json';
1112
import todoJson from '@/static/todo.json';
1213
import todoJsonEn from '@/static/todo.en.json';
14+
import coinGameJson from '@/static/coin-game.json';
15+
import coinGameJsonEn from '@/static/coin-game.en.json';
1316
import { t, locale } from '@/i18n';
1417
1518
const TinyIconArrowRight = IconArrowRight();
@@ -37,17 +40,21 @@ let revealCardOnFirstChunk = false;
3740
const messageContentMap = {
3841
element: t('extend.prompt.element'),
3942
page: t('extend.prompt.page'),
43+
coin: t('extend.prompt.coin'),
4044
};
4145
const bubbleContentMap = {
4246
element: t('extend.prompt.elementBubble'),
4347
page: t('extend.prompt.pageBubble'),
48+
coin: t('extend.prompt.coinBubble'),
4449
};
4550
const inputMessage = computed(
4651
() => `?input-message=${messageContentMap[extendSelect.value as keyof typeof messageContentMap]}`,
4752
);
4853
49-
/** 已开始回放流程(生成中 / 准备中 / 暂停待续)时固定在右下角;仅待播放或重播待命时居中 */
50-
const streamControlsDocked = computed(() => generating.value || preparingPlayback.value || !streamCompleted.value);
54+
/** 首次播放按钮居中展示;生成中 / 暂停 / 播放过后的重放均固定右下角,避免遮挡内容 */
55+
const streamControlsDocked = computed(
56+
() => generating.value || preparingPlayback.value || !streamCompleted.value || hasPlayedOnce.value,
57+
);
5158
5259
const userBubbleContent = computed(
5360
() => bubbleContentMap[extendSelect.value as keyof typeof bubbleContentMap],
@@ -57,6 +64,9 @@ const getJsonData = (type: string) => {
5764
if (type === 'element') {
5865
return caculatorJson;
5966
}
67+
if (type === 'coin') {
68+
return locale.value === 'en_US' ? coinGameJsonEn : coinGameJson;
69+
}
6070
return locale.value === 'en_US' ? todoJsonEn : todoJson;
6171
};
6272
@@ -227,7 +237,7 @@ const handleCornerReplay = () => {
227237
};
228238
229239
watch(isMobile, (mobile) => {
230-
if (mobile && extendSelect.value === 'page') {
240+
if (mobile && (extendSelect.value === 'page' || extendSelect.value === 'coin')) {
231241
handleExtendClick('element');
232242
}
233243
});
@@ -268,6 +278,16 @@ onUnmounted(() => {
268278
>
269279
{{ t('extend.todoApp') }}
270280
</tiny-button>
281+
<tiny-button
282+
v-if="!isMobile"
283+
class="extend-button extend-button-element-3"
284+
:reset-time="0"
285+
:class="{ 'extend-button-element-active': extendSelect === 'coin' }"
286+
value="coin"
287+
@click="handleExtendClick('coin')"
288+
>
289+
{{ t('extend.coinGame') }}
290+
</tiny-button>
271291
</tiny-button-group>
272292
<div class="home-extend-schema">
273293
<div class="home-extend-schema-header">
@@ -310,13 +330,15 @@ onUnmounted(() => {
310330
class="home-extend-render-area"
311331
:class="{ 'is-visible': cardVisible, 'no-exit': suppressExitAnimation }"
312332
>
313-
<GenuiRenderer
314-
:key="rendererKey"
315-
class="home-extend-schema-renderer"
316-
:content="message?.content || ''"
317-
:generating="generating"
318-
:customActions="customActions"
319-
/>
333+
<GenuiConfigProvider :materials="materials">
334+
<GenuiRenderer
335+
:key="rendererKey"
336+
class="home-extend-schema-renderer"
337+
:content="message?.content || ''"
338+
:generating="generating"
339+
:customActions="customActions"
340+
/>
341+
</GenuiConfigProvider>
320342
</div>
321343
</div>
322344
</div>
@@ -645,11 +667,15 @@ onUnmounted(() => {
645667
font-size: 16px;
646668
647669
&-element-1 {
648-
border-radius: 382px;
670+
border-radius: 382px 0 0 382px;
649671
}
650672
651673
&-element-2 {
652-
border-radius: 382px;
674+
border-radius: 0;
675+
}
676+
677+
&-element-3 {
678+
border-radius: 0 382px 382px 0;
653679
}
654680
655681
&-element-active {

sites/homepage/web/src/i18n/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"title": "Unlock more possibilities",
5555
"calculator": "Calculator",
5656
"todoApp": "Todo App",
57+
"coinGame": "Coin Duel",
5758
"tryPlayground": "Try it in Playground",
5859
"replayControls": "Playback controls",
5960
"pause": "Pause",
@@ -64,8 +65,10 @@
6465
"prompt": {
6566
"element": "Generate a calculator without buttons, use div elements, macaron colors, no TinyLayout, make it beautiful",
6667
"page": "Create a rich todo app with as many features as you can think of",
68+
"coin": "Create a coin duel simulator: both sides start with 100 yuan. The opponent tosses N coins in a row; if at least one lands heads the opponent wins X yuan, otherwise you win and the opponent pays you Y yuan. Simulate until one side goes broke and show both balances changing live with a line chart",
6769
"elementBubble": "Generate a calculator with div elements, macaron colors, make it beautiful",
68-
"pageBubble": "Create a rich todo app with as many features as you can think of"
70+
"pageBubble": "Create a rich todo app with as many features as you can think of",
71+
"coinBubble": "Create a coin duel simulator where both sides start with 100 yuan and play until one goes broke"
6972
}
7073
},
7174
"guide": {

sites/homepage/web/src/i18n/zh.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"title": "解锁更多玩法",
5555
"calculator": "计算器",
5656
"todoApp": "Todo应用",
57+
"coinGame": "硬币博弈",
5758
"tryPlayground": "我也试试,进入 Playground",
5859
"replayControls": "回放控制",
5960
"pause": "暂停",
@@ -64,8 +65,10 @@
6465
"prompt": {
6566
"element": "生成一个计算器,不要用button,使用div,马卡龙配色,不要使用TinyLayout,要好看的",
6667
"page": "创建一个待办应用,界面要丰富,把想到的功能尽量加进去",
68+
"coin": "生成一个硬币博弈模拟器:双方各有100元,对手连续抛N次硬币,只要至少一次正面向上则对手胜并赢走X元,否则你胜、对手赔你Y元,一直模拟到一方破产为止,用折线图实时展示双方资金变化",
6769
"elementBubble": "生成一个计算器,使用div,马卡龙配色,要好看的",
68-
"pageBubble": "创建一个待办应用,界面要丰富,把想到的功能尽量加进去"
70+
"pageBubble": "创建一个待办应用,界面要丰富,把想到的功能尽量加进去",
71+
"coinBubble": "生成一个硬币博弈模拟器,双方各100元,模拟到一方破产"
6972
}
7073
},
7174
"guide": {

0 commit comments

Comments
 (0)