Skip to content

Commit

Permalink
扩展属性功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Apr 28, 2024
1 parent eee751a commit 6900b83
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
4 changes: 0 additions & 4 deletions core/quanta/quanta.lmak
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ LINUX_LIBS = {
"stdc++fs"
}

OBJS = {
"quanta.cpp", "main.cpp"
}

--非WINDOWS预编译命令
--格式: cmd
--"cp -r bin/libcurl-x64.dll $(SolutionDir)bin"
Expand Down
9 changes: 5 additions & 4 deletions core/quanta/quanta.mak
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ LDFLAGS += -L$(SOLUTION_DIR)library

#自动生成目标
OBJS =
COBJS = $(patsubst %.c, $(INT_DIR)/%.o, quanta.cpp main.cpp)
MOBJS = $(patsubst %.m, $(INT_DIR)/%.o, $(COBJS))
CCOBJS = $(patsubst %.cc, $(INT_DIR)/%.o, $(MOBJS))
OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCOBJS))
#根目录
OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c)))
OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m)))
OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc)))
OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp)))

# 编译所有源文件
$(INT_DIR)/%.o : $(SRC_DIR)/%.c
Expand Down
7 changes: 0 additions & 7 deletions core/quanta/quanta.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\mainlib.h" />
<ClInclude Include="src\quanta.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\execute.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Develop|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\mainlib.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Develop|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\quanta.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
Expand Down
9 changes: 0 additions & 9 deletions core/quanta/quanta.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="src\mainlib.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="src\quanta.h">
<Filter>inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\execute.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\main.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\mainlib.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\quanta.cpp">
<Filter>src</Filter>
</ClCompile>
Expand Down
45 changes: 40 additions & 5 deletions server/business/component/attr_component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local qenum = quanta.enum
local log_warn = logger.warn
local log_debug = logger.debug
local tinsert = table.insert
local supper = string.upper
local sformat = string.format
local qmerge = qtable.merge

Expand All @@ -11,6 +12,10 @@ local config_mgr = quanta.get("config_mgr")

local attr_db = config_mgr:get_table("attribute")

local AttrID = quanta.enum("AttrID")
local INTERNAL = { "_base", "_inc", "_per" }
local INTERNALID = 1000

local AttrComponent = mixin()
local prop = property(AttrComponent)
prop:reader("range", {}) --属性集合
Expand All @@ -26,7 +31,7 @@ dbprop:store_values("attrs", {}) --属性集合

--委托回调
function AttrComponent:__delegate()
for _, attr in attr_db:iterator() do
local function delegate_attr(attr)
AttrComponent["get_" .. attr.nick] = function(this)
return this:get_attr(attr.id)
end
Expand All @@ -41,6 +46,26 @@ function AttrComponent:__delegate()
return this:cost_attr(attr.id, value)
end
end
local function delegate_internal_attr(attr_bid, attr)
for idx, name in ipairs(INTERNAL) do
AttrID[attr.enum_key .. supper(name)] = attr_bid + idx
delegate_attr({ id = attr_bid + idx, nick = attr.nick .. name, increase = true})
end
end
end
for _, attr in attr_db:iterator() do
if attr.complex then
local attr_bid = INTERNALID + attr.id * 3
delegate_internal_attr(attr_bid, attr)
AttrComponent["get_" .. attr.nick] = function(this)
local base = this:get_attr(attr_bid)
local add_val = this:get_attr(attr_bid + 1)
local per_val = this:get_attr(attr_bid + 2)
return (base + add_val) * (1 + per_val)
end
else
delegate_attr(attr)
end
end
end

Expand All @@ -50,12 +75,22 @@ function AttrComponent:init_attrset(type_attr_db, range)
for _, attr in type_attr_db:iterator() do
local attr_id = qenum("AttrID", attr.key)
local attr_type = attr_db:find_value("type", attr_id)
local attr_limit = attr_db:find_value("limit", attr_id)
local attr_complex = attr_db:find_value("complex", attr_id)
local attr_def = { save = attr.save, back = attr.back, range = attr.range, type = attr_type }
if attr.limit then
attr_def.limit_id = qenum("AttrID", attr.limit)
if attr_limit then
attr_def.limit_id = qenum("AttrID", attr_limit)
end
if attr_complex then
local attr_bid = INTERNALID + attr_id * 3
for idx, name in ipairs(INTERNAL) do
self.attr_set[attr_bid + idx] = { save = false, back = false, range = 0, type = attr_type }
self.attrs[attr_bid + idx] = attr_type == "int" and 0 or ""
end
else
self.attr_set[attr_id] = attr_def
self.attrs[attr_id] = attr_type == "int" and 0 or ""
end
self.attr_set[attr_id] = attr_def
self.attrs[attr_id] = attr_type == "int" and 0 or ""
end
end

Expand Down

0 comments on commit 6900b83

Please sign in to comment.