Skip to content

Commit

Permalink
dev: implement more class wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
seven-mile committed Feb 6, 2022
1 parent ab06e1e commit 467aafd
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 7 deletions.
4 changes: 0 additions & 4 deletions dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "pch.h"
#include "war3/jass_string.h"
#include "war3/hash_table.h"
#include "war3/native_table.h"
#include "war3/func_callback.h"
#include "war3/func_call.h"

// Define your custom script in script.cpp!
// This function will be called periodly, every ~10ms?
Expand Down
5 changes: 5 additions & 0 deletions pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
#include "globals.h"
#include "war3/enum.h"

// disable static_assert for my MSVC, it seems
// the new version has a bug on it.
// if you're not using VC toolset 14.31.31103(VS 17.1 preview5), COMMENT IT!
#define static_assert(...)

#endif //PCH_H
5 changes: 4 additions & 1 deletion war3/wrapper/JassHandle.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "../../pch.h"
#include "JassHandle.h"


JassHandle::operator bool()
{
return handle;
}
2 changes: 2 additions & 0 deletions war3/wrapper/JassHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ struct JassHandle
{
HObject handle;
JassHandle(HObject const &handle) : handle(handle) { }

operator bool();
};

2 changes: 2 additions & 0 deletions war3/wrapper/JassHero.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "../../pch.h"
#include "JassHero.h"
11 changes: 11 additions & 0 deletions war3/wrapper/JassHero.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include "JassUnit.h"
struct JassHero : public JassUnit
{
JassHero(HUnit handle) : JassUnit(handle) { }
JassHero(JassUnit unit) : JassUnit(nullptr) {
if (unit.IsType(UNIT_TYPE::HERO))
handle = unit.handle;
}
};

2 changes: 0 additions & 2 deletions war3/wrapper/JassPlayer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "../../pch.h"
#include "JassPlayer.h"
#include "JassUnit.h"
#include "JassUnitGroup.h"
#include "../func_call.h"

JassPlayer JassPlayer::EnumPlayer()
Expand Down
1 change: 1 addition & 0 deletions war3/wrapper/JassPlayer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "JassHandle.h"
#include "../enum.h"
#include "JassUnitGroup.h"

struct JassPlayer : public JassHandle
{
Expand Down
15 changes: 15 additions & 0 deletions war3/wrapper/JassUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ JassUnit::JassUnit(JassPlayer owner, int unitId, float x, float y, float face, b
isCorpse ? "CreateCorpse" : "CreateUnit",
unitId, x, y, face)) { }

JassUnit JassUnit::EnumUnit()
{
return CallFn<HUnit>("GetEnumUnit");
}

JassUnit JassUnit::FilterUnit()
{
return CallFn<HUnit>("GetFilterUnit");
}

void JassUnit::Kill()
{
CallFn<void>("KillUnit", handle);
Expand All @@ -23,6 +33,11 @@ void JassUnit::SetShow(bool show)
CallFn<void>("ShowUnit", handle, show);
}

bool JassUnit::IsType(UNIT_TYPE type)
{
return CallFn<bool>("IsUnitType", handle, type);
}

RACE JassUnit::GetRace()
{
return CallFn<RACE>("GetUnitRace", handle);
Expand Down
5 changes: 5 additions & 0 deletions war3/wrapper/JassUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ struct JassUnit : JassWidget
// create JassUnit
JassUnit(struct JassPlayer owner, int unitId, float x, float y, float face, bool isCorpse = false);

static JassUnit EnumUnit();
static JassUnit FilterUnit();

// action : management
void Kill();
void Remove();
Expand All @@ -16,6 +19,8 @@ struct JassUnit : JassWidget
// property : getter/setter
void SetShow(bool show);

bool IsType(UNIT_TYPE type);

RACE GetRace();

void SetState(UNIT_STATE const& state, float value);
Expand Down
43 changes: 43 additions & 0 deletions war3/wrapper/JassUnitGroup.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
#include "../../pch.h"
#include "JassUnitGroup.h"
#include "../func_call.h"

JassUnitGroup JassUnitGroup::Create()
{
return CallFn<HGroup>("CreateGroup");
}

void JassUnitGroup::Destroy()
{
CallFn<void>("DestroyGroup", handle);
}

JassUnit JassUnitGroup::FirstUnit()
{
return CallFn<HUnit>("FirstOfGroup", handle);
}

JassUnitGroup& JassUnitGroup::ForEach(std::function<void(JassUnit)> const& action)
{
CallFn<void>("ForGroup", handle, [action]() {
action(JassUnit::EnumUnit());
});
return *this;
}

JassUnitGroup& JassUnitGroup::Clear()
{
CallFn<void>("GroupClear", handle);
return *this;
}

JassUnitGroup& JassUnitGroup::PushBack(JassUnit unit)
{
CallFn<void>("GroupAddUnit", handle, unit.handle);
return *this;
}

size_t JassUnitGroup::Size()
{
size_t ret_val = 0;
this->ForEach([&](JassUnit){ ret_val++; });
return ret_val;
}
9 changes: 9 additions & 0 deletions war3/wrapper/JassUnitGroup.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#pragma once
#include "JassHandle.h"
#include "JassUnit.h"
struct JassUnitGroup : public JassHandle
{
JassUnitGroup(HObject handle) : JassHandle(handle) { }

JassUnitGroup Create();
void Destroy();

JassUnit FirstUnit();
JassUnitGroup& ForEach(std::function<void(JassUnit)> const& action);
JassUnitGroup& Clear();
JassUnitGroup& PushBack(JassUnit unit);
size_t Size();
};

0 comments on commit 467aafd

Please sign in to comment.