Skip to content

Commit

Permalink
New translations v2-migration.md (Thai)
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-crowdin committed Mar 1, 2024
1 parent c99aef0 commit afe91dc
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions translations/th_TH/docs/dev/apis/csync/v2-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
prev: false
next: false
description: Guide to migrating from CSync v1 to v2.
---

# v2.0.0 Migration Guide

The boilerplate from previous versions is now redundant as **CSync** will handle things itself.<br>
This means Steps 3 and 4 of the outdated guide are no longer necessary.

To begin updating, replace `SyncedInstance` with `SyncedConfig`.<br>

```cs
MyConfig : SyncedInstance<MyConfig> // [!code --]
MyConfig : SyncedConfig<MyConfig> // [!code ++]
```

We will now register our config with **CSync** through `ConfigManager` instead of `InitInstance(this)`.
Notice how we specify our mod's GUID through `base()` to ensure it doesn't overlap with others behind the scenes.

```cs
public ExampleConfig(ConfigFile cfg) : base("MyModName") {
InitInstance(this); // [!code --]
ConfigManager.Register(this); // [!code ++]
EXAMPLE_VAR = cfg.BindSyncedEntry("General", "bExampleVar", true, "This is an example variable that will be synced.");
}
```

**We are all done!** If you previously had join/leave patches and request/receiver methods, you should remove these to prevent any possible issues.

**OPTIONAL**<br>
This update also provides the `SyncComplete` event that you can hook into if desired.

```cs
public ExampleConfig(ConfigFile cfg) : base("MyModName") {
ConfigManager.Register(this);

EXAMPLE_VAR = cfg.BindSyncedEntry("General", "bExampleVar", true, "This is an example variable that will be synced.");

SyncComplete += DoSomethingAfterSync; // [!code ++]
}

public void DoSomethingAfterSync(object sender, EventArgs args) { // [!code ++]
// Run some logic here // [!code ++]
} // [!code ++]
```

0 comments on commit afe91dc

Please sign in to comment.