feat(bunsik): MVP 전체 구현 — 맵, 요리·서빙, 손님 NPC, 업그레이드 20개, 세이브, 결제, 한/영 UI
- Shop.luau: 손님·주문·조리·서빙·구매 순수 로직(lune 단위 테스트, 시뮬레이터 공용) - 서버: World(부지 6칸), PlotBuilder(파트 모형), PlotController, Npc(트윈 이동), Data(ProfileStore), Receipts(결제 1회 = 지급 1회), Game - 클라이언트: Hud(돈·다음 업그레이드·목록·결제·언어·튜토리얼), 내 조리대 전용 버튼, 튜토리얼 화살표, 주인 전용 테스트 버튼 - 2단계 업그레이드 10개 추가, 파이썬 시뮬레이터를 실제 로직 기반 tools/sim.luau로 교체 - tools/cloud.py: 업로드, 원격 Luau 실행, 게임패스·개발자 상품 생성, 서버 인원 설정 - tests/cloud/integration.luau: 로블록스 서버 통합 테스트 514개 통과 - check.sh에 luau-lsp 타입 검사 추가, ProfileStore 고정 버전 포함 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
83
bunsik-tycoon/src/server/Data.luau
Normal file
83
bunsik-tycoon/src/server/Data.luau
Normal file
@@ -0,0 +1,83 @@
|
||||
--!strict
|
||||
-- 세이브 데이터(ProfileStore). 세션 잠금으로 서버 이동 때 덮어쓰기·복사를 막습니다.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local RunService = game:GetService("RunService")
|
||||
local ServerScriptService = game:GetService("ServerScriptService")
|
||||
|
||||
local ProfileStore = require(ServerScriptService.Vendor.ProfileStore)
|
||||
|
||||
local Data = {}
|
||||
|
||||
Data.TEMPLATE = {
|
||||
Money = 0,
|
||||
Bought = 0,
|
||||
PurchaseIdCache = {} :: { string },
|
||||
TutorialDone = false,
|
||||
Lang = "",
|
||||
Served = 0,
|
||||
Earned = 0,
|
||||
Version = 1,
|
||||
}
|
||||
|
||||
export type SaveData = typeof(Data.TEMPLATE)
|
||||
|
||||
-- 데이터 구조를 바꾸면 store 이름을 올리지 말고 Version과 Reconcile로 이전합니다.
|
||||
local STORE_NAME = "PlayerData_v1"
|
||||
|
||||
local store = ProfileStore.New(STORE_NAME, Data.TEMPLATE)
|
||||
-- Studio 테스트는 실제 저장소를 건드리지 않습니다.
|
||||
local activeStore = if RunService:IsStudio() then store.Mock else store
|
||||
|
||||
local profiles: { [Player]: any } = {}
|
||||
|
||||
function Data.keyFor(userId: number): string
|
||||
return "Player_" .. userId
|
||||
end
|
||||
|
||||
-- 플레이어 데이터를 불러옵니다. 실패하거나 그 사이 나가면 nil.
|
||||
function Data.load(player: Player): any
|
||||
local profile = activeStore:StartSessionAsync(Data.keyFor(player.UserId), {
|
||||
Cancel = function()
|
||||
return player.Parent ~= Players
|
||||
end,
|
||||
})
|
||||
if profile == nil then
|
||||
return nil
|
||||
end
|
||||
profile:AddUserId(player.UserId)
|
||||
profile:Reconcile()
|
||||
profile.OnSessionEnd:Connect(function()
|
||||
profiles[player] = nil
|
||||
if player.Parent == Players then
|
||||
player:Kick(
|
||||
"세이브 세션이 다른 서버로 넘어갔어요. 다시 접속해 주세요 / Your save session moved. Please rejoin"
|
||||
)
|
||||
end
|
||||
end)
|
||||
if player.Parent ~= Players then
|
||||
profile:EndSession()
|
||||
return nil
|
||||
end
|
||||
profiles[player] = profile
|
||||
return profile
|
||||
end
|
||||
|
||||
function Data.get(player: Player): any
|
||||
return profiles[player]
|
||||
end
|
||||
|
||||
function Data.release(player: Player)
|
||||
local profile = profiles[player]
|
||||
profiles[player] = nil
|
||||
if profile then
|
||||
profile:EndSession()
|
||||
end
|
||||
end
|
||||
|
||||
-- 테스트용: 실제 저장소 대신 Mock 저장소를 씁니다.
|
||||
function Data.useMock()
|
||||
activeStore = store.Mock
|
||||
end
|
||||
|
||||
return Data
|
||||
Reference in New Issue
Block a user