Commit 45fc7229 authored by Chen Bill's avatar Chen Bill

check is_iterator_dirty for Group.Next

parent a6f5cc42
......@@ -23,6 +23,7 @@ public:
card_set::iterator it;
int32 ref_handle{ 0 };
uint32 is_readonly{ 0 };
bool is_iterator_dirty{ true };
inline bool has_card(card* c) {
return container.find(c) != container.end();
......
......@@ -46,6 +46,7 @@ int32 scriptlib::group_delete(lua_State *L) {
group* pgroup = *(group**) lua_touserdata(L, 1);
if(pgroup->is_readonly != 2)
return 0;
pgroup->is_iterator_dirty = true;
pgroup->is_readonly = 0;
pduel->sgroups.insert(pgroup);
return 0;
......@@ -66,6 +67,7 @@ int32 scriptlib::group_clear(lua_State *L) {
check_param(L, PARAM_TYPE_GROUP, 1);
group* pgroup = *(group**) lua_touserdata(L, 1);
if (pgroup->is_readonly != 1) {
pgroup->is_iterator_dirty = true;
pgroup->container.clear();
}
return 0;
......@@ -77,6 +79,7 @@ int32 scriptlib::group_add_card(lua_State *L) {
group* pgroup = *(group**) lua_touserdata(L, 1);
card* pcard = *(card**) lua_touserdata(L, 2);
if (pgroup->is_readonly != 1) {
pgroup->is_iterator_dirty = true;
pgroup->container.insert(pcard);
}
return 0;
......@@ -88,6 +91,7 @@ int32 scriptlib::group_remove_card(lua_State *L) {
group* pgroup = *(group**) lua_touserdata(L, 1);
card* pcard = *(card**) lua_touserdata(L, 2);
if (pgroup->is_readonly != 1) {
pgroup->is_iterator_dirty = true;
pgroup->container.erase(pcard);
}
return 0;
......@@ -96,6 +100,9 @@ int32 scriptlib::group_get_next(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_GROUP, 1);
group* pgroup = *(group**) lua_touserdata(L, 1);
if (pgroup->is_iterator_dirty) {
return luaL_error(L, "Called Group.GetNext without calling Group.GetFirst first.");
}
if(pgroup->it == pgroup->container.end())
lua_pushnil(L);
else {
......@@ -111,6 +118,7 @@ int32 scriptlib::group_get_first(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_GROUP, 1);
group* pgroup = *(group**) lua_touserdata(L, 1);
pgroup->is_iterator_dirty = false;
if (pgroup->container.size()) {
pgroup->it = pgroup->container.begin();
interpreter::card2value(L, (*(pgroup->it)));
......@@ -637,6 +645,7 @@ int32 scriptlib::group_remove(lua_State *L) {
uint32 extraargs = lua_gettop(L) - 3;
if(pgroup->is_readonly == 1)
return 0;
pgroup->is_iterator_dirty = true;
for (auto cit = pgroup->container.begin(); cit != pgroup->container.end();) {
if((*cit) != pexception && pduel->lua->check_matching(*cit, 2, extraargs)) {
cit = pgroup->container.erase(cit);
......@@ -644,7 +653,6 @@ int32 scriptlib::group_remove(lua_State *L) {
else
++cit;
}
pgroup->it = pgroup->container.begin();
return 0;
}
int32 scriptlib::group_merge(lua_State *L) {
......@@ -655,6 +663,7 @@ int32 scriptlib::group_merge(lua_State *L) {
group* mgroup = *(group**) lua_touserdata(L, 2);
if(pgroup->is_readonly == 1)
return 0;
pgroup->is_iterator_dirty = true;
pgroup->container.insert(mgroup->container.begin(), mgroup->container.end());
return 0;
}
......@@ -666,6 +675,7 @@ int32 scriptlib::group_sub(lua_State *L) {
group* sgroup = *(group**) lua_touserdata(L, 2);
if(pgroup->is_readonly == 1)
return 0;
pgroup->is_iterator_dirty = true;
for (auto& pcard : sgroup->container) {
pgroup->container.erase(pcard);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment