Skip to content

Commit 73a779b

Browse files
committed
initial commit
0 parents  commit 73a779b

File tree

13 files changed

+531
-0
lines changed

13 files changed

+531
-0
lines changed

.editorconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
2+
3+
###############################
4+
# Core EditorConfig Options #
5+
###############################
6+
root = true
7+
8+
###############################
9+
# File Formatting Options #
10+
###############################
11+
[*.cs]
12+
indent_style = tab
13+
indent_size = 4
14+
charset = utf-8
15+
insert_final_newline = true
16+
trim_trailing_whitespace = true
17+
18+
###############################
19+
# C# Formatting Rules #
20+
###############################
21+
22+
csharp_new_line_before_open_brace = all
23+
csharp_space_between_method_declaration_parameter_list_parentheses = false
24+
csharp_space_between_method_call_parameter_list_parentheses = true
25+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
26+
csharp_space_after_keywords_in_control_flow_statements = true
27+
csharp_space_between_parentheses = control_flow_statements
28+
csharp_indent_case_contents = true
29+
csharp_indent_switch_labels = true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/bin/
2+
**/obj/
3+
**/.DS_Store

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## [1.0.0] 2024-7-16
4+
5+
- _Initial commit_

LICENSE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# MIT LICENSE
2+
3+
Copyright 2024 Shi Johnson-Bey <shijbey@gmail.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
6+
software and associated documentation files (the "Software"), to deal in the Software
7+
without restriction, including without limitation the rights to use, copy, modify,
8+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies
13+
or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

