Skip to content

Commit

Permalink
更新C#例子
Browse files Browse the repository at this point in the history
  • Loading branch information
davyxu committed Mar 19, 2019
1 parent 1a82677 commit a289ff1
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,37 +139,34 @@ tabtoy --mode=v2 --json_out=config.json --combinename=Config Table.xlsx
[例子](https://github.com/davyxu/tabtoy/tree/master/v2/example/csharp)

```csharp
using (var stream = new FileStream("../../../../Config.bin", FileMode.Open))
{
stream.Position = 0;
using (var stream = new FileStream("../../Config.bin", FileMode.Open))
{
stream.Position = 0;

var reader = new tabtoy.DataReader(stream);

if ( !reader.ReadHeader( ) )
{
Console.WriteLine("combine file crack!");
return;
}
var reader = new tabtoy.DataReader(stream);

var config = new gamedef.Config();
table.Config.Deserialize(config, reader);
var config = new table.Config();

// 直接通过下标获取或遍历
var directFetch = config.Sample[2];
var result = reader.ReadHeader(config.GetBuildID());
if ( result != FileState.OK)
{
Console.WriteLine("combine file crack!");
return;
}

// 根据索引取
var indexFetch = config.GetSampleByID(100);

// 取不存在的元素时, 返回给定的默认值, 避免空
var indexFetchByDefault = config.GetSampleByID(0, new gamedef.SampleDefine() );
table.Config.Deserialize(config, reader);

// 添加日志输出或自定义输出
config.TableLogger.AddTarget( new tabtoy.DebuggerTarget() );
// 直接通过下标获取或遍历
var directFetch = config.Sample[2];

// 取空时, 当默认值不为空时, 输出日志
var nullFetchOutLog = config.GetSampleByID( 0 );
// 添加日志输出或自定义输出
config.TableLogger.AddTarget(new tabtoy.DebuggerTarget());

}
// 取空时, 当默认值不为空时, 输出日志
var nullFetchOutLog = config.GetSampleByID(0);

}
```

### lua读取例子
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var log = golog.New("main")

const (
Version = "2.8.12"
Version = "2.9.0"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion v2/example/cpp/cpp/Config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by github.com/davyxu/tabtoy
// Version: 2.8.11
// Version: 2.9.0
// DO NOT EDIT!!
#include <vector>
#include <map>
Expand Down
Binary file modified v2/example/csharp/Example/Config.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion v2/example/csharp/Example/Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by github.com/davyxu/tabtoy
// Version: 2.8.11
// Version: 2.9.0
// DO NOT EDIT!!
using System.Collections.Generic;

Expand Down
13 changes: 8 additions & 5 deletions v2/example/csharp/Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
using System;
using System.IO;
using tabtoy;

namespace csharptest
{
class Program
{

static void Main(string[] args)
{
var dir = Directory.GetCurrentDirectory();
{
using (var stream = new FileStream("../../Config.bin", FileMode.Open))
{
stream.Position = 0;

var reader = new tabtoy.DataReader(stream);

if ( !reader.ReadHeader( ) )

var config = new table.Config();

var result = reader.ReadHeader(config.GetBuildID());
if ( result != FileState.OK)
{
Console.WriteLine("combine file crack!");
return;
}

var config = new table.Config();

table.Config.Deserialize(config, reader);

// 直接通过下标获取或遍历
Expand Down
2 changes: 1 addition & 1 deletion v2/example/golang/Config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Tool": "github.com/davyxu/tabtoy",
"Version": "2.8.11",
"Version": "2.9.0",
"Sample":[
{ "ID": 100, "Name": "黑猫警长", "NumericalRate": 0.6, "ItemID": 100, "BuffID":[ 10 ], "Pos": { "X": 100, "Y": 89 }, "Type": 0, "SkillID":[ 4, 6, 7 ], "AttackParam": { "Value": 1 }, "SingleStruct": { "HP": 100, "AttackRate": 1.2 }, "StrStruct":[ { "HP": 3, "ExType": 0 }, { "HP": 10, "ExType": 1 } ] },
{ "ID": 101, "Name": "葫芦\n", "NumericalRate": 0.8, "ItemID": 100, "BuffID":[ 3, 1 ], "Type": 2, "SkillID":[ 1 ], "SingleStruct": { "HP": 10 }, "StrStruct":[ { } ] },
Expand Down
2 changes: 1 addition & 1 deletion v2/example/golang/table/table_gen.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by github.com/davyxu/tabtoy
// Version: 2.8.11
// Version: 2.9.0
// DO NOT EDIT!!
package table

Expand Down
2 changes: 1 addition & 1 deletion v2/example/lua/Config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Generated by github.com/davyxu/tabtoy
-- Version: 2.8.11
-- Version: 2.9.0

local tab = {
Sample = {
Expand Down

0 comments on commit a289ff1

Please sign in to comment.