Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'moonbitlang:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
spaceack authored Oct 28, 2024
2 parents fe7e1b0 + 2c5040f commit cd06afd
Show file tree
Hide file tree
Showing 38 changed files with 399 additions and 106 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Setup Node
Expand Down
199 changes: 95 additions & 104 deletions src/build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -28,123 +28,109 @@ function githubBtn(
</iframe>`
}

fs.rmSync('dist', { recursive: true, force: true })
fs.mkdirSync('dist')

async function getPRInfo(teamName: string) {
const prNumber = getPrNumber(teamName)
const res = await ghClient.request(
'GET /repos/{owner}/{repo}/pulls/{pull_number}',
{
async function getPRInfo(prNumber: number) {
return (
await ghClient.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner: 'moonbitlang',
repo: 'MoonBit-Code-JAM-2024',
pull_number: prNumber,
headers: {
'X-GitHub-Api-Version': '2022-11-28',
},
},
)

return res.data
})
).data
}

type MetaInfo = {
teamName: string
title?: string
control?: string
readme?: string
cover: boolean
prInfo: Awaited<ReturnType<typeof getPRInfo>>
}

function $(strings: TemplateStringsArray, ...args: string[]): string {
const command = strings.reduce(
(prev, current, i) => prev + args[i - 1] + current,
)
return cp.execSync(command).toString().trim()
}

function getPrNumber(teamName: string): number {
const files = fs
.readdirSync(`teams/${teamName}`, { withFileTypes: true })
.filter(d => d.isFile())
.map(d => d.name)

const latestFile = files.sort((a, b) => {
const aTime = fs.statSync(`teams/${teamName}/${a}`).ctimeMs
const bTime = fs.statSync(`teams/${teamName}/${b}`).ctimeMs
return bTime - aTime
})[0]

const commit = $`git log --format=%H teams/${teamName}/${latestFile}`.split(
'\n',
)[0]
const oldestMergeCommit =
$`git rev-list --reverse --merges ${commit}^..HEAD`.split('\n')[0]
const mergeCommitMessage = $`git log --format=%B -n 1 ${oldestMergeCommit}`
const title = mergeCommitMessage.split('\n')[0]
const prNumber = title.match(/Merge pull request #(\d+)/)?.[1]
if (prNumber === undefined) {
throw new Error('No PR number found')
}
return Number(prNumber)
}
const metaInfos = new Map<string, MetaInfo>()

async function collectMetaInfo(teamName: string): Promise<MetaInfo> {
const prInfo = process.env.DEV
? JSON.parse(fs.readFileSync('dev/data.json', 'utf8'))
: await getPRInfo(teamName)
async function collectMetaInfos(): Promise<void> {
const pulls = await ghClient.request('GET /repos/{owner}/{repo}/pulls', {
state: 'closed',
owner: 'moonbitlang',
repo: 'MoonBit-Code-JAM-2024',
headers: {
'X-GitHub-Api-Version': '2022-11-28',
},
})

const metaInfo: MetaInfo = {
teamName,
cover: false,
prInfo,
}
for (const pull of pulls.data) {
const pull_number = pull.number
const files = await ghClient.request(
'GET /repos/{owner}/{repo}/pulls/{pull_number}/files',
{
owner: 'moonbitlang',
repo: 'MoonBit-Code-JAM-2024',
pull_number,
headers: {
'X-GitHub-Api-Version': '2022-11-28',
},
},
)
for (const file of files.data) {
const [teams, teamName, name] = file.filename.split('/', 3)
if (teams === 'teams' && name === 'game.wasm') {
if (metaInfos.has(teamName)) {
break
}
if (!fs.existsSync(`teams/${teamName}`)) {
break
}
const prInfo = await getPRInfo(pull_number)
const metaInfo: MetaInfo = {
prInfo,
cover: false,
}

const files = fs
.readdirSync(`teams/${teamName}`, { withFileTypes: true })
.filter(d => d.isFile())
.map(d => d.name)
const files = fs
.readdirSync(`teams/${teamName}`, { withFileTypes: true })
.filter(d => d.isFile())
.map(d => d.name)

for (const file of files) {
const read = (file: string): string =>
fs.readFileSync(`teams/${teamName}/${file}`, 'utf8')
switch (file) {
case 'cover.png': {
metaInfo.cover = true
continue
}
case 'README.md': {
metaInfo.readme = read(file)
continue
}
case 'title': {
metaInfo.title = read(file)
continue
}
case 'control': {
metaInfo.control = read(file)
continue
}
}
}

for (const file of files) {
const read = (file: string): string =>
fs.readFileSync(`teams/${teamName}/${file}`, 'utf8')
switch (file) {
case 'cover.png': {
metaInfo.cover = true
continue
}
case 'README.md': {
metaInfo.readme = read(file)
continue
}
case 'title': {
metaInfo.title = read(file)
continue
}
case 'control': {
metaInfo.control = read(file)
continue
console.log(`metainfo of ${teamName}:`, metaInfo)
metaInfos.set(teamName, metaInfo)
break
}
}
}

return metaInfo
}

const teamNames = fs
.readdirSync('teams', { withFileTypes: true })
.filter(d => d.isDirectory())
.map(d => d.name)

const metaInfos = await Promise.all(teamNames.map(collectMetaInfo))

function renderGameCard(metaInfo: MetaInfo): string {
function renderGameCard(teamName: string, metaInfo: MetaInfo): string {
const coverPath = metaInfo.cover
? `${querystring.escape(metaInfo.teamName)}/cover.png`
? `${querystring.escape(teamName)}/cover.png`
: 'default-cover.png'

const teamPath = querystring.escape(metaInfo.teamName)
const teamPath = querystring.escape(teamName)
const authorName = metaInfo.prInfo.head.user.login
const repoName = metaInfo.prInfo.head.repo?.name

Expand All @@ -153,8 +139,8 @@ function renderGameCard(metaInfo: MetaInfo): string {
}

const footer = metaInfo.title
? `<h2>${metaInfo.title}</h2><p>${metaInfo.teamName}</p>`
: `<p>${metaInfo.teamName}</p>`
? `<h2>${metaInfo.title}</h2><p>${teamName}</p>`
: `<p>${teamName}</p>`

return /*html*/ `
<div class='game-card'>
Expand All @@ -173,8 +159,10 @@ function renderGameCard(metaInfo: MetaInfo): string {
`.trim()
}

function indexHtml(metaInfos: MetaInfo[]): string {
const gameCards = metaInfos.map(renderGameCard).join('\n')
function indexHtml(): string {
const gameCards = [...metaInfos.entries()]
.map(e => renderGameCard(...e))
.join('\n')

return /*html*/ `
<!DOCTYPE html>
Expand Down Expand Up @@ -336,8 +324,8 @@ function indexHtml(metaInfos: MetaInfo[]): string {
`
}

function gameIndexHtml(metaInfo: MetaInfo): string {
const title = metaInfo.title ?? metaInfo.teamName
function gameIndexHtml(teamName: string, metaInfo: MetaInfo): string {
const title = metaInfo.title ?? teamName
const control = metaInfo.control ?? ''
const readme = metaInfo.readme ? md.render(metaInfo.readme) : ''
const authorName = metaInfo.prInfo.head.user.login
Expand Down Expand Up @@ -521,17 +509,20 @@ function copyWasm4(dist: string) {
}
}

fs.writeFileSync('dist/index.html', indexHtml(metaInfos))
fs.rmSync('dist', { recursive: true, force: true })
fs.mkdirSync('dist')
await collectMetaInfos()
fs.writeFileSync('dist/index.html', indexHtml())
fs.copyFileSync('assets/default-cover.png', 'dist/default-cover.png')
for (const metaInfo of metaInfos) {
const gameIndex = gameIndexHtml(metaInfo)
fs.mkdirSync(`dist/${metaInfo.teamName}`)
copyWasm4(metaInfo.teamName)
for (const file of fs.readdirSync(`teams/${metaInfo.teamName}`)) {
for (const [teamName, metaInfo] of metaInfos) {
const gameIndex = gameIndexHtml(teamName, metaInfo)
fs.mkdirSync(`dist/${teamName}`)
copyWasm4(teamName)
for (const file of fs.readdirSync(`teams/${teamName}`)) {
fs.copyFileSync(
`teams/${metaInfo.teamName}/${file}`,
`dist/${metaInfo.teamName}/${file === 'game.wasm' ? 'cart.wasm' : file}`,
`teams/${teamName}/${file}`,
`dist/${teamName}/${file === 'game.wasm' ? 'cart.wasm' : file}`,
)
}
fs.writeFileSync(`dist/${metaInfo.teamName}/index.html`, gameIndex)
fs.writeFileSync(`dist/${teamName}/index.html`, gameIndex)
}
7 changes: 7 additions & 0 deletions teams/Gameboy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Moonbit
Game
我准备做一个格斗游戏,暂时没有建模(后期会进行添加)
游戏玩法:
选出角色进行战斗,可以两个人对打也可以打人机
左右方向移动
下方向攻击
Binary file added teams/Gameboy/game.wasm
Binary file not shown.
Binary file added teams/GoToTheDoor/GoToTheDoorDemo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions teams/GoToTheDoor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## 项目描述
一个开源的游戏开发项目

## 游戏简介
通过↑ ↓ ← → 来控制人物移动
Go to the door 是一款跑酷冒险类游戏,在充满邪念与恶意的地图中存活下来,到达地图中的大门才能喘息片刻并挑战下一关!
致敬和模仿LEVEL DEVIL。

## 主要功能
- **多样的关卡设计**:包含多个关卡,每个关卡都有独特的挑战和谜题。

## 贡献者和致谢

贡献者:
xuancai

特别感谢:
所有贡献者和开源社区的支持。
1 change: 1 addition & 0 deletions teams/GoToTheDoor/control.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
通过↑ ↓ ← → 来控制人物移动
Binary file added teams/GoToTheDoor/demo.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions teams/GoToTheDoor/title.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Go to the door
32 changes: 32 additions & 0 deletions teams/天地一!屋!大爱盟/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 飞机大战
## 游戏玩法

### 自机

有一百的生命值,初始发射普通子弹

### 敌机

1. 中型机

会发射普通子弹,发射方向为自机方向

2. 小型机

可以理解为FPV自杀式无人机

### 弹药箱

1. 回复生命箱

回复$50$点生命

2. 双发弹

拾取后会发射一段时间的双发弹

3. 高爆弹

拾取后发射一段时间的高伤害高爆弹

## 游戏有很多其他的“特性”建议自行游玩查看QWQ
1 change: 1 addition & 0 deletions teams/天地一!屋!大爱盟/control
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
上下左右控制飞机移动,子弹自动垂直向上发射
Binary file added teams/天地一!屋!大爱盟/cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions teams/天地一!屋!大爱盟/game.html

Large diffs are not rendered by default.

Binary file added teams/天地一!屋!大爱盟/game.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions teams/天地一!屋!大爱盟/title
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
飞机大战
9 changes: 9 additions & 0 deletions teams/寻找新大陆/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 操作

通过`` `` `` `` 来控制bird移动,避免撞到管道障碍物。

## 提示

‌基本操作‌:玩家键盘上键控制小鸟上升,放松手指则小鸟会快速下降。点击上键的频率和力度需要掌握好,以保持小鸟在空中的平衡‌<br>

‌游戏目标‌:玩家的目标是控制小鸟穿越由不同长度水管组成的障碍,安全通过每一个障碍物而不撞到水管。每成功通过一个障碍物,小鸟就会获得1分,如果撞到水管则游戏结束‌。
1 change: 1 addition & 0 deletions teams/寻找新大陆/control
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
方向键移动,躲避障碍物成功得分
Binary file added teams/寻找新大陆/cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added teams/寻找新大陆/game.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions teams/寻找新大陆/title
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FlyBird
Loading

0 comments on commit cd06afd

Please sign in to comment.