PersonalityVectorExample.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1183465E-0EFA-4C65-B306-281C0D5B26E2}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonalityVectorExample", "src\PersonalityVectorExample\PersonalityVectorExample.csproj", "{F7AE63C8-8848-4D97-9022-B49E1A8A0953}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{E03DD065-8599-414B-A6BC-6B71D43B36F8}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonalityVectorExample.Test", "tests\PersonalityVectorExample.Test\PersonalityVectorExample.Test.csproj", "{EF9606FE-CA51-4BE1-A2B3-2CB7A6FE6270}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Release|Any CPU = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{F7AE63C8-8848-4D97-9022-B49E1A8A0953}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{F7AE63C8-8848-4D97-9022-B49E1A8A0953}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{F7AE63C8-8848-4D97-9022-B49E1A8A0953}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{F7AE63C8-8848-4D97-9022-B49E1A8A0953}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{EF9606FE-CA51-4BE1-A2B3-2CB7A6FE6270}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{EF9606FE-CA51-4BE1-A2B3-2CB7A6FE6270}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{EF9606FE-CA51-4BE1-A2B3-2CB7A6FE6270}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{EF9606FE-CA51-4BE1-A2B3-2CB7A6FE6270}.Release|Any CPU.Build.0 = Release|Any CPU
31+
EndGlobalSection
32+
GlobalSection(NestedProjects) = preSolution
33+
{F7AE63C8-8848-4D97-9022-B49E1A8A0953} = {1183465E-0EFA-4C65-B306-281C0D5B26E2}
34+
{EF9606FE-CA51-4BE1-A2B3-2CB7A6FE6270} = {E03DD065-8599-414B-A6BC-6B71D43B36F8}
35+
EndGlobalSection
36+
EndGlobal

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# NPC Personality Vector Example
2+
3+
This repository contains a simplified example implementation of a personality component for non-player characters in simulation games. I made it to track how likely characters are to engage in different behaviors. Also, I wanted to be able to calculate how compatible two personalities are.
4+
5+
The `Personality` class represents character personalities as a vector of real-valued numbers. You can access each personality trait using a corresponding enum value. Also, you can calculate the similarity of two personalities on a scale from -1 to 1. -1 means they are diametrically opposed, and 1 means they are completely compatible.
6+
7+
By default, all personality attributes are clamped on the interval [-100, 100]. Setting the value of `ATTRS_MAX_ABS` will adjust this interval. For instance, `Personality<PersonalityAttrs>.ATTR_MAX_ABS = 50` will change the interval to [-50, 50]. `ATTRS_MAX_ABS` may only be a positive number.
8+
9+
This package can be used with Unity. You will need to write your own `PersonalityController` class to wrap the personality instance and make it available within the Inspector. See the example below.
10+
11+
If you have any questions, create a new GitHub issue. Don't forget to star the repository if you find this useful.
12+
13+
## Package Dependencies
14+
15+
- [MathNet.Numerics](https://www.nuget.org/packages/MathNet.Numerics/) v5.0.0
16+
17+
## General C\# Example
18+
19+
```csharp
20+
using PersonalitySample;
21+
22+
// Start by defining an enum stating what the attributes of a relationship are.
23+
public enum PersonalityAttrs
24+
{
25+
VALUES_MONEY,
26+
VALUES_FAMILY,
27+
VALUES_LOYALTY,
28+
VALUES_POWER,
29+
VALUES_LOVE
30+
}
31+
32+
Personality<PersonalityAttrs> personalityA = new Personality<PersonalityAttrs>();
33+
personalityA.Set( PersonalityAttrs.VALUES_MONEY, 45 );
34+
// Output: Personality(VALUES_MONEY=45, VALUES_FAMILY=0, VALUES_LOYALTY=0, VALUES_POWER=0, VALUES_LOVE=0)
35+
36+
Personality<PersonalityAttrs> personalityB = new Personality<PersonalityAttrs>();
37+
personalityB.Set( PersonalityAttrs.VALUES_MONEY, -10 );
38+
// Output: Personality(VALUES_MONEY=-10, VALUES_FAMILY=0, VALUES_LOYALTY=0, VALUES_POWER=0, VALUES_LOVE=0)
39+
40+
Console.WriteLine(personalityA.Similarity(personalityB));
41+
// Output: -0.3
42+
// These characters are not very compatible.
43+
44+
personalityB.Set( PersonalityAttrs.VALUES_MONEY, 45 );
45+
Console.WriteLine(personalityA.Similarity(personalityB));
46+
// Output: 1
47+
// These characters are now 100% compatible
48+
49+
```
50+
51+
## Unity Example
52+
53+
```csharp
54+
using UnityEngine;
55+
using PersonalitySample;
56+
57+
public class PersonalityController : MonoBehaviour
58+
{
59+
public enum PersonalityAttrs
60+
{
61+
VALUES_MONEY,
62+
VALUES_FAMILY,
63+
VALUES_LOYALTY,
64+
VALUES_POWER,
65+
VALUES_LOVE
66+
}
67+
68+
public Personality<PersonalityAttrs> personality;
69+
70+
// Initial values for personality traits
71+
public float values_money;
72+
public float values_family;
73+
public float values_loyalty;
74+
public float values_power;
75+
public float values_love;
76+
77+
void Awake()
78+
{
79+
personality = new Personality<PersonalityAttrs>();
80+
personality[VALUES_MONEY] = values_money;
81+
personality[VALUES_FAMILY] = values_family;
82+
personality[VALUES_LOYALTY] = values_loyalty;
83+
personality[VALUES_POWER] = values_power;
84+
personality[VALUES_LOVE] = values_love;
85+
}
86+
}
87+
88+
```

bundle_release.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/python3
2+
3+
"""Release Bundler
4+
5+
This script assists with creating proper bundles for release
6+
7+
"""
8+
import pathlib
9+
import shutil
10+
import subprocess
11+
import xml.etree.ElementTree as ET
12+
13+
PACKAGE_NAME = "PersonalityVectorExample"
14+
15+
PROJECT_ROOT = pathlib.Path(__file__).parent
16+
17+
BUILD_DIR = (
18+
PROJECT_ROOT
19+
/ "src"
20+
/ "PersonalityVectorExample"
21+
/ "bin"
22+
/ "Release"
23+
/ "netstandard2.1"
24+
)
25+
26+
RELEASE_DIR = PROJECT_ROOT / "src" / "PersonalityVectorExample" / "bin" / "Release"
27+
28+
LICENSE_PATH = PROJECT_ROOT / "LICENSE.md"
29+
30+
README_PATH = PROJECT_ROOT / "README.md"
31+
32+
CSPROJ_PATH = (
33+
PROJECT_ROOT
34+
/ "src"
35+
/ "PersonalityVectorExample"
36+
/ "PersonalityVectorExample.csproj"
37+
)
38+
39+
OUTPUT_DIR = pathlib.Path("dist")
40+
41+
42+
def get_project_version() -> str:
43+
"""Read the project version number from the csproj file."""
44+
tree = ET.parse(CSPROJ_PATH)
45+
46+
root = tree.getroot()
47+
48+
try:
49+
version_elem = root.findall(".//Version")[0]
50+
except IndexError as exc:
51+
raise RuntimeError(
52+
f"Could not find <Version> element in: {CSPROJ_PATH}."
53+
) from exc
54+
55+
version_text = version_elem.text
56+
57+
if not isinstance(version_text, str):
58+
raise TypeError(f"Version element in '{CSPROJ_PATH}' missing inner text.")
59+
60+
return version_text
61+
62+
63+
def main():
64+
"""The main entry point for the script."""
65+
66+
# Clean out the previous release
67+
if RELEASE_DIR.exists():
68+
shutil.rmtree(str(RELEASE_DIR))
69+
70+
# Create a new build
71+
try:
72+
subprocess.run(["dotnet", "build", "--configuration", "Release"], check=True)
73+
except subprocess.CalledProcessError:
74+
print("An error occurred during build")
75+
return
76+
77+
# Copy the license and readme to the built distribution
78+
shutil.copyfile(LICENSE_PATH, RELEASE_DIR / "LICENSE.md")
79+
shutil.copyfile(README_PATH, RELEASE_DIR / "README.md")
80+
81+
# Zip the build directory
82+
project_version = get_project_version()
83+
84+
shutil.make_archive(
85+
str(OUTPUT_DIR / f"{PACKAGE_NAME}_{project_version}"), "zip", RELEASE_DIR
86+
)
87+
88+
89+
if __name__ == "__main__":
90+
main()
11.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)