Constrution d'un joueur

This commit is contained in:
Crom (Thibaut CHARLES) 2015-03-04 17:09:45 +01:00
parent 9009ee4ae6
commit 627c6cb077
4 changed files with 65 additions and 10 deletions

41
Assets/src/Player.cs Normal file
View File

@ -0,0 +1,41 @@
using UnityEngine;
using System.Collections;
public class Player {
Player(int _charID, int _roleID){
charID = _charID;
roleID = _roleID;
var ct = Rdb.GetTable("characters");
charname = ct.GetValue<string>(charID, "name");
spellID = ct.GetValue<int>(charID, "spell");
hp = ct.GetValue<int>(charID, "hp");
var rt = Rdb.GetTable("roles");
rolename = rt.GetValue<string>(roleID, "name");
ultiID = rt.GetValue<int>(roleID, "ulti");
align = rt.GetValue<string>(roleID, "alignment");
}
void DebugInfo() {
Debug.Log(charname+" is a "+rolename+" with "+hp.ToString()+" hit points");
}
int charID;
int roleID;
string charname;
int spellID;
int hp;
string rolename;
int ultiID;
string align;
}

12
Assets/src/Player.cs.meta Normal file
View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1747e8b9a8f0111409e8e9970a88305a
timeCreated: 1425468606
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,7 +2,8 @@ using UnityEngine;
using System.IO;
using System.Collections.Generic;
public class RulesDatabase {
//RulesDatabase
public class Rdb {
public static TwoDA GetTable(string name) {
TwoDA t = null;
@ -18,16 +19,16 @@ public class RulesDatabase {
}
public static string GetStrRef(int strref) {
RulesDatabase inst = Get();
Rdb inst = Get();
return inst.m_strref.GetValue(strref, "text");
return inst.m_strref.GetValue<string>(strref, "text");
}
private RulesDatabase() {
private Rdb() {
m_tables = new Dictionary<string, TwoDA>();
string[] files = Directory.GetFiles(m_folder, "*.2da", SearchOption.AllDirectories);
@ -43,12 +44,12 @@ public class RulesDatabase {
}
private static RulesDatabase m_inst = null;
private static Rdb m_inst = null;
private static object m_singlmutex = new Object();
private static RulesDatabase Get() {
private static Rdb Get() {
lock(m_singlmutex) {
if(m_inst==null)
m_inst = new RulesDatabase();
m_inst = new Rdb();
}
return m_inst;
}
@ -58,4 +59,4 @@ public class RulesDatabase {
private string m_folder = "Assets/rules";
}
}

View File

@ -1,4 +1,5 @@
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
@ -47,11 +48,11 @@ public class TwoDA : UnityEngine.Object {
file.Close();
}
public string GetValue(int nRow, string sColumn) {
public T GetValue<T>(int nRow, string sColumn) {
int nCol = FindHeaderCol(sColumn);
if(nCol>=0) {
return m_data[nRow][nCol];
return (T)Convert.ChangeType(m_data[nRow][nCol], typeof(T));
}
else {
throw new UnityException("Column '"+sColumn+"' not found in 2DA");