什么样的配置文件格式允许otherfiles的夹杂物和设置的继承?
-
22-07-2019 - |
题
我正在写一个多人基于C ++的游戏。
我需要存储关于游戏的信息charactors一种灵活的文件格式。
在游戏charactors通常不会共享相同的属性,或使用basew
例如:
这将允许我做一些像这样的格式:
#include "standardsettings.config"
//include other files which this file
//then changes
FastSpaceship:
Speed: 10 //pixels/sec
Rotation: 5 //deg/sec
MotherShip : FastSpaceship //inherits all the settings of the Spaceship ship
ShieldRecharge: 4
WeaponA [ power:10,
range:20,
style:fireball]
SlowMotherShip : MotherShip //inherits all the settings of the monther ship
Speed: 4 // override speed
我一直在寻找,做这一切,或者是类似的预先存在的格式,但没有运气。我渴望不重新发明轮子,除非我必须这样做,所以如果有人知道支持这些功能的任何好的配置文件格式,我想知道
解决方案 4
在搜索我找到一个很好的解决方案使用的很多的Lua
的Lua我发现最初被设计为一个配置文件的语言,但随后演变成一个完整的编程语言。
实施例
util.lua
-- helper function needed for inheritance
function inherit(t) -- return a deep copy (incudes all subtables) of the table t
local new = {} -- create a new table
local i, v = next(t, nil) -- i is an index of t, v = t[i]
while i do
if type(v)=="table" then v=inherit(v) end -- deep copy
new[i] = v
i, v = next(t, i) -- get next index
end
return new
end
globalsettings.lua
require "util"
SpaceShip = {
speed = 1,
rotation =1
}
myspaceship.lua
require "globalsettings" -- include file
FastSpaceship = inherits(SpaceShip)
FastSpaceship.Speed = 10
FastSpaceship.Rotation = 5
MotherShip = inherits(FastSpaceship)
MotherShip.ShieldRecharge = 4
ShieldRecharge.WeaponA = {
Power = 10,
Range = 20,
Style = "fireball"
SlowMotherShip = inherits(MotherShip)
SlowMotherShip.Speed = 4
使用在Lua打印功能其也容易,如果它们是正确的测试设置。语法是不太一样好,因为我想它,但它如此接近我想要什么,我不会记写了一点。
在使用这里代码 HTTP:// windrealm.com/tutorials/reading-a-lua-configuration-file-from-c.php 我可以读取设置到我的C ++程序
其他提示
JSON是关于简单的文件格式左右,具有成熟的图书馆,你可以解释它做你想做的任何事情。
{
"FastSpaceship" : {
"Speed" : 10,
"Rotation" : 5
},
"MotherShip" : {
"Inherits" : "FastSpaceship",
"ShieldRecharge" : 4,
"WeaponA": {
"Power": 10,
"Range": 20,
"style": "fireball"
}
},
"SlowMotherShip": {
"Inherits": "MotherShip",
"Speed": 4
}
}
YAML ?这就像JSON没有逗号和引号。
您可能要检查出某种基于帧的表示,因为它似乎这正是你在说什么。维基百科页面的链接,也许你可以使用,或者创建自己的一些已有的实现。
不隶属于 StackOverflow