mirror of
https://github.com/minetest-mods/skinsdb.git
synced 2025-07-20 08:10:22 +02:00
Compare commits
4 Commits
1fcd3c4a8c
...
8048cb08f1
Author | SHA1 | Date | |
---|---|---|---|
8048cb08f1 | |||
77c00a0823 | |||
8799ba0bd5 | |||
b5ba66deca |
8
api.lua
8
api.lua
@ -2,9 +2,11 @@
|
|||||||
local storage = minetest.get_mod_storage()
|
local storage = minetest.get_mod_storage()
|
||||||
|
|
||||||
function skins.get_player_skin(player)
|
function skins.get_player_skin(player)
|
||||||
if player:get_attribute("skinsdb:skin_key") then
|
local meta = player:get_meta()
|
||||||
storage:set_string(player:get_player_name(), player:get_attribute("skinsdb:skin_key"))
|
if meta:get("skinsdb:skin_key") then
|
||||||
player:set_attribute("skinsdb:skin_key", nil)
|
-- Move player data prior July 2018 to mod storage
|
||||||
|
storage:set_string(player:get_player_name(), player:get_string("skinsdb:skin_key"))
|
||||||
|
meta:set_string("skinsdb:skin_key", "")
|
||||||
end
|
end
|
||||||
local skin = storage:get_string(player:get_player_name())
|
local skin = storage:get_string(player:get_player_name())
|
||||||
return skins.get(skin) or skins.get(skins.default)
|
return skins.get(skin) or skins.get(skins.default)
|
||||||
|
2
mod.conf
2
mod.conf
@ -1,4 +1,4 @@
|
|||||||
name = skinsdb
|
name = skinsdb
|
||||||
description = Player skin mod, supporting unified_inventory, sfinv and smart_inventory
|
description = Player skin mod, supporting unified_inventory, sfinv and smart_inventory
|
||||||
depends = default
|
depends = player_api
|
||||||
optional_depends = unified_inventory,3d_armor,clothing,sfinv
|
optional_depends = unified_inventory,3d_armor,clothing,sfinv
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import sys, requests, base64
|
import sys, requests, base64
|
||||||
|
|
||||||
|
download_preview = ( len (sys.argv) > 1 and sys.argv[1] == "with_preview" )
|
||||||
|
|
||||||
|
|
||||||
print("Downloading skins from minetest.fensta.bplaced.net ...")
|
print("Downloading skins from minetest.fensta.bplaced.net ...")
|
||||||
# Requesting all skins and their raw texture using the API
|
# Requesting all skins and their raw texture using the API
|
||||||
r = requests.get('http://minetest.fensta.bplaced.net/api/v2/get.json.php?getlist&page=1&per_page=999999999')
|
r = requests.get('http://minetest.fensta.bplaced.net/api/v2/get.json.php?getlist&page=1&per_page=999999999')
|
||||||
@ -10,35 +13,42 @@ if r.status_code != 200:
|
|||||||
data = r.json()
|
data = r.json()
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
print("Writing to file and downloading previews ...")
|
if download_preview:
|
||||||
|
print("Writing to file and downloading previews ...")
|
||||||
|
else:
|
||||||
|
print("Writing skins")
|
||||||
|
|
||||||
|
|
||||||
for json in data["skins"]:
|
for json in data["skins"]:
|
||||||
id = str(json["id"])
|
id = str(json["id"])
|
||||||
# Downloading the preview of the skin
|
|
||||||
r2 = requests.get('http://minetest.fensta.bplaced.net/skins/1/' + id + ".png")
|
|
||||||
if r.status_code == 200:
|
|
||||||
preview = r2.content
|
|
||||||
# Read meta datas
|
|
||||||
name = str(json["name"])
|
|
||||||
author = str(json["author"])
|
|
||||||
license = str(json["license"])
|
|
||||||
# Texture file
|
# Texture file
|
||||||
raw_data = base64.b64decode(json["img"])
|
raw_data = base64.b64decode(json["img"])
|
||||||
file = open("../textures/character_" + id + ".png", "wb")
|
file = open("../textures/character_" + id + ".png", "wb")
|
||||||
file.write(bytearray(raw_data))
|
file.write(bytearray(raw_data))
|
||||||
file.close()
|
file.close()
|
||||||
# Preview file
|
|
||||||
file = open("../textures/character_" + id + "_preview.png", "wb")
|
|
||||||
file.write(bytearray(preview))
|
|
||||||
file.close()
|
|
||||||
# Meta file
|
# Meta file
|
||||||
|
name = str(json["name"])
|
||||||
|
author = str(json["author"])
|
||||||
|
license = str(json["license"])
|
||||||
file = open("../meta/character_" + id + ".txt", "w")
|
file = open("../meta/character_" + id + ".txt", "w")
|
||||||
file.write(name + "\n" + author + "\n" + license + "\n")
|
file.write(name + "\n" + author + "\n" + license + "\n")
|
||||||
file.close()
|
file.close()
|
||||||
print("Added #%s Name: %s Author: %s License: %s" % (id, name, author, license))
|
print("Added #%s Name: %s Author: %s License: %s" % (id, name, author, license))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
if download_preview:
|
||||||
|
# Downloading the preview of the skin
|
||||||
|
r2 = requests.get('http://minetest.fensta.bplaced.net/skins/1/' + id + ".png")
|
||||||
|
if r2.status_code == 200:
|
||||||
|
# Preview file
|
||||||
|
preview = r2.content
|
||||||
|
file = open("../textures/character_" + id + "_preview.png", "wb")
|
||||||
|
file.write(bytearray(preview))
|
||||||
|
file.close()
|
||||||
else:
|
else:
|
||||||
print("Failed to download skin #" + id)
|
print("Failed to download skin preview #" + id)
|
||||||
|
|
||||||
|
|
||||||
print("Fetched " + str(count) + " skins!")
|
print("Fetched " + str(count) + " skins!")
|
||||||
|
Reference in New Issue
Block a user