继续完善USERS模块,升级头像相关功能
This commit is contained in:
@@ -250,6 +250,7 @@ SETTING={--Settings
|
|||||||
10,13,2,8
|
10,13,2,8
|
||||||
},
|
},
|
||||||
face={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
|
face={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
|
||||||
|
dataSaving=false,
|
||||||
|
|
||||||
--Graphic
|
--Graphic
|
||||||
block=true,ghost=.3,center=1,
|
block=true,ghost=.3,center=1,
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ function NET.wsclose_stream()
|
|||||||
WS.close("stream")
|
WS.close("stream")
|
||||||
end
|
end
|
||||||
|
|
||||||
--Account
|
--Account & User
|
||||||
function NET.register(username,email,password)
|
function NET.register(username,email,password)
|
||||||
if NET.lock("register")then
|
if NET.lock("register")then
|
||||||
WS.send("app",JSON.encode{
|
WS.send("app",JSON.encode{
|
||||||
@@ -141,12 +141,13 @@ function NET.getAccessToken()
|
|||||||
WS.send("user",JSON.encode{action=0})
|
WS.send("user",JSON.encode{action=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.getUserInfo(id,ifDetail)
|
function NET.getUserInfo(uid)
|
||||||
|
local hash=not SETTING.dataSaving and USERS.getHash(uid)
|
||||||
WS.send("user",JSON.encode{
|
WS.send("user",JSON.encode{
|
||||||
action=1,
|
action=1,
|
||||||
data={
|
data={
|
||||||
id=id,
|
id=uid,
|
||||||
detailed=ifDetail or false,
|
hash=hash,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@@ -297,7 +298,7 @@ function NET.updateWS_user()
|
|||||||
LOG.print(text.loginSuccessed)
|
LOG.print(text.loginSuccessed)
|
||||||
|
|
||||||
--Get self infos
|
--Get self infos
|
||||||
NET.getUserInfo()
|
NET.getUserInfo(USER.uid)
|
||||||
NET.unlock("wsc_user")
|
NET.unlock("wsc_user")
|
||||||
elseif res.action==0 then--Get accessToken
|
elseif res.action==0 then--Get accessToken
|
||||||
NET.accessToken=res.accessToken
|
NET.accessToken=res.accessToken
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ function scene.keyDown(k)
|
|||||||
kb.isDown("w")and"r99"or
|
kb.isDown("w")and"r99"or
|
||||||
kb.isDown("e")and"unlimited"
|
kb.isDown("e")and"unlimited"
|
||||||
)or"solo",
|
)or"solo",
|
||||||
(USERS.getName(USER.uid)or"???").."'s room"
|
(USERS.getUsername(USER.uid)or"???").."'s room"
|
||||||
)
|
)
|
||||||
lastCreateRoomTime=TIME()
|
lastCreateRoomTime=TIME()
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
local loadImage=love.graphics.newImage
|
local loadImage=love.graphics.newImage
|
||||||
local fs=love.filesystem
|
local fs=love.filesystem
|
||||||
|
|
||||||
local ins=table.insert
|
|
||||||
|
|
||||||
local texture_noImage=DOGC{32,32,
|
local texture_noImage=DOGC{32,32,
|
||||||
{"setc",0,0,0},
|
{"setc",0,0,0},
|
||||||
{"rect","fill",0,0,32,32},
|
{"rect","fill",0,0,32,32},
|
||||||
@@ -14,27 +12,22 @@ local texture_noImage=DOGC{32,32,
|
|||||||
|
|
||||||
local function _getEmptyUser()
|
local function _getEmptyUser()
|
||||||
return{
|
return{
|
||||||
uid=-1,
|
|
||||||
username="[X]",
|
username="[X]",
|
||||||
motto="Techmino haowan",
|
motto="Techmino haowan",
|
||||||
hash=false,
|
hash="",
|
||||||
new=false,
|
new=false,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local imgReqSeq={}
|
|
||||||
local db_img={}
|
local db_img={}
|
||||||
local db=setmetatable({},{__index=function(self,k)
|
local db=setmetatable({},{__index=function(self,k)
|
||||||
local file="cache/user"..k..".dat"
|
local file="cache/user"..k..".dat"
|
||||||
if fs.getInfo(file)then
|
local d=fs.getInfo(file)and JSON.decode(fs.read(file))or _getEmptyUser()
|
||||||
rawset(self,k,JSON.decode(fs.read(file)))
|
rawset(self,k,d)
|
||||||
if fs.getInfo(self[k].hash)then
|
if type(d.hash)=="string"and #d.hash>0 and fs.getInfo(d.hash)then
|
||||||
db_img[k].avatar=loadImage(self[k].hash)
|
db_img[k].avatar=loadImage(d.hash)
|
||||||
end
|
|
||||||
else
|
|
||||||
rawset(self,k,_getEmptyUser())
|
|
||||||
end
|
end
|
||||||
return self[k]
|
return d
|
||||||
end})
|
end})
|
||||||
|
|
||||||
local USERS={}
|
local USERS={}
|
||||||
@@ -51,31 +44,24 @@ function USERS.updateUserData(data)
|
|||||||
if data.avatar then
|
if data.avatar then
|
||||||
fs.write("cache/"..data.hash,data.avatar:sub(data.avatar:find","+1))
|
fs.write("cache/"..data.hash,data.avatar:sub(data.avatar:find","+1))
|
||||||
db_img[uid].avatar=loadImage("cache/"..data.hash)
|
db_img[uid].avatar=loadImage("cache/"..data.hash)
|
||||||
db[uid].hash=data.hash
|
db[uid].hash=type(data.hash)=="string"and data.hash>0 and data.hash
|
||||||
db[uid].new=true
|
db[uid].new=true
|
||||||
end
|
end
|
||||||
needSave=true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function USERS.getUsername(uid)return db[uid].username end
|
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.getAvatar(uid)
|
function USERS.getAvatar(uid)
|
||||||
if db_img[uid]then
|
if db_img[uid]then
|
||||||
return db_img[uid]
|
return db_img[uid]
|
||||||
else
|
else
|
||||||
if not db[uid].new then
|
if not db[uid].new then
|
||||||
ins(imgReqSeq,uid)
|
NET.getUserInfo(uid)
|
||||||
db[uid].new=true
|
db[uid].new=true
|
||||||
end
|
end
|
||||||
return texture_noImage
|
return texture_noImage
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function USERS.update()
|
|
||||||
if #imgReqSeq>0 and WS.status("user")=="running"then
|
|
||||||
NET.getUserInfo(imgReqSeq[#imgReqSeq],true)
|
|
||||||
imgReqSeq[#imgReqSeq]=nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return USERS
|
return USERS
|
||||||
Reference in New Issue
Block a user