未获取到用户头像时显示随机方块
This commit is contained in:
2
main.lua
2
main.lua
@@ -67,9 +67,9 @@ require"parts.gametoolfunc"
|
|||||||
FREEROW= require"parts.freeRow"
|
FREEROW= require"parts.freeRow"
|
||||||
DATA= require"parts.data"
|
DATA= require"parts.data"
|
||||||
|
|
||||||
USERS= require"parts.users"
|
|
||||||
TEXTURE= require"parts.texture"
|
TEXTURE= require"parts.texture"
|
||||||
SKIN= require"parts.skin"
|
SKIN= require"parts.skin"
|
||||||
|
USERS= require"parts.users"
|
||||||
NET= require"parts.net"
|
NET= require"parts.net"
|
||||||
VK= require"parts.virtualKey"
|
VK= require"parts.virtualKey"
|
||||||
PLY= require"parts.player"
|
PLY= require"parts.player"
|
||||||
|
|||||||
@@ -18,13 +18,14 @@ local emptyUser={
|
|||||||
hash="",
|
hash="",
|
||||||
new=false,
|
new=false,
|
||||||
}
|
}
|
||||||
local texture_noImage=DOGC{128,128,
|
local defaultAvatar={}
|
||||||
{"setCL",.1,.1,.1},
|
for i=1,29 do
|
||||||
{"fRect",0,0,128,128},
|
local img=TEXTURE.miniBlock[i]
|
||||||
{"setCL",1,1,1},
|
defaultAvatar[i]=DOGC{128,128,
|
||||||
{"setFT",100},
|
{"clear",.1,.1,.1},
|
||||||
{"mText","?",64,-6},
|
{"draw",img,63,63,.2,30,30,img:getWidth()/2,img:getHeight()/2},
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
local db_img={}
|
local db_img={}
|
||||||
local db=setmetatable({},{__index=function(self,k)
|
local db=setmetatable({},{__index=function(self,k)
|
||||||
@@ -32,9 +33,10 @@ local db=setmetatable({},{__index=function(self,k)
|
|||||||
local file="cache/user"..k..".dat"
|
local file="cache/user"..k..".dat"
|
||||||
local d=fs.getInfo(file)and JSON.decode(fs.read(file))or TABLE.copy(emptyUser)
|
local d=fs.getInfo(file)and JSON.decode(fs.read(file))or TABLE.copy(emptyUser)
|
||||||
rawset(self,k,d)
|
rawset(self,k,d)
|
||||||
if type(d.hash)=="string"and #d.hash>0 and fs.getInfo("cache/"..d.hash)then
|
db_img[k]=
|
||||||
db_img[k]=loadAvatar("cache/"..d.hash)
|
type(d.hash)=="string"and #d.hash>0 and fs.getInfo("cache/"..d.hash)and
|
||||||
end
|
loadAvatar("cache/"..d.hash)or
|
||||||
|
defaultAvatar[math.random(29)]
|
||||||
return d
|
return d
|
||||||
end})
|
end})
|
||||||
|
|
||||||
@@ -60,15 +62,11 @@ function USERS.getUsername(uid)return db[uid].username end
|
|||||||
function USERS.getMotto(uid)return db[uid].motto end
|
function USERS.getMotto(uid)return db[uid].motto end
|
||||||
function USERS.getHash(uid)return db[uid].hash end
|
function USERS.getHash(uid)return db[uid].hash end
|
||||||
function USERS.getAvatar(uid)
|
function USERS.getAvatar(uid)
|
||||||
if db_img[uid]then
|
if not db[uid].new then
|
||||||
return db_img[uid]
|
NET.getUserInfo(uid)
|
||||||
else
|
db[uid].new=true
|
||||||
if not db[uid].new then
|
|
||||||
NET.getUserInfo(uid)
|
|
||||||
db[uid].new=true
|
|
||||||
end
|
|
||||||
return texture_noImage
|
|
||||||
end
|
end
|
||||||
|
return db_img[uid]
|
||||||
end
|
end
|
||||||
|
|
||||||
return USERS
|
return USERS
|
||||||
Reference in New Issue
Block a